Build 1.0_r1(from source)

java.security
Class DigestInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by java.security.DigestInputStream
All Implemented Interfaces:
Closeable

public class DigestInputStream
extends FilterInputStream


Field Summary
protected  MessageDigest digest
           
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
DigestInputStream(InputStream stream, MessageDigest digest)
           
 
Method Summary
 MessageDigest getMessageDigest()
          Returns the MessageDigest which the receiver uses when computing the hash.
 void on(boolean on)
          Enables or disables the digest function (default is on).
 int read()
          Reads the next byte and returns it as an int.
 int read(byte[] b, int off, int len)
          Reads at most count bytes from this FilterInputStream and stores them in byte array buffer starting at offset.
 void setMessageDigest(MessageDigest digest)
          Sets the MessageDigest which the receiver will use when computing the hash.
 String toString()
          Returns a string containing a concise, human-readable description of the receiver.
 
Methods inherited from class java.io.FilterInputStream
available, close, mark, markSupported, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

digest

protected MessageDigest digest
Constructor Detail

DigestInputStream

public DigestInputStream(InputStream stream,
                         MessageDigest digest)
Method Detail

getMessageDigest

public MessageDigest getMessageDigest()
Returns the MessageDigest which the receiver uses when computing the hash.

Returns:
MessageDigest the digest the receiver uses when computing the hash.

setMessageDigest

public void setMessageDigest(MessageDigest digest)
Sets the MessageDigest which the receiver will use when computing the hash.

Parameters:
digest - MessageDigest the digest to use when computing the hash.
See Also:
MessageDigest, on(boolean)

read

public int read()
         throws IOException
Reads the next byte and returns it as an int. Updates the digest for the byte if this function is enabled.

Overrides:
read in class FilterInputStream
Returns:
int the byte which was read or -1 at end of stream.
Throws:
IOException - If reading the source stream causes an IOException.

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Description copied from class: FilterInputStream
Reads at most count bytes from this FilterInputStream and stores them in byte array buffer starting at offset. Answer the number of bytes actually read or -1 if no bytes were read and end of stream was encountered. This implementation reads bytes from the target stream.

Overrides:
read in class FilterInputStream
Parameters:
b - the byte array in which to store the read bytes.
off - the offset in buffer to store the read bytes.
len - the maximum number of bytes to store in buffer.
Returns:
the number of bytes actually read or -1 if end of stream.
Throws:
IOException - If the stream is already closed or another IOException occurs.

on

public void on(boolean on)
Enables or disables the digest function (default is on).

Parameters:
on - boolean true if the digest should be computed, and false otherwise.
See Also:
MessageDigest

toString

public String toString()
Returns a string containing a concise, human-readable description of the receiver.

Overrides:
toString in class Object
Returns:
String a printable representation for the receiver.

Build 1.0_r1(from source)

Please submit a feedback, bug or feature