FileDocCategorySizeDatePackage
CheckedOutputStream.javaAPI DocAndroid 1.5 API3208Wed May 06 22:41:02 BST 2009java.util.zip

CheckedOutputStream

public class CheckedOutputStream extends FilterOutputStream
The {@code 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.
since
Android 1.0

Fields Summary
private final Checksum
check
Constructors Summary
public CheckedOutputStream(OutputStream os, Checksum cs)
Constructs a new {@code CheckedOutputStream} on {@code OutputStream} {@code os}. The checksum is calculated using the algorithm implemented by {@code csum}.

param
os the output stream to calculate checksum for.
param
cs an entity implementing the checksum algorithm.
since
Android 1.0

        super(os);
        check = cs;
    
Methods Summary
public java.util.zip.ChecksumgetChecksum()
Returns the checksum calculated on the stream read so far.

return
the updated checksum.
since
Android 1.0

        return check;
    
public voidwrite(int val)
Writes the specified byte to the underlying stream. The checksum is updated with {@code val}.

param
val the data value to written to the output stream.
throws
IOException if an IO error has occurred.
since
Android 1.0

        out.write(val);
        check.update(val);
    
public voidwrite(byte[] buf, int off, int nbytes)
Writes n bytes of data from {@code buf} starting at offset {@code off} to the underlying stream. The checksum is updated with the bytes written.

param
buf data written to the output stream.
param
off the offset to start reading the data from {@code buf} written to the output stream.
param
nbytes number of bytes to write to the output stream.
throws
IOException if an IO error has occurred.
since
Android 1.0

        out.write(buf, off, nbytes);
        check.update(buf, off, nbytes);