org.nuiton.util
Class MD5InputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
java.security.DigestInputStream
org.nuiton.util.MD5InputStream
- All Implemented Interfaces:
- java.io.Closeable
public class MD5InputStream
- extends java.security.DigestInputStream
MD5InputStream, a subclass of FilterInputStream implementing MD5
functionality on a stream.
- Author:
- tchemit
|
Field Summary |
protected long |
streamLength
length of readed stream |
| Fields inherited from class java.security.DigestInputStream |
digest |
| Fields inherited from class java.io.FilterInputStream |
in |
|
Constructor Summary |
MD5InputStream(java.io.InputStream in)
Creates a MD5InputStream |
|
Method Summary |
protected static java.security.MessageDigest |
getMD5Digest()
|
long |
getStreamLength()
|
byte[] |
hash()
Returns array of bytes representing hash of the stream as finalized for
the current state. |
static byte[] |
hash(java.io.InputStream input)
Compute the MD5 for the given input. |
static byte[] |
hash(java.lang.String input)
Compute the MD5 for the given input sring. |
int |
read()
|
int |
read(byte[] bytes,
int offset,
int length)
|
| Methods inherited from class java.security.DigestInputStream |
getMessageDigest, on, setMessageDigest, toString |
| Methods inherited from class java.io.FilterInputStream |
available, close, mark, markSupported, read, reset, skip |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
streamLength
protected long streamLength
- length of readed stream
MD5InputStream
public MD5InputStream(java.io.InputStream in)
- Creates a MD5InputStream
- Parameters:
in - The input stream
getMD5Digest
protected static java.security.MessageDigest getMD5Digest()
hash
public static byte[] hash(java.io.InputStream input)
throws java.io.IOException
- Compute the MD5 for the given
input.
Note: The the stream will be closed after calling the method
even if something was wrong.
- Parameters:
input - the stream to parse
- Returns:
- the MD5 hash for the given input stream
- Throws:
java.io.IOException - if any pb while reading in stream or digest
hash
public static byte[] hash(java.lang.String input)
throws java.io.IOException
- Compute the MD5 for the given
input sring.
- Parameters:
input - the stream to parse
- Returns:
- the MD5 hash for the given input String
- Throws:
java.io.IOException - if any pb while reading in stream or digest
read
public int read()
throws java.io.IOException
- Overrides:
read in class java.security.DigestInputStream
- Throws:
java.io.IOException
read
public int read(byte[] bytes,
int offset,
int length)
throws java.io.IOException
- Overrides:
read in class java.security.DigestInputStream
- Throws:
java.io.IOException
hash
public byte[] hash()
- Returns array of bytes representing hash of the stream as finalized for
the current state.
- Returns:
- hash
- See Also:
MessageDigest.digest()
getStreamLength
public long getStreamLength()
Copyright © 2004-2010 CodeLutin. All Rights Reserved.