sk.baka.ambient.commons
Class CountingInputStream

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

public abstract class CountingInputStream
extends 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(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(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 IOException
Specified by:
read in class InputStream
Throws:
IOException

read

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

read

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

skip

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

mark

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

reset

public void reset()
           throws IOException
Overrides:
reset in class InputStream
Throws:
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 IOException
Overrides:
available in class InputStream
Throws:
IOException

close

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

markSupported

public boolean markSupported()
Overrides:
markSupported in class InputStream


Copyright © 2007-2008. All Rights Reserved.