Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.esau.ptarmigan.util
Class CountingInputStream  view CountingInputStream download CountingInputStream.java

java.lang.Object
  extended byjava.io.InputStream
      extended byjava.io.FilterInputStream
          extended byorg.esau.ptarmigan.util.CountingInputStream
All Implemented Interfaces:
java.io.Closeable

public class CountingInputStream
extends java.io.FilterInputStream

Counts the number of bytes that pass through it.

Note that the counter in this filter is independent of the mark/reset logic. If you wish to reset the counter when you reset the mark, you'll have to do so manually with a call to resetCount().

Note that this class has its own renamed read() methods. This is to insulate a buffered parent class that will read-ahead as necessary.

Version:
$Revision: 1.3 $ $Date: 2002/10/02 05:30:04 $

Field Summary
(package private) static int BLOCK_SIZE
           
(package private) static org.apache.commons.logging.Log log
          logging object
private  long m_count
           
private  long m_limit
           
(package private) static int NO_LIMIT
           
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
CountingInputStream(java.io.InputStream in)
           
CountingInputStream(java.io.InputStream in, long limit)
           
 
Method Summary
 int fastForward(int n)
          a substitute for skip, which doesn't seem to want to work correctly on buffered streams
 long getCount()
          The number of bytes that have passed through this stream.
 long getLimit()
           
 long getRemaining()
           
 int readC()
           
 int readC(byte[] b)
           
 int readC(byte[] b, int off, int len)
           
 void resetCount()
          Start the count at zero
 boolean rewind(int n)
          reposition the stream from the last mark point (in case we read too far)
 void setLimit(long limit)
           
 long skipC(long n)
           
 
Methods inherited from class java.io.FilterInputStream
available, close, mark, markSupported, read, read, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_LIMIT

static final int NO_LIMIT
See Also:
Constant Field Values

m_limit

private long m_limit

m_count

private long m_count

BLOCK_SIZE

static final int BLOCK_SIZE
See Also:
Constant Field Values

log

static org.apache.commons.logging.Log log
logging object

Constructor Detail

CountingInputStream

public CountingInputStream(java.io.InputStream in)

CountingInputStream

public CountingInputStream(java.io.InputStream in,
                           long limit)
Method Detail

readC

public int readC()
          throws java.io.IOException

readC

public int readC(byte[] b)
          throws java.io.IOException

readC

public int readC(byte[] b,
                 int off,
                 int len)
          throws java.io.IOException

skipC

public long skipC(long n)
           throws java.io.IOException

getCount

public long getCount()
The number of bytes that have passed through this stream.


resetCount

public void resetCount()
Start the count at zero


getLimit

public long getLimit()

setLimit

public void setLimit(long limit)

getRemaining

public long getRemaining()

fastForward

public int fastForward(int n)
                throws java.io.IOException
a substitute for skip, which doesn't seem to want to work correctly on buffered streams

TODO: should be 'long' param?


rewind

public boolean rewind(int n)
               throws java.io.IOException
reposition the stream from the last mark point (in case we read too far)

TODO: should be 'long' param?