net.sf.zipme
Class CheckedOutputStream

java.lang.Object
  extended byjava.io.OutputStream
      extended bynet.sf.zipme.CheckedOutputStream

public class CheckedOutputStream
extends java.io.OutputStream

OutputStream that computes a checksum of data being written using a supplied Checksum object.

See Also:
Checksum

Field Summary
protected  java.io.OutputStream out
          This is the subordinate OutputStream that this class redirects its method calls to.
 
Constructor Summary
CheckedOutputStream(java.io.OutputStream out, Checksum cksum)
          Creates a new CheckInputStream on top of the supplied OutputStream using the supplied Checksum.
 
Method Summary
 void close()
          This method closes the underlying OutputStream.
 void flush()
          This method attempt to flush all buffered output to be written to the underlying output sink.
 Checksum getChecksum()
          Returns the Checksum object used.
 void write(byte[] buf)
          This method writes all the bytes in the specified array to the underlying OutputStream.
 void write(byte[] buf, int off, int len)
          Writes the byte array to the OutputStream and updates the Checksum.
 void write(int bval)
          Writes one byte to the OutputStream and updates the Checksum.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

out

protected java.io.OutputStream out
This is the subordinate OutputStream that this class redirects its method calls to.

Constructor Detail

CheckedOutputStream

public CheckedOutputStream(java.io.OutputStream out,
                           Checksum cksum)
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().


write

public void write(int bval)
           throws java.io.IOException
Writes one byte to the OutputStream and updates the Checksum.

Throws:
java.io.IOException

write

public void write(byte[] buf)
           throws java.io.IOException
This method writes all the bytes in the specified array to the underlying OutputStream. It does this by calling the three parameter version of this method - write(byte[], int, int) in this class instead of writing to the underlying OutputStream directly. This allows most subclasses to avoid overriding this method.

Parameters:
buf - The byte array to write bytes from
Throws:
java.io.IOException - If an error occurs

write

public void write(byte[] buf,
                  int off,
                  int len)
           throws java.io.IOException
Writes the byte array to the OutputStream and updates the Checksum.

Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
This method closes the underlying OutputStream. Any further attempts to write to this stream may throw an exception.

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

flush

public void flush()
           throws java.io.IOException
This method attempt to flush all buffered output to be written to the underlying output sink.

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