Package fr.gouv.vitam.common.digest

# Class Digest

java.lang.Object
fr.gouv.vitam.common.digest.Digest

public class Digest extends Object
Digest implementation

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Digest(DigestType algo)`
  Create one DigestLight
  `Digest(String digest, DigestType algo)`
  Create one DigestLight from parameter

- ## Method Summary

  Modifier and Type
  Method
  Description
  `final byte[]`
  `digest()`
  `static Digest`
  `digest(File in, DigestType algo)`
  `static Digest`
  `digest(InputStream in, DigestType algo)`
  `final String`
  `digest64()`
  `final String`
  `digestHex()`
  `final boolean`
  `equals(Object obj)`
  `final boolean`
  `equalsWithType(byte[] digest, DigestType algo)`
  `final boolean`
  `equalsWithType(String digest, DigestType algo)`
  `InputStream`
  `getDigestInputStream(InputStream inputStream)`
  Will update the Digest while the returned InputStream will be read
  `OutputStream`
  `getDigestOutputStream(OutputStream outputStream)`
  Will update the Digest while the returned OutputStream will be read
  `final int`
  `hashCode()`
  `final Digest`
  `reset()`
  Reset the DigestLight
  `final String`
  `toString()`
  `final DigestType`
  `type()`
  `final Digest`
  `update(byte[] bytes)`
  `final Digest`
  `update(byte[] bytes, int offset, int length)`
  `final Digest`
  `update(File in)`
  `final Digest`
  `update(File in, long start, long limit)`
  `final Digest`
  `update(InputStream inputStream)`
  `final Digest`
  `update(InputStream inputStream, int chunkSize)`
  `final Digest`
  `update(InputStream inputStream, int chunkSize, long limit)`
  `final Digest`
  `update(String value)`
  `final Digest`
  `update(ByteBuffer buffer)`
  `final Digest`
  `update(FileChannel fileChannelInputStream)`
  `final Digest`
  `update(FileChannel fileChannelInputStream, long start, int chunkSize, long limit)`

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### Digest

    public Digest(DigestType algo)
    Create one DigestLight
    Parameters:
      `algo` - the algorithm to use
    Throws:
      `IllegalArgumentException` - if null or unknown algorithm

  - ### Digest

    public Digest(String digest, DigestType algo)
    Create one DigestLight from parameter
    Parameters:
      `digest` - as String to create
      `algo` - the algorithm to use
    Throws:
      `IllegalArgumentException` - if null or unknown algorithm or if digest is null or empty

- ## Method Details

  - ### 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:
      `IllegalArgumentException` - if bytes null

  - ### update

    public final Digest update(byte[] bytes, int offset, int length)
    Parameters:
      `bytes` - the bytes from which to update
      `offset` - the offset position
      `length` - the length
    Returns:
      this
    Throws:
      `IllegalArgumentException` - if bytes null, offset < 0, length < 0

  - ### update

    public final Digest update(ByteBuffer buffer)
    Parameters:
      `buffer` - for updating Digest
    Returns:
      this
    Throws:
      `IllegalArgumentException` - if buffer null

  - ### update

    public final Digest update(String value)
    Parameters:
      `value` - the String value from which to update
    Returns:
      this
    Throws:
      `IllegalArgumentException` - value null

  - ### update

    public final Digest update(File in) throws IOException
    Parameters:
      `in` - the file from which to update
    Returns:
      this
    Throws:
      `IOException` - if any IO error occurs
      `IllegalArgumentException` - in null

  - ### update

    public final Digest update(File in, long start, long limit) throws IOException
    Parameters:
      `in` - the file from which to update
      `start` - the position to start
      `limit` - if less than 0, means all
    Returns:
      this
    Throws:
      `IOException` - if any IO error occurs
      `IllegalArgumentException` - in null, start < 0

  - ### update

    public final Digest update(InputStream inputStream) throws IOException
    Parameters:
      `inputStream` - the inputstream from which to update using default chunksize
    Returns:
      this
    Throws:
      `IOException` - if any IO error occurs
      `IllegalArgumentException` - inputstream null

  - ### update

    public final Digest update(InputStream inputStream, int chunkSize) throws IOException
    Parameters:
      `inputStream` - the inputstream from which to update
      `chunkSize` - the chunksize to use
    Returns:
      this
    Throws:
      `IOException` - if any IO error occurs
      `IllegalArgumentException` - inputstream null, chunksize < 1

  - ### update

    public final Digest update(InputStream inputStream, int chunkSize, long limit) throws IOException
    Parameters:
      `inputStream` - the inputstream from which to update
      `chunkSize` - the chunksize to use
      `limit` - if less than 0, means all
    Returns:
      this
    Throws:
      `IOException` - if any IO error occurs
      `IllegalArgumentException` - inputstream null, chunksize < 1

  - ### update

    public final Digest update(FileChannel fileChannelInputStream) throws IOException
    Parameters:
      `fileChannelInputStream` - the FileChannel inputstream from which to update
    Returns:
      this
    Throws:
      `IOException` - if any IO error occurs
      `IllegalArgumentException` - fileChannelIinputStream null

  - ### update

    public final Digest update(FileChannel fileChannelInputStream, long start, int chunkSize, long limit) throws IOException
    Parameters:
      `fileChannelInputStream` - the FileChannel inputstream from which to update
      `start` - the position to start
      `chunkSize` - the chunksize to use
      `limit` - if less than 0, means all
    Returns:
      this
    Throws:
      `IOException` - if any IO error occurs
      `IllegalArgumentException` - fileChannelIinputStream null, start < 0, chunksize < 1

  - ### getDigestInputStream

    public InputStream getDigestInputStream(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 OutputStream getDigestOutputStream(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 String digestHex()
    Returns:
      the digest in Base16 format

  - ### digest64

    public final String digest64()
    Returns:
      the digest in Base64 format

  - ### toString

    public final String toString()
    Overrides:
      `toString` in class `Object`

  - ### equals

    public final boolean equals(Object obj)
    Overrides:
      `equals` in class `Object`

  - ### hashCode

    public final int hashCode()
    Overrides:
      `hashCode` in class `Object`

  - ### equalsWithType

    public final boolean equalsWithType(String digest, DigestType algo)
    Parameters:
      `digest` - the digest to compare to
      `algo` - 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 use
      `algo` - the associated algorithm
    Returns:
      True if the 2 digests are of the same type and same value

  - ### digest

    public static Digest digest(InputStream in, DigestType algo) throws IOException
    Parameters:
      `in` - the inputstream from which the digest will be computed
      `algo` - the algorithm to use
    Returns:
      the digest for this inputStream
    Throws:
      `IOException` - if any IO error occurs
      `IllegalArgumentException` - in or algo null

  - ### digest

    public static Digest digest(File in, DigestType algo) throws IOException
    Parameters:
      `in` - the file from which the digest will be computed
      `algo` - the algorithm to use
    Returns:
      the digest for this File
    Throws:
      `IOException` - if any IO error occurs
      `IllegalArgumentException` - in or algo null