edu.rice.cs.plt.io
Class ChecksumOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by edu.rice.cs.plt.io.DirectOutputStream
          extended by edu.rice.cs.plt.io.ChecksumOutputStream
All Implemented Interfaces:
Closeable, Flushable

public class ChecksumOutputStream
extends DirectOutputStream

A stream that accumulates its bytes in a Checksum object.


Field Summary
 
Fields inherited from class edu.rice.cs.plt.io.DirectOutputStream
DEFAULT_BUFFER_SIZE
 
Constructor Summary
ChecksumOutputStream(Checksum checksum)
          Instantiate with the given Checksum.
 
Method Summary
 void close()
           
 void flush()
           
 long getValue()
          Return checksum.getValue().
static ChecksumOutputStream makeAdler32()
          Create a stream for computing Adler-32 checksums.
static ChecksumOutputStream makeCRC32()
          Create a stream for computing CRC-32 checksums.
 void write(byte[] bbuf)
          Delegate to the more general DirectOutputStream.write(byte[], int, int) method
 void write(byte[] bbuf, int offset, int len)
          Subclasses are, at a minimum, required to implement this method.
 void write(int b)
          Delegate to the more general DirectOutputStream.write(byte[], int, int) method
 
Methods inherited from class edu.rice.cs.plt.io.DirectOutputStream
write, write, write, writeAll, writeAll, writeAll
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChecksumOutputStream

public ChecksumOutputStream(Checksum checksum)
Instantiate with the given Checksum. checksum will not be reset, and may contain a partially-computed value.

Method Detail

getValue

public long getValue()
Return checksum.getValue(). For 32-bit checksums, this can be cast to an int without losing any information.


close

public void close()
Specified by:
close in interface Closeable
Overrides:
close in class OutputStream

flush

public void flush()
Specified by:
flush in interface Flushable
Overrides:
flush in class OutputStream

write

public void write(byte[] bbuf)
Description copied from class: DirectOutputStream
Delegate to the more general DirectOutputStream.write(byte[], int, int) method

Overrides:
write in class DirectOutputStream

write

public void write(byte[] bbuf,
                  int offset,
                  int len)
Description copied from class: DirectOutputStream
Subclasses are, at a minimum, required to implement this method.

Specified by:
write in class DirectOutputStream

write

public void write(int b)
Description copied from class: DirectOutputStream
Delegate to the more general DirectOutputStream.write(byte[], int, int) method

Overrides:
write in class DirectOutputStream

makeCRC32

public static ChecksumOutputStream makeCRC32()
Create a stream for computing CRC-32 checksums.

See Also:
CRC32

makeAdler32

public static ChecksumOutputStream makeAdler32()
Create a stream for computing Adler-32 checksums.

See Also:
Adler32