Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.novell.java.security
Class DigestInputStream

    java.lang.Object
      |
      +--java.io.InputStream
            |
            +--java.io.FilterInputStream
                  |
                  +--com.novell.java.security.DigestInputStream

public class DigestInputStream
extends java.io.FilterInputStream

Provides a transparent stream that updates the associated message digest using the bits going through the stream. To complete the message digest computation, call one of the digest methods on the associated message digest after calling one of this digest input stream's read() methods.

It is possible to turn this stream on or off by calling the on() method. When it is on, a call to read() results in an update on the message digest. But when it is off, the message digest is not updated. The default is for the stream to be on.

Note that digest objects can compute only one digest, so that in order to compute intermediate digests, you should retain a handle on the digest object and clone it for each digest to be computed, leaving the orignal digest untouched.

See Also:
  `MessageDigest`, `DigestOutputStream`

Constructor Summary
`DigestInputStream(java.io.InputStream stream, MessageDigest digest)` Creates a digest input stream using the specified input stream and message digest.

Method Summary
`MessageDigest` | `getMessageDigest()` Returns the message digest associated with this stream.
`void` | `on(boolean on)` Turns the digest function ON (default) or OFF.
`int` | `read()` Reads a byte and updates the message digest if the digest function is on.
`int` | `read(byte[] b, int off, int len)` Reads into a byte array and updates the message digest if the digest function is on.
`void` | `setMessageDigest(MessageDigest digest)` Associates the specified message digest with this stream.
`java.lang.String` | `toString()` Prints a String representation of this digest input stream and its associated message digest object.

Methods inherited from class java.io.FilterInputStream
`available, close, mark, markSupported, read, reset, skip`

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### DigestInputStream

    public DigestInputStream(java.io.InputStream stream,
                             MessageDigest digest)

  Creates a digest input stream using the specified input stream and message digest.
  Parameters:
    `stream` - The input stream.
    `digest` - The message digest to associate with this stream.

Method Detail

### getMessageDigest

    public MessageDigest getMessageDigest()

  Returns the message digest associated with this stream.
  Returns:
    The message digest associated with this stream.

### setMessageDigest

    public void setMessageDigest(MessageDigest digest)

  Associates the specified message digest with this stream.
  Parameters:
    `digest` - The message digest to be associated with this stream.

### read

    public int read()
             throws java.io.IOException

  Reads a byte and updates the message digest if the digest function is on. It reads a byte from the input stream, blocking until the byte is actually read. If the digest function is on, the read() method will then call the update() method on the message digest associated with this stream, passing it the byte that was read.
  Returns:
    The byte that was read.
  Throws:
    java.io.IOException - Thrown if an I/O error occurs.
  Overrides:
    read in class java.io.FilterInputStream
  See Also:
    `MessageDigest.update(byte)`

### read

    public int read(byte[] b,
                    int off,
                    int len)
             throws java.io.IOException

  Reads into a byte array and updates the message digest if the digest function is on. It reads up to len bytes from the input stream into the array b[], starting at offset off. This read() method blocks until the data is actually read. If the digest function is on, read() will then call the update() method on the message digest associated with this stream, passing it the data.
  Parameters:
    `b` - The array into which the data is read.
    `off` - The starting offset into the byte array (b[]) where the data should be placed.
    `len` - The maximum number of bytes to be read from the input stream into the byte array (b[]), starting at offset off.
  Returns:
    The actual number of bytes read. This is less than len if the end of the stream is reached prior to reading len bytes. A -1 is returned if no bytes were read because the end of the stream had already been reached when the call was made.
  Throws:
    java.io.IOException - Thrown if an I/O error occurs.
  Overrides:
    read in class java.io.FilterInputStream
  See Also:
    `MessageDigest.update(byte[], int, int)`

### on

    public void on(boolean on)

  Turns the digest function ON (default) or OFF. When it is ON, a call to read() results in an update on the message digest. But when it is OFF, the message digest is not updated.
  Parameters:
    `on` - A boolean set to TRUE to set the digest function ON, or false to turn the digest function off.

### toString

    public java.lang.String toString()

  Prints a String representation of this digest input stream and its associated message digest object.
  Overrides:
    toString in class java.lang.Object

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD