Package fr.gouv.vitam.common.digest
Class Digest
- java.lang.Object
-
- fr.gouv.vitam.common.digest.Digest
-
public class Digest extends java.lang.Object
Digest 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 Digest
digest(java.io.File in, DigestType algo)
static Digest
digest(java.io.InputStream in, DigestType algo)
java.lang.String
digest64()
java.lang.String
digestHex()
boolean
equals(java.lang.Object obj)
boolean
equalsWithType(byte[] digest, DigestType algo)
boolean
equalsWithType(java.lang.String digest, DigestType algo)
java.io.InputStream
getDigestInputStream(java.io.InputStream inputStream)
Will update the Digest while the returned InputStream will be readjava.io.OutputStream
getDigestOutputStream(java.io.OutputStream outputStream)
Will update the Digest while the returned OutputStream will be readint
hashCode()
Digest
reset()
Reset the DigestLightjava.lang.String
toString()
DigestType
type()
Digest
update(byte[] bytes)
Digest
update(byte[] bytes, int offset, int length)
Digest
update(java.io.File in)
Digest
update(java.io.File in, long start, long limit)
Digest
update(java.io.InputStream inputStream)
Digest
update(java.io.InputStream inputStream, int chunkSize)
Digest
update(java.io.InputStream inputStream, int chunkSize, long limit)
Digest
update(java.lang.String value)
Digest
update(java.nio.ByteBuffer buffer)
Digest
update(java.nio.channels.FileChannel fileChannelInputStream)
Digest
update(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:
toString
in classjava.lang.Object
-
equals
public final boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public final int hashCode()
- Overrides:
hashCode
in 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 final 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 final 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
-
-