Package fr.gouv.vitam.common.digest
Class Digest
- java.lang.Object
-
- fr.gouv.vitam.common.digest.Digest
-
public class Digest extends java.lang.ObjectDigest implementation
-
-
Constructor Summary
Constructors Constructor Description Digest(DigestType algo)Create one DigestLightDigest(java.lang.String digest, DigestType algo)Create one DigestLight from parameter
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]digest()static Digestdigest(java.io.File in, DigestType algo)static Digestdigest(java.io.InputStream in, DigestType algo)java.lang.Stringdigest64()java.lang.StringdigestHex()booleanequals(java.lang.Object obj)booleanequalsWithType(byte[] digest, DigestType algo)booleanequalsWithType(java.lang.String digest, DigestType algo)java.io.InputStreamgetDigestInputStream(java.io.InputStream inputStream)Will update the Digest while the returned InputStream will be readjava.io.OutputStreamgetDigestOutputStream(java.io.OutputStream outputStream)Will update the Digest while the returned OutputStream will be readinthashCode()Digestreset()Reset the DigestLightjava.lang.StringtoString()DigestTypetype()Digestupdate(byte[] bytes)Digestupdate(byte[] bytes, int offset, int length)Digestupdate(java.io.File in)Digestupdate(java.io.File in, long start, long limit)Digestupdate(java.io.InputStream inputStream)Digestupdate(java.io.InputStream inputStream, int chunkSize)Digestupdate(java.io.InputStream inputStream, int chunkSize, long limit)Digestupdate(java.lang.String value)Digestupdate(java.nio.ByteBuffer buffer)Digestupdate(java.nio.channels.FileChannel fileChannelInputStream)Digestupdate(java.nio.channels.FileChannel fileChannelInputStream, long start, int chunkSize, long limit)
-
-
-
Constructor Detail
-
Digest
public Digest(DigestType algo)
Create one DigestLight- Parameters:
algo- the algorithm to use- Throws:
java.lang.IllegalArgumentException- if null or unknown algorithm
-
Digest
public Digest(java.lang.String digest, DigestType algo)Create one DigestLight from parameter- Parameters:
digest- as String to createalgo- the algorithm to use- Throws:
java.lang.IllegalArgumentException- if null or unknown algorithm or if digest is null or empty
-
-
Method Detail
-
type
public final DigestType type()
- Returns:
- the associated digest type
-
update
public final Digest update(byte[] bytes)
- Parameters:
bytes- the bytes from which to update- Returns:
- this
- Throws:
java.lang.IllegalArgumentException- if bytes null
-
update
public final Digest update(byte[] bytes, int offset, int length)
- Parameters:
bytes- the bytes from which to updateoffset- the offset positionlength- the length- Returns:
- this
- Throws:
java.lang.IllegalArgumentException- if bytes null, offset < 0, length < 0
-
update
public final Digest update(java.nio.ByteBuffer buffer)
- Parameters:
buffer- for updating Digest- Returns:
- this
- Throws:
java.lang.IllegalArgumentException- if buffer null
-
update
public final Digest update(java.lang.String value)
- Parameters:
value- the String value from which to update- Returns:
- this
- Throws:
java.lang.IllegalArgumentException- value null
-
update
public final Digest update(java.io.File in) throws java.io.IOException
- Parameters:
in- the file from which to update- Returns:
- this
- Throws:
java.io.IOException- if any IO error occursjava.lang.IllegalArgumentException- in null
-
update
public final Digest update(java.io.File in, long start, long limit) throws java.io.IOException
- Parameters:
in- the file from which to updatestart- the position to startlimit- if less than 0, means all- Returns:
- this
- Throws:
java.io.IOException- if any IO error occursjava.lang.IllegalArgumentException- in null, start < 0
-
update
public final Digest update(java.io.InputStream inputStream) throws java.io.IOException
- Parameters:
inputStream- the inputstream from which to update using default chunksize- Returns:
- this
- Throws:
java.io.IOException- if any IO error occursjava.lang.IllegalArgumentException- inputstream null
-
update
public final Digest update(java.io.InputStream inputStream, int chunkSize) throws java.io.IOException
- Parameters:
inputStream- the inputstream from which to updatechunkSize- the chunksize to use- Returns:
- this
- Throws:
java.io.IOException- if any IO error occursjava.lang.IllegalArgumentException- inputstream null, chunksize < 1
-
update
public final Digest update(java.io.InputStream inputStream, int chunkSize, long limit) throws java.io.IOException
- Parameters:
inputStream- the inputstream from which to updatechunkSize- the chunksize to uselimit- if less than 0, means all- Returns:
- this
- Throws:
java.io.IOException- if any IO error occursjava.lang.IllegalArgumentException- inputstream null, chunksize < 1
-
update
public final Digest update(java.nio.channels.FileChannel fileChannelInputStream) throws java.io.IOException
- Parameters:
fileChannelInputStream- the FileChannel inputstream from which to update- Returns:
- this
- Throws:
java.io.IOException- if any IO error occursjava.lang.IllegalArgumentException- fileChannelIinputStream null
-
update
public final Digest update(java.nio.channels.FileChannel fileChannelInputStream, long start, int chunkSize, long limit) throws java.io.IOException
- Parameters:
fileChannelInputStream- the FileChannel inputstream from which to updatestart- the position to startchunkSize- the chunksize to uselimit- if less than 0, means all- Returns:
- this
- Throws:
java.io.IOException- if any IO error occursjava.lang.IllegalArgumentException- fileChannelIinputStream null, start < 0, chunksize < 1
-
getDigestInputStream
public java.io.InputStream getDigestInputStream(java.io.InputStream inputStream)
Will update the Digest while the returned InputStream will be read- Parameters:
inputStream- from which the data to digest will be done- Returns:
- the new InputStream to use instead of the given one as parameter
-
getDigestOutputStream
public java.io.OutputStream getDigestOutputStream(java.io.OutputStream outputStream)
Will update the Digest while the returned OutputStream will be read- Parameters:
outputStream- to which the data to digest will be written- Returns:
- the new OutputStream to use instead of the given one as parameter
-
reset
public final Digest reset()
Reset the DigestLight- Returns:
- this
-
digest
public final byte[] digest()
- Returns:
- the digest
-
digestHex
public final java.lang.String digestHex()
- Returns:
- the digest in Base16 format
-
digest64
public final java.lang.String digest64()
- Returns:
- the digest in Base64 format
-
toString
public final java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
equals
public final boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public final int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equalsWithType
public final boolean equalsWithType(java.lang.String digest, DigestType algo)- Parameters:
digest- the digest to compare toalgo- the associated algorithm- Returns:
- True if the 2 digests are of the same type and same value
-
equalsWithType
public final boolean equalsWithType(byte[] digest, DigestType algo)- Parameters:
digest- the digest in byte to usealgo- the associated algorithm- Returns:
- True if the 2 digests are of the same type and same value
-
digest
public static Digest digest(java.io.InputStream in, DigestType algo) throws java.io.IOException
- Parameters:
in- the inputstream from which the digest will be computedalgo- the algorithm to use- Returns:
- the digest for this inputStream
- Throws:
java.io.IOException- if any IO error occursjava.lang.IllegalArgumentException- in or algo null
-
digest
public static Digest digest(java.io.File in, DigestType algo) throws java.io.IOException
- Parameters:
in- the file from which the digest will be computedalgo- the algorithm to use- Returns:
- the digest for this File
- Throws:
java.io.IOException- if any IO error occursjava.lang.IllegalArgumentException- in or algo null
-
-