2.17.2: 2011-06-17

net.sf.basedb.util
Class InputStreamTracker

java.lang.Object
  extended by java.io.InputStream
      extended by net.sf.basedb.util.InputStreamTracker
All Implemented Interfaces:
Closeable

public class InputStreamTracker
extends InputStream

This class is used to keep track of the number of bytes read from the underlying input stream. This is very useful for code that needs to reporter progress but are having difficulties to know the number of processed bytes.

Version:
2.4
Author:
nicklas
Last modified
$Date: 2008-09-11 22:08:14 +0200 (Thu, 11 Sep 2008) $

Field Summary
private  InputStream in
          The source input stream to read from.
private  long numRead
          The number of bytes that has been read from the underlying input stream so far.
private  long numReadAtMark
          The number of bytes that had been read when mark(int) was called.
 
Constructor Summary
InputStreamTracker(InputStream in)
          Create a new input stream tracker.
 
Method Summary
 int available()
           
 void close()
           
 long getNumRead()
          Get the number of bytes read or skipped from the input stream.
 void mark(int readlimit)
           
 boolean markSupported()
           
 int read()
           
 int read(byte[] b)
           
 int read(byte[] b, int off, int len)
           
 void reset()
           
 long skip(long n)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

in

private final InputStream in
The source input stream to read from.


numRead

private long numRead
The number of bytes that has been read from the underlying input stream so far.


numReadAtMark

private long numReadAtMark
The number of bytes that had been read when mark(int) was called.

Constructor Detail

InputStreamTracker

public InputStreamTracker(InputStream in)
Create a new input stream tracker.

Parameters:
in - The input stream to read from
Method Detail

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

mark

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

markSupported

public boolean markSupported()
Overrides:
markSupported in class InputStream

read

public int read()
         throws IOException
Specified by:
read in class InputStream
Throws:
IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Overrides:
read in class InputStream
Throws:
IOException

read

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

reset

public void reset()
           throws IOException
Overrides:
reset in class InputStream
Throws:
IOException

skip

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

getNumRead

public long getNumRead()
Get the number of bytes read or skipped from the input stream. If the underlying stream supports reset() this will also reset the number of read bytes to the latest mark(int) position.

Returns:
The number of bytes that has been read so far

2.17.2: 2011-06-17