net.sf.jazzlib
Class CheckedInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java13.io.FilterInputStream
          extended by net.sf.jazzlib.CheckedInputStream

public class CheckedInputStream
extends FilterInputStream

InputStream that computes a checksum of the data being read using a supplied Checksum object.

Author:
Tom Tromey
See Also:
Checksum

Field Summary
 
Fields inherited from class java13.io.FilterInputStream
in
 
Constructor Summary
CheckedInputStream(java.io.InputStream in, Checksum sum)
          Creates a new CheckInputStream on top of the supplied OutputStream using the supplied Checksum.
 
Method Summary
 Checksum getChecksum()
          Returns the Checksum object used.
 int read()
          Reads one byte, updates the checksum and returns the read byte (or -1 when the end of file was reached).
 int read(byte[] buf, int off, int len)
          Reads at most len bytes in the supplied buffer and updates the checksum with it.
 long skip(long n)
          Skips n bytes by reading them in a temporary buffer and updating the the checksum with that buffer.
 
Methods inherited from class java13.io.FilterInputStream
available, close, mark, markSupported, read, reset
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CheckedInputStream

public CheckedInputStream(java.io.InputStream in,
                          Checksum sum)
Creates a new CheckInputStream on top of the supplied OutputStream using the supplied Checksum.

Method Detail

getChecksum

public Checksum getChecksum()
Returns the Checksum object used. To get the data checksum computed so far call getChecksum.getValue().


read

public int read()
         throws java.io.IOException
Reads one byte, updates the checksum and returns the read byte (or -1 when the end of file was reached).

Overrides:
read in class FilterInputStream
Returns:
the next byte of data, or -1 if the end of the stream is reached.
Throws:
java.io.IOException - if an I/O error occurs.
See Also:
java.io.FilterInputStream#in

read

public int read(byte[] buf,
                int off,
                int len)
         throws java.io.IOException
Reads at most len bytes in the supplied buffer and updates the checksum with it. Returns the number of bytes actually read or -1 when the end of file was reached.

Overrides:
read in class FilterInputStream
Parameters:
buf - the buffer into which the data is read.
off - the start offset of the data.
len - the maximum number of bytes read.
Returns:
the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
Throws:
java.io.IOException - if an I/O error occurs.
See Also:
java.io.FilterInputStream#in

skip

public long skip(long n)
          throws java.io.IOException
Skips n bytes by reading them in a temporary buffer and updating the the checksum with that buffer. Returns the actual number of bytes skiped which can be less then requested when the end of file is reached.

Overrides:
skip in class FilterInputStream
Parameters:
n - the number of bytes to be skipped.
Returns:
the actual number of bytes skipped.
Throws:
java.io.IOException - if an I/O error occurs.