public class CheckedOutputStream extends FilterOutputStream
CheckedOutputStream
class is used to maintain a running checksum
of all data written to a stream. The purpose of this checksum is to establish
data integrity, by publishing the checksum to other parties wanting to read
the non corrupted data.out
Constructor and Description |
---|
CheckedOutputStream(OutputStream os,
Checksum cs)
Constructs a new
CheckedOutputStream on OutputStream
os . |
Modifier and Type | Method and Description |
---|---|
Checksum |
getChecksum()
Returns the checksum calculated on the stream read so far.
|
void |
write(byte[] buf,
int off,
int nbytes)
Writes n bytes of data from
buf starting at offset off to
the underlying stream. |
void |
write(int val)
Writes the specified byte to the underlying stream.
|
close, flush
write
public CheckedOutputStream(OutputStream os, Checksum cs)
CheckedOutputStream
on OutputStream
os
. The checksum is calculated using the algorithm implemented
by csum
.os
- the output stream to calculate checksum for.cs
- an entity implementing the checksum algorithm.public Checksum getChecksum()
public void write(int val) throws IOException
val
.write
in class FilterOutputStream
val
- the data value to written to the output stream.IOException
- if an IO error has occurred.public void write(byte[] buf, int off, int nbytes) throws IOException
buf
starting at offset off
to
the underlying stream. The checksum is updated with the bytes written.write
in class FilterOutputStream
buf
- data written to the output stream.off
- the offset to start reading the data from buf
written
to the output stream.nbytes
- number of bytes to write to the output stream.IOException
- if an IO error has occurred.