edu.rice.cs.plt.io
Class MessageDigestOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by edu.rice.cs.plt.io.DirectOutputStream
          extended by edu.rice.cs.plt.io.MessageDigestOutputStream
All Implemented Interfaces:
Closeable, Flushable

public class MessageDigestOutputStream
extends DirectOutputStream

A stream that accumulates its bytes in a MessageDigest object.


Field Summary
 
Fields inherited from class edu.rice.cs.plt.io.DirectOutputStream
DEFAULT_BUFFER_SIZE
 
Constructor Summary
MessageDigestOutputStream(MessageDigest messageDigest)
          Instantiate with the given MessageDigest.
 
Method Summary
 void close()
           
 byte[] digest()
          Return messageDigest.digest().
 void flush()
           
static MessageDigestOutputStream makeMD5()
          Create a stream for computing MD5 hashes.
static MessageDigestOutputStream makeSHA1()
          Create a stream for computing SHA-1 hashes.
static MessageDigestOutputStream makeSHA256()
          Create a stream for computing SHA-256 hashes.
 void write(byte[] bbuf)
          Delegate to the more general DirectOutputStream.write(byte[], int, int) method
 void write(byte[] bbuf, int offset, int len)
          Subclasses are, at a minimum, required to implement this method.
 void write(int b)
          Delegate to the more general DirectOutputStream.write(byte[], int, int) method
 
Methods inherited from class edu.rice.cs.plt.io.DirectOutputStream
write, write, write, writeAll, writeAll, writeAll
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MessageDigestOutputStream

public MessageDigestOutputStream(MessageDigest messageDigest)
Instantiate with the given MessageDigest. messageDigest will not be reset, and may contain a partially-computed digest.

Method Detail

digest

public byte[] digest()
Return messageDigest.digest().


close

public void close()
Specified by:
close in interface Closeable
Overrides:
close in class OutputStream

flush

public void flush()
Specified by:
flush in interface Flushable
Overrides:
flush in class OutputStream

write

public void write(byte[] bbuf)
Description copied from class: DirectOutputStream
Delegate to the more general DirectOutputStream.write(byte[], int, int) method

Overrides:
write in class DirectOutputStream

write

public void write(byte[] bbuf,
                  int offset,
                  int len)
Description copied from class: DirectOutputStream
Subclasses are, at a minimum, required to implement this method.

Specified by:
write in class DirectOutputStream

write

public void write(int b)
Description copied from class: DirectOutputStream
Delegate to the more general DirectOutputStream.write(byte[], int, int) method

Overrides:
write in class DirectOutputStream

makeMD5

public static MessageDigestOutputStream makeMD5()
Create a stream for computing MD5 hashes. Throws a RuntimeException with a NoSuchAlgorithmException cause if the MD5 algorithm implementation cannot be located.


makeSHA1

public static MessageDigestOutputStream makeSHA1()
Create a stream for computing SHA-1 hashes. Throws a RuntimeException with a NoSuchAlgorithmException cause if the SHA-1 algorithm implementation cannot be located.


makeSHA256

public static MessageDigestOutputStream makeSHA256()
Create a stream for computing SHA-256 hashes. Throws a RuntimeException with a NoSuchAlgorithmException cause if the SHA-256 algorithm implementation cannot be located.