code: public static byte[] getDigest(Resource<?> resource, MessageDigest digest)
     {
        try (InputStream stream = resource.getResourceInputStream();
                 DigestInputStream digestStream = new DigestInputStream(stream, digest))
        {
           byte[] buffer = new byte[16384];
           while (digestStream.read(buffer, 0, buffer.length) != -1)
           {
           }
        }
        catch (IOException e)
        {
           throw new IllegalStateException("Error calculating digest for resource [" + resource.getFullyQualifiedName()
                    + "]", e);
        }
        return digest.digest();
     }
docs: Returns the {@link Byte} array message digest of {@link #getResourceInputStream()} using the given
  {@link MessageDigest}.