Class HashCalculator
java.lang.Object
com.pnfsoftware.jeb.util.encoding.HashCalculator
Memory and CPU efficient way to compute message digests.
This class supersedes Hash.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionHashCalculator(InputStream in, int flags) Create a calculator for the requested checksum and digest algorithms. -
Method Summary
Modifier and TypeMethodDescriptionstatic final Longadler32(InputStream in) Compute an Adler-32 checksum for an input stream.booleancompute()Compute the requested digests and stream size.static final Longcrc32(InputStream in) Compute a CRC-32 checksum for an input stream.longGet the computed Adler-32 checksum.longgetCrc32()Get the computed CRC-32 checksum.byte[]getMd5()Get the computed MD5 digest.byte[]getSha1()Get the computed SHA-1 digest.byte[]Get the computed SHA-256 digest.longgetSize()Get the number of bytes consumed during computation.static final byte[]md5(InputStream in) Compute an MD5 digest for an input stream.static final byte[]sha1(InputStream in) Compute a SHA-1 digest for an input stream.static final byte[]sha256(InputStream in) Compute a SHA-256 digest for an input stream.
-
Field Details
-
CRC32
public static final int CRC32Compute a CRC-32 checksum.- See Also:
-
ADLER32
public static final int ADLER32Compute an Adler-32 checksum.- See Also:
-
MD5
public static final int MD5Compute an MD5 digest.- See Also:
-
SHA1
public static final int SHA1Compute a SHA-1 digest.- See Also:
-
SHA256
public static final int SHA256Compute a SHA-256 digest.- See Also:
-
-
Constructor Details
-
Method Details
-
crc32
Compute a CRC-32 checksum for an input stream.- Parameters:
in- input stream to consume- Returns:
- checksum value, or null if reading failed
-
adler32
Compute an Adler-32 checksum for an input stream.- Parameters:
in- input stream to consume- Returns:
- checksum value, or null if reading failed
-
md5
Compute an MD5 digest for an input stream.- Parameters:
in- input stream to consume- Returns:
- digest bytes, or null if reading failed or the digest is unavailable
-
sha1
Compute a SHA-1 digest for an input stream.- Parameters:
in- input stream to consume- Returns:
- digest bytes, or null if reading failed or the digest is unavailable
-
sha256
Compute a SHA-256 digest for an input stream.- Parameters:
in- input stream to consume- Returns:
- digest bytes, or null if reading failed or the digest is unavailable
-
getSize
public long getSize()Get the number of bytes consumed during computation.- Returns:
- stream size in bytes
-
getCrc32
public long getCrc32()Get the computed CRC-32 checksum.- Returns:
- CRC-32 value
-
getAdler32
public long getAdler32()Get the computed Adler-32 checksum.- Returns:
- Adler-32 value
-
getMd5
public byte[] getMd5()Get the computed MD5 digest.- Returns:
- digest bytes
-
getSha1
public byte[] getSha1()Get the computed SHA-1 digest.- Returns:
- digest bytes
-
getSha256
public byte[] getSha256()Get the computed SHA-256 digest.- Returns:
- digest bytes
-
compute
Compute the requested digests and stream size.- Returns:
- true on success, false if one of the requested digest algorithm is not available
- Throws:
IOException- on stream IO error
-