HTTPClient
Class MD5InputStream

java.lang.Object
  extended byjava.io.InputStream
      extended byjava.io.FilterInputStream
          extended byHTTPClient.MD5InputStream

class MD5InputStream
extends FilterInputStream

This class calculates a running md5 digest of the data read. When the stream is closed the calculated digest is passed to a HashVerifier which is expected to verify this digest and to throw an Exception if it fails.


Field Summary
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
MD5InputStream(InputStream is, HashVerifier verifier)
           
 
Method Summary
 void close()
          Close the stream and check the digest.
 int read()
           
 int read(byte[] buf, int off, int len)
           
 long skip(long num)
           
 
Methods inherited from class java.io.FilterInputStream
available, mark, markSupported, read, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MD5InputStream

public MD5InputStream(InputStream is,
                      HashVerifier verifier)
Parameters:
is - the input stream over which the md5 hash is to be calculated
verifier - the HashVerifier to invoke when the stream is closed
Method Detail

read

public int read()
         throws IOException
Throws:
IOException

read

public int read(byte[] buf,
                int off,
                int len)
         throws IOException
Throws:
IOException

skip

public long skip(long num)
          throws IOException
Throws:
IOException

close

public void close()
           throws IOException
Close the stream and check the digest. If the stream has not been fully read then the rest of the data will first be read (and discarded) to complete the digest calculation.

Throws:
IOException - if the close()'ing the underlying stream throws an IOException, or if the expected digest and the calculated digest don't match.