java.util.zip
Class CheckedInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by java.util.zip.CheckedInputStream
All Implemented Interfaces:
Closeable

public class CheckedInputStream
extends FilterInputStream

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

See Also:
Checksum

Field Summary
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
CheckedInputStream(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 java.io.FilterInputStream
available, close, mark, markSupported, read, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CheckedInputStream

public CheckedInputStream(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 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 value returned from in.read()
Throws:
IOException - If an error occurs

read

public int read(byte[] buf,
                int off,
                int len)
         throws 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 to read bytes into
off - The index into the buffer to start storing bytes
len - The maximum number of bytes to read.
Returns:
The value retured from in.read(byte[], int, int)
Throws:
IOException - If an error occurs

skip

public long skip(long n)
          throws 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 requested number of bytes to skip.
Returns:
The value returned from in.skip(long)
Throws:
IOException - If an error occurs