jut.io
Class InputCountStream

java.lang.Object
  extended by java.io.InputStream
      extended by jut.io.InputCountStream
All Implemented Interfaces:
Closeable
Direct Known Subclasses:
HashInputStream

public class InputCountStream
extends InputStream

InputStream counting the bytes read. the methods skip(long), mark(int) and reset() are not supported and throw an UnsupportedOperationException.


Field Summary
protected  InputStream baseStream
          the underlying input stream.
protected  ICount counter
          counter for the bytes read from this InputStream.
 
Constructor Summary
protected InputCountStream()
          create a new InputStream counting the bytes passing through. the constructor's caller is responsible for filling in the baseStream field.
  InputCountStream(File file)
          create a new InputStream counting the bytes passing through. for creating the stream, the Streams.input(File) method is used.
  InputCountStream(File file, ICount counter)
          create a new InputStream counting the bytes passing through. for creating the stream, the Streams.input(File) method is used.
protected InputCountStream(ICount counter)
          create a new InputStream counting the bytes passing through. the constructor's caller is responsible for filling in the baseStream field.
  InputCountStream(InputStream input)
          create a new FilterInputStream counting the bytes passing through.
  InputCountStream(InputStream input, ICount counter)
          create a new FilterInputStream counting the bytes passing through.
 
Method Summary
 int available()
          
 void close()
          
 long getCount()
          returns the number of bytes that have passed through this InputCountStream.
 ICount getCounter()
          returns the counter for this InputCountStream.
 void mark(int readlimit)
           this method always throws an UnsupportedOperationException.
 boolean markSupported()
          this method always returns false.
 int read()
          
 int read(byte[] buffer)
          
 int read(byte[] buffer, int off, int len)
          
 void reset()
           this method always throws an UnsupportedOperationException.
 long skip(long count)
           this method always throws an UnsupportedOperationException.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

counter

protected final ICount counter
counter for the bytes read from this InputStream.


baseStream

protected InputStream baseStream
the underlying input stream.

Constructor Detail

InputCountStream

protected InputCountStream()
create a new InputStream counting the bytes passing through. the constructor's caller is responsible for filling in the baseStream field.


InputCountStream

protected InputCountStream(ICount counter)
create a new InputStream counting the bytes passing through. the constructor's caller is responsible for filling in the baseStream field.

Parameters:
counter - - the counter to use.

InputCountStream

public InputCountStream(File file)
                 throws FileNotFoundException
create a new InputStream counting the bytes passing through. for creating the stream, the Streams.input(File) method is used.

Parameters:
file - - the file to open the InputStream for.
Throws:
FileNotFoundException - if the file cannot be opened for reading.

InputCountStream

public InputCountStream(File file,
                        ICount counter)
                 throws FileNotFoundException
create a new InputStream counting the bytes passing through. for creating the stream, the Streams.input(File) method is used.

Parameters:
file - - the file to open the InputStream for.
counter - - the counter to use.
Throws:
FileNotFoundException - if the file cannot be opened for reading.

InputCountStream

public InputCountStream(InputStream input)
create a new FilterInputStream counting the bytes passing through.

Parameters:
input - - the InputStream to wrap.

InputCountStream

public InputCountStream(InputStream input,
                        ICount counter)
create a new FilterInputStream counting the bytes passing through.

Parameters:
input - - the InputStream to wrap.
counter - - the counter to use.
Method Detail

read

public int read(byte[] buffer,
                int off,
                int len)
         throws IOException

Overrides:
read in class InputStream
Throws:
IOException

read

public int read(byte[] buffer)
         throws IOException

Overrides:
read in class InputStream
Throws:
IOException

read

public int read()
         throws IOException

Specified by:
read in class InputStream
Throws:
IOException

skip

public long skip(long count)
          throws IOException
this method always throws an UnsupportedOperationException.

Overrides:
skip in class InputStream
Throws:
IOException

mark

public void mark(int readlimit)
this method always throws an UnsupportedOperationException.

Overrides:
mark in class InputStream

reset

public void reset()
           throws IOException
this method always throws an UnsupportedOperationException.

Overrides:
reset in class InputStream
Throws:
IOException

markSupported

public boolean markSupported()
this method always returns false.

Overrides:
markSupported in class InputStream
Returns:
always false.

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

getCount

public long getCount()
returns the number of bytes that have passed through this InputCountStream.

Returns:
the number of bytes that have passed through this InputCountStream.

getCounter

public ICount getCounter()
returns the counter for this InputCountStream.

Returns:
the counter for this InputCountStream.