Package java.util.zip

Class 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.
    • Constructor Detail

      • CheckedOutputStream

        public CheckedOutputStream​(OutputStream os,
                                   Checksum cs)
        Constructs a new CheckedOutputStream on OutputStream os. The checksum is calculated using the algorithm implemented by csum.
        Parameters:
        os - the output stream to calculate checksum for.
        cs - an entity implementing the checksum algorithm.
    • Method Detail

      • getChecksum

        public Checksum getChecksum()
        Returns the checksum calculated on the stream read so far.
        Returns:
        the updated checksum.
      • write

        public void write​(int val)
                   throws IOException
        Writes the specified byte to the underlying stream. The checksum is updated with val.
        Overrides:
        write in class FilterOutputStream
        Parameters:
        val - the data value to written to the output stream.
        Throws:
        IOException - if an IO error has occurred.
      • write

        public void write​(byte[] buf,
                          int off,
                          int nbytes)
                   throws IOException
        Writes n bytes of data from buf starting at offset off to the underlying stream. The checksum is updated with the bytes written.
        Overrides:
        write in class FilterOutputStream
        Parameters:
        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.
        Throws:
        IOException - if an IO error has occurred.