Object DigestUtil

  • All Implemented Interfaces:

    
    public class DigestUtil
    
                        

    Utility class for MD5/ETag digest operations. These are digests as expected in S3 responses by the AWS SDKs. For AWS SDK checksum operations (SHA1, SHA256, CRC32, etc.), see ChecksumUtil.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
      public final static DigestUtil INSTANCE
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final static String hexDigestMultipart(List<Path> paths) Calculates a hex encoded MD5 digest for the contents of a list of paths.
      final static String hexDigest(File file)
      final static String hexDigest(String salt, File file)
      final static String hexDigest(InputStream inputStream) Calculates a hex encoded MD5 digest for the content of an inputStream.
      final static String hexDigest(String salt, InputStream inputStream) Calculates a hex encoded MD5 digest for the content of an inputStream.
      final static String base64Digest(InputStream inputStream) Calculates a base64 MD5 digest for the content of an inputStream.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • hexDigestMultipart

         final static String hexDigestMultipart(List<Path> paths)

        Calculates a hex encoded MD5 digest for the contents of a list of paths. This is a special case that emulates how AWS calculates the MD5 Checksums of the parts of a Multipart upload. API Stackoverflow Quote from Stackoverflow: Say you uploaded a 14MB file to a bucket without server-side encryption, and your part size is 5MB. Calculate 3 MD5 checksums corresponding to each part, i.e. the checksum of the first 5MB, the second 5MB, and the last 4MB. Then take the checksum of their concatenation. MD5 checksums are often printed as hex representations of binary data, so make sure you take the MD5 of the decoded binary concatenation, not of the ASCII or UTF-8 encoded concatenation. When that's done, add a hyphen and the number of parts to get the ETag.

        Parameters:
        paths - the list of paths.
        Returns:

        A special hex digest that is used for files uploaded in parts.

      • hexDigest

         final static String hexDigest(InputStream inputStream)

        Calculates a hex encoded MD5 digest for the content of an inputStream.

        Mainly used for comparison of files. E.g. After Putting a File to the Server, the Amazon S3-Client expects a hex encoded MD5 digest as the ETag, as part of the response Header to verify the validity of the transferred file.

        Parameters:
        inputStream - the InputStream.
        Returns:

        String Hex MD5 digest.

      • hexDigest

         final static String hexDigest(String salt, InputStream inputStream)

        Calculates a hex encoded MD5 digest for the content of an inputStream.

        Mainly used for comparison of files. E.g. After Putting a File to the Server, the Amazon S3-Client expects a hex encoded MD5 digest as the ETag, as part of the response Header to verify the validity of the transferred file. For encrypted uploads, the returned digest may not be the same as the local client digest value.

        Parameters:
        salt - Optional salt to add to be digested, for simulating encryption dependent digest.
        inputStream - the InputStream.
        Returns:

        String Hex MD5 digest.

      • base64Digest

         final static String base64Digest(InputStream inputStream)

        Calculates a base64 MD5 digest for the content of an inputStream.

        Mainly used for comparison of files. E.g. After Putting a File to the Server, the Amazon S3-Client expects a base64 MD5 digest, ETag, as part of the response Header to verify the validity of the transferred file.

        Parameters:
        inputStream - the InputStream.
        Returns:

        String Base64 MD5 digest.