sk.baka.ambient.commons
Class CountingInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by sk.baka.ambient.commons.CountingInputStream
All Implemented Interfaces:
java.io.Closeable
Direct Known Subclasses:
NotifyingInputStream

public abstract class CountingInputStream
extends java.io.InputStream

Counts bytes which are being read.

Author:
Martin Vysny

Field Summary
 int blockLength
          Fire events only when a block of given size (in bytes) has been read.
 
Constructor Summary
CountingInputStream(java.io.InputStream in, int blockLength)
          Creates new counting stream instance.
 
Method Summary
 int available()
           
 void close()
           
protected abstract  void countEvent(long currentPosition)
          Invoked when the position
 long getCurrentPosition()
          Returns number of bytes already read.
 void mark(int readlimit)
           
 boolean markSupported()
           
 int read()
           
 int read(byte[] buffer)
           
 int read(byte[] buffer, int offset, int count)
           
 void reset()
           
 long skip(long count)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

blockLength

public final int blockLength
Fire events only when a block of given size (in bytes) has been read. This prevents firing events after each byte read.

Constructor Detail

CountingInputStream

public CountingInputStream(java.io.InputStream in,
                           int blockLength)
Creates new counting stream instance.

Parameters:
in - poll this stream.
blockLength - Fire events only when a block of given size (in bytes) has been read. This prevents firing events after each byte read.
Method Detail

read

public int read()
         throws java.io.IOException
Specified by:
read in class java.io.InputStream
Throws:
java.io.IOException

read

public int read(byte[] buffer,
                int offset,
                int count)
         throws java.io.IOException
Overrides:
read in class java.io.InputStream
Throws:
java.io.IOException

read

public int read(byte[] buffer)
         throws java.io.IOException
Overrides:
read in class java.io.InputStream
Throws:
java.io.IOException

skip

public long skip(long count)
          throws java.io.IOException
Overrides:
skip in class java.io.InputStream
Throws:
java.io.IOException

mark

public void mark(int readlimit)
Overrides:
mark in class java.io.InputStream

reset

public void reset()
           throws java.io.IOException
Overrides:
reset in class java.io.InputStream
Throws:
java.io.IOException

getCurrentPosition

public long getCurrentPosition()
Returns number of bytes already read.

Returns:
the number of bytes.

countEvent

protected abstract void countEvent(long currentPosition)
Invoked when the position

Parameters:
currentPosition -

available

public int available()
              throws java.io.IOException
Overrides:
available in class java.io.InputStream
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.InputStream
Throws:
java.io.IOException

markSupported

public boolean markSupported()
Overrides:
markSupported in class java.io.InputStream


Copyright © 2007-2009. All Rights Reserved.