Package java.util.zip
Class CheckedOutputStream
java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
java.util.zip.CheckedOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
public class CheckedOutputStream extends FilterOutputStream
The
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.-
Field Summary
Fields inherited from class java.io.FilterOutputStream
out -
Constructor Summary
Constructors Constructor Description CheckedOutputStream(OutputStream os, Checksum cs)Constructs a newCheckedOutputStreamonOutputStreamos. -
Method Summary
Modifier and Type Method Description ChecksumgetChecksum()Returns the checksum calculated on the stream read so far.voidwrite(byte[] buf, int off, int nbytes)Writes n bytes of data frombufstarting at offsetoffto the underlying stream.voidwrite(int val)Writes the specified byte to the underlying stream.Methods inherited from class java.io.FilterOutputStream
close, flushMethods inherited from class java.io.OutputStream
write
-
Constructor Details
-
CheckedOutputStream
Constructs a newCheckedOutputStreamonOutputStreamos. The checksum is calculated using the algorithm implemented bycsum.- Parameters:
os- the output stream to calculate checksum for.cs- an entity implementing the checksum algorithm.
-
-
Method Details
-
getChecksum
Returns the checksum calculated on the stream read so far.- Returns:
- the updated checksum.
-
write
Writes the specified byte to the underlying stream. The checksum is updated withval.- Overrides:
writein classFilterOutputStream- Parameters:
val- the data value to written to the output stream.- Throws:
IOException- if an IO error has occurred.
-
write
Writes n bytes of data frombufstarting at offsetoffto the underlying stream. The checksum is updated with the bytes written.- Overrides:
writein classFilterOutputStream- Parameters:
buf- data written to the output stream.off- the offset to start reading the data frombufwritten to the output stream.nbytes- number of bytes to write to the output stream.- Throws:
IOException- if an IO error has occurred.
-