FileDocCategorySizeDatePackage
DigestOutputStream.javaAPI DocAndroid 1.5 API4455Wed May 06 22:41:06 BST 2009java.security

DigestOutputStream

public class DigestOutputStream extends FilterOutputStream
{@code DigestOutputStream} is a {@code FilterOutputStream} which maintains an associated message digest.

Fields Summary
protected MessageDigest
digest
The message digest for this stream.
private boolean
isOn
Constructors Summary
public DigestOutputStream(OutputStream stream, MessageDigest digest)
Constructs a new instance of this {@code DigestOutputStream}, using the given {@code stream} and the {@code digest}.

param
stream the output stream.
param
digest the message digest.
since
Android 1.0


                                                              
         
        super(stream);
        this.digest = digest;
    
Methods Summary
public java.security.MessageDigestgetMessageDigest()
Returns the message digest for this stream.

return
the message digest for this stream.
since
Android 1.0

        return digest;
    
public voidon(boolean on)
Enables or disables the digest function (default is on).

param
on {@code true} if the digest should be computed, {@code false} otherwise.
since
Android 1.0

        isOn = on;
    
public voidsetMessageDigest(java.security.MessageDigest digest)
Sets the message digest which this stream will use.

param
digest the message digest which this stream will use.
since
Android 1.0

        this.digest = digest;
    
public java.lang.StringtoString()
Returns a string containing a concise, human-readable description of this {@code DigestOutputStream} including the digest.

return
a printable representation for this {@code DigestOutputStream}.
since
Android 1.0

        return super.toString() + ", " + digest.toString() + //$NON-NLS-1$
            (isOn ? ", is on" : ", is off"); //$NON-NLS-1$ //$NON-NLS-2$
    
public voidwrite(int b)
Writes the specified {@code int} to the stream. Updates the digest if this function is {@link #on(boolean)}.

param
b the byte to be written.
throws
IOException if writing to the stream causes a {@code IOException}
since
Android 1.0

        // update digest only if digest functionality is on
        if (isOn) {
            digest.update((byte)b);
        }
        // write the byte
        out.write(b);
    
public voidwrite(byte[] b, int off, int len)
Writes {@code len} bytes into the stream, starting from the specified offset. Updates the digest if this function is {@link #on(boolean)}.

param
b the buffer to write to.
param
off the index of the first byte in {@code b} to write.
param
len the number of bytes in {@code b} to write.
throws
IOException if writing to the stream causes an {@code IOException}.
since
Android 1.0

        // update digest only if digest functionality is on
        if (isOn) {
            digest.update(b, off, len);
        }
        // write len bytes
        out.write(b, off, len);