com.novell.java.security
Class DigestOutputStream
java.lang.Object
|
+--java.io.OutputStream
|
+--java.io.FilterOutputStream
|
+--com.novell.java.security.DigestOutputStream
- public class DigestOutputStream
- extends java.io.FilterOutputStream
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 ouput
stream's write() methods.
It is possible to turn this stream ON or OFF by calling the on()
method. When it is ON, a call to write() results in an update on
the message digest. When the output stream is OFF, the message
digest is not updated. The default is for the stream to be ON.
- See Also:
MessageDigest
,
DigestInputStream
Fields inherited from class java.io.FilterOutputStream |
out |
Constructor Summary |
DigestOutputStream(java.io.OutputStream stream,
MessageDigest digest)
Creates a digest output stream using the specified output
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. |
void |
setMessageDigest(MessageDigest digest)
Associates the specified message digest with this stream. |
java.lang.String |
toString()
Prints a String representation of this digest output stream and
its associated message digest object. |
void |
write(byte[] b,
int off,
int len)
Updates the message digest using the specified subarray,
and writes the subarray to the output stream. |
void |
write(int b)
Updates the message digest using the specified byte. |
Methods inherited from class java.io.FilterOutputStream |
close,
flush,
write |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
DigestOutputStream
public DigestOutputStream(java.io.OutputStream stream,
MessageDigest digest)
- Creates a digest output stream using the specified output
stream and message digest.
- Parameters:
stream
- The output stream.digest
- The message digest to associate with this stream.
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.
write
public void write(int b)
throws java.io.IOException
- Updates the message digest using the specified byte. The
update is done only if the digest function is ON. Following
the update the byte is written to the output stream. If the
digest function is set to ON by the on() method, the write
method calls the update() method on the message digest
associated with this stream, passing it the byte b. The byte
is then written to the output stream, blocking until the byte
is actually written.
- Parameters:
b
- The byte to be used for updating and writing to the
output stream.- Throws:
- java.io.IOException - Thrown if an I/O error occurs.
- Overrides:
- write in class java.io.FilterOutputStream
- See Also:
MessageDigest.update(byte)
write
public void write(byte[] b,
int off,
int len)
throws java.io.IOException
- Updates the message digest using the specified subarray,
and writes the subarray to the output stream. The update is
done only if the digest function is set to ON by calling
the on() method. That is, if the digest function is ON, this
write() method calls update() on the message digest associated
with this stream, passing it the subarray specifications.
This write() method then writes the subarray bytes to the
output stream, blocking until the bytes are actually written.
- Parameters:
b
- The array containing the subarray to be used for
updating and writing to the output stream.off
- The offset into the byte array (b[]) of the first
byte to be updated and written.len
- The number of bytes of data to be updated and written
from the byte array (b[]), starting at offset specified by
the off parameter.- Throws:
- java.io.IOException - if an I/O error occurs.
- Overrides:
- write in class java.io.FilterOutputStream
- 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 the write() function results in an update on the
message digest. When the digest function is OFF the message
digest is not updated.
- Parameters:
on
- A boolean set to TRUE to turn the digest function ON,
and FALSE to turn it OFF.
toString
public java.lang.String toString()
- Prints a String representation of this digest output stream and
its associated message digest object.
- Overrides:
- toString in class java.lang.Object