com.sibvisions.util.io
Class ByteCountInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by com.sibvisions.util.io.ByteCountInputStream
All Implemented Interfaces:
java.io.Closeable

public class ByteCountInputStream
extends java.io.FilterInputStream

The ByteCountInputStream is an InputStream wrapper which counts read bytes and also enables reading of expected bytes if known.


Field Summary
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
ByteCountInputStream(java.io.InputStream pStream)
          Creates a new instance of ByteCountInputStream.
ByteCountInputStream(java.io.InputStream pStream, long pExpectedBytes)
          Creates a new instance of ByteCountInputStream for the given stream and calculated number of expected bytes.
 
Method Summary
 void close()
          
 long getExpectedBytes()
          Gets the expected bytes.
 long getReadBytes()
          Gets the read bytes.
 long getSkippedBytes()
          Gets the skipped bytes.
 int read()
          
 int read(byte[] pContent, int pOffset, int pLength)
          
 void readAvailableBytes()
          If expected bytes count is set, this method will read the bytes which weren't read yet.
 long skip(long pBytes)
          
 
Methods inherited from class java.io.FilterInputStream
available, mark, markSupported, read, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteCountInputStream

public ByteCountInputStream(java.io.InputStream pStream)
Creates a new instance of ByteCountInputStream.

Parameters:
pStream - the wrapped stream

ByteCountInputStream

public ByteCountInputStream(java.io.InputStream pStream,
                            long pExpectedBytes)
Creates a new instance of ByteCountInputStream for the given stream and calculated number of expected bytes.

Parameters:
pStream - the wrapped stream
pExpectedBytes - the number of expected bytes
Method Detail

close

public void close()
           throws java.io.IOException

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.FilterInputStream
Throws:
java.io.IOException

read

public int read()
         throws java.io.IOException

Overrides:
read in class java.io.FilterInputStream
Throws:
java.io.IOException

read

public int read(byte[] pContent,
                int pOffset,
                int pLength)
         throws java.io.IOException

Overrides:
read in class java.io.FilterInputStream
Throws:
java.io.IOException

skip

public long skip(long pBytes)
          throws java.io.IOException

Overrides:
skip in class java.io.FilterInputStream
Throws:
java.io.IOException

readAvailableBytes

public void readAvailableBytes()
                        throws java.io.IOException
If expected bytes count is set, this method will read the bytes which weren't read yet.

Throws:
java.io.IOException - if reading bytes failed

getReadBytes

public long getReadBytes()
Gets the read bytes.

Returns:
the number of read bytes

getSkippedBytes

public long getSkippedBytes()
Gets the skipped bytes.

Returns:
the number of read bytes

getExpectedBytes

public long getExpectedBytes()
Gets the expected bytes.

Returns:
the number of expected bytes


Copyright © 2009 SIB Visions GmbH. All Rights Reserved.