net.sf.zig_project.gpl.common.io
Class MeteredInputStream

java.lang.Object
  extended byjava.io.InputStream
      extended byjava.io.FilterInputStream
          extended bynet.sf.zig_project.gpl.common.io.MeteredInputStream

public class MeteredInputStream
extends FilterInputStream

Meters the number of bytes read across a given InputStream. The number of bytes that have been either read or skipped may be polled through getMeteredBytes().

The number of bytes represented by this meter may be safely assumed to be an unsigned 64 bit value if necessary. Note that the maximum value representable by this meter would then concievably be 264-2 bytes.

This class is only limitedly thread safe. Controlling the position of the stream, or the state of the underlying stream should entirely contained to a single thread. However, independant threads may safely and predictably poll the current meter.

Version:
April 6, 2005
Author:
Frank Ziglar

Field Summary
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
MeteredInputStream(InputStream is)
           
 
Method Summary
 long getMeteredBytes()
          Polls the meter for the number of bytes read by this InputStream.
 void mark(int read_ahead)
           
 int read()
           
 int read(byte[] buf)
           
 int read(byte[] buf, int off, int len)
           
 void reset()
          Resets this InputStream to it's last marked state.
 long skip(long l)
           
 
Methods inherited from class java.io.FilterInputStream
available, close, markSupported
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MeteredInputStream

public MeteredInputStream(InputStream is)
Method Detail

read

public int read()
         throws IOException
Throws:
IOException

read

public int read(byte[] buf,
                int off,
                int len)
         throws IOException
Throws:
IOException

read

public int read(byte[] buf)
         throws IOException
Throws:
IOException

skip

public long skip(long l)
          throws IOException
Throws:
IOException

mark

public void mark(int read_ahead)

reset

public void reset()
           throws IOException
Resets this InputStream to it's last marked state. Calling this method will back up the number of metered bytes back to that of the last mark(int) operation.

Throws:
IOException

getMeteredBytes

public long getMeteredBytes()
Polls the meter for the number of bytes read by this InputStream. Note that when the meter has been reset(), this method will ignore the number of bytes read between that reset operation and the last mark(int) operation.

Returns:
the number of bytes metered by this InputStream