net.sf.zipme
Class CheckedInputStream

java.lang.Object
  extended byjava.io.InputStream
      extended bynet.sf.zipme.CheckedInputStream

public class CheckedInputStream
extends java.io.InputStream

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

See Also:
Checksum

Field Summary
protected  java.io.InputStream in
          This is the subordinate InputStream to which method calls are redirected
 
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
 int available()
          Calls the in.available() method.
 void close()
          This method closes the input stream by closing the input stream that this object is filtering.
 Checksum getChecksum()
          Returns the Checksum object used.
 void mark(int readlimit)
          Calls the in.mark(int) method.
 boolean markSupported()
          Calls the in.markSupported() method.
 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)
          Calls the read(byte[], int, int) overloaded method.
 int read(byte[] buf, int off, int len)
          Reads at most len bytes in the supplied buffer and updates the checksum with it.
 void reset()
          Calls the in.reset() method.
 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.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

in

protected java.io.InputStream in
This is the subordinate InputStream to which method calls are redirected

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).

Throws:
java.io.IOException

read

public int read(byte[] buf)
         throws java.io.IOException
Calls the read(byte[], int, int) overloaded method. Note that this method does not redirect its call directly to a corresponding method in in. This allows subclasses to override only the three argument version of read.

Parameters:
buf - The buffer to read bytes into
Returns:
The value retured from in.read(byte[], int, int)
Throws:
java.io.IOException - If an error occurs

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.

Throws:
java.io.IOException

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.

Throws:
java.io.IOException

mark

public void mark(int readlimit)
Calls the in.mark(int) method.

Parameters:
readlimit - The parameter passed to in.mark(int)

markSupported

public boolean markSupported()
Calls the in.markSupported() method.

Returns:
true if mark/reset is supported, false otherwise

reset

public void reset()
           throws java.io.IOException
Calls the in.reset() method.

Throws:
java.io.IOException - If an error occurs

available

public int available()
              throws java.io.IOException
Calls the in.available() method.

Returns:
The value returned from in.available()
Throws:
java.io.IOException - If an error occurs

close

public void close()
           throws java.io.IOException
This method closes the input stream by closing the input stream that this object is filtering. Future attempts to access this stream may throw an exception.

Throws:
java.io.IOException - If an error occurs