org.logi.crypto.io
Class HashInputStream

java.lang.Object
  |
  +--java.io.InputStream
        |
        +--java.io.FilterInputStream
              |
              +--org.logi.crypto.io.HashInputStream

public class HashInputStream
extends java.io.FilterInputStream

This InputStream hashes everything read from an underlying OutputStream and then returns the data. The hash can be retrieved by calling getFingerprint().

Version:
1.0.6
Author:
Logi Ragnarsson (logir@logi.org)
See Also:
HashOutputStream

Constructor Summary
HashInputStream(java.io.InputStream in)
          Creates a new HashInputStream around in.
HashInputStream(java.io.InputStream in, HashState hashState)
          Creates a new HashInputStream around in.
 
Method Summary
 int available()
          Returns the number of bytes that can be read from this input stream without blocking.
 Fingerprint getFingerprint()
          Return a fingerprint of all data read so far.
 boolean markSupported()
          Returns false.
 int read()
          Reads the next byte of data from this input stream.
 int read(byte[] b, int off, int len)
          Reads up to len bytes of data from this input stream into an array of bytes.
 long skip(long n)
          Skips over and discards n bytes of data from the input stream.
 
Methods inherited from class java.io.FilterInputStream
close, mark, read, reset
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HashInputStream

public HashInputStream(java.io.InputStream in,
                       HashState hashState)
Creates a new HashInputStream around in. hashState will be used to calculate fingerprints.

HashInputStream

public HashInputStream(java.io.InputStream in)
Creates a new HashInputStream around in. A new SHA1State will be used to calculate fingerprints.
See Also:
SHA1State
Method Detail

getFingerprint

public Fingerprint getFingerprint()
Return a fingerprint of all data read so far.

read

public int read()
         throws java.io.IOException
Reads the next byte of data from this input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.
Overrides:
read in class java.io.FilterInputStream

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Reads up to len bytes of data from this input stream into an array of bytes. This method blocks until some input is available.

The actual number of bytes read is returned or -1 if the end of the stream is reached.

Overrides:
read in class java.io.FilterInputStream

skip

public long skip(long n)
          throws java.io.IOException
Skips over and discards n bytes of data from the input stream. The skip method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly 0. The actual number of bytes skipped is returned.

The skipped data will NOT be incorporated into the hash.

Overrides:
skip in class java.io.FilterInputStream

available

public int available()
              throws java.io.IOException
Returns the number of bytes that can be read from this input stream without blocking.
Overrides:
available in class java.io.FilterInputStream

markSupported

public boolean markSupported()
Returns false. (This could be implemented, but I've never seen it used. Mail me if you want it!)
Overrides:
markSupported in class java.io.FilterInputStream


Copyright (c) 1997-2001 Logi Ragnarsson - Distributed under the GPL