@Override public void mark(int readlimit) { if (markSupported()) { super.mark(readlimit); digestLastMarked = cloneFrom(digest); } }
private void resetDigest() { try { digest = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException("No message digest support for MD5 was found.", e); } digestCanBeCloned = canBeCloned(digest); }
/** * Resets the wrapped input stream and the in progress message digest. */ @Override public void reset() throws IOException { if (markSupported()) { super.reset(); if (digestLastMarked == null) { resetDigest(); } else { digest = cloneFrom(digestLastMarked); } } else { throw new IOException("mark/reset not supported"); } }
input = md5DigestStream = new MD5DigestCalculatingInputStream(input); contentMd5 = Base64.encodeAsString(md5DigestStream.getMd5Digest());
MD5DigestCalculatingInputStream is = new MD5DigestCalculatingInputStream( new ByteArrayInputStream(data)); baExpected = IOUtils.toByteArray(is); byte[] md5 = is.getMd5Digest(); assertTrue(Arrays.equals(md5Expected, md5)); MD5DigestCalculatingInputStream is = new MD5DigestCalculatingInputStream( new ByteArrayInputStream(data)); is.mark(-1); baExpected = IOUtils.toByteArray(is); byte[] md5 = is.getMd5Digest(); assertTrue(Arrays.equals(md5Expected, md5)); is.reset(); byte[] ba = IOUtils.toByteArray(is); byte[] md5_2 = is.getMd5Digest(); assertTrue(Arrays.equals(md5Expected, md5_2)); assertTrue(Arrays.equals(baExpected, ba)); MD5DigestCalculatingInputStream is = new MD5DigestCalculatingInputStream( new ByteArrayInputStream(data)); is.mark(-1); is.read(new byte[10]); is.reset(); byte[] ba = IOUtils.toByteArray(is); if (DEBUG) System.out.println("ba.length: " + ba.length); assertTrue(Arrays.equals(baExpected, ba)); byte[] md5 = is.getMd5Digest();
/** * Resets the wrapped input stream and the in progress message digest. */ @Override public void reset() throws IOException { if (markSupported()) { super.reset(); digest = (digestLastMarked == null) // This is necessary so that should there be a reset without a // preceding mark, the MD5 would still be computed correctly. ? newMD5() : cloneFrom(digestLastMarked); } else { throw new IOException("mark/reset not supported"); } }
byte[] clientSideHash = md5DigestStream.getMd5Digest(); byte[] serverSideHash = BinaryUtils.fromHex(etag);
isCurr = md5DigestStream = new MD5DigestCalculatingInputStream(isCurr);
public MD5DigestCalculatingInputStream(InputStream in) { super(in); resetDigest(); if (in.markSupported() && !digestCanBeCloned) { log.debug("Mark-and-reset disabled on MD5 calculation because the digest implementation does not support cloning. " + "This will limit the SDK's ability to retry requests that failed. Consider pre-calculating the MD5 " + "checksum for the request or switching to a security provider that supports message digest cloning."); } }
/** * Constructor. * @param in input stream */ public MD5DigestCalculatingInputStream(InputStream in) { super(in); digest = newMD5(); }
inputStream = md5DigestStream = new MD5DigestCalculatingInputStream(inputStream); final byte[] clientSideHash = md5DigestStream.getMd5Digest(); final byte[] serverSideHash = BinaryUtils.fromHex(metadata.getETag());
/** * Resets the wrapped input stream and the in progress message digest. */ @Override public void reset() throws IOException { if (markSupported()) { super.reset(); digest = (digestLastMarked == null) // This is necessary so that should there be a reset without a // preceding mark, the MD5 would still be computed correctly. ? newMD5() : cloneFrom(digestLastMarked); } else { throw new IOException("mark/reset not supported"); } }
byte[] clientSideHash = md5DigestStream.getMd5Digest(); byte[] serverSideHash = BinaryUtils.fromHex(etag);
isCurr = md5DigestStream = new MD5DigestCalculatingInputStream(isCurr);
public MD5DigestCalculatingInputStream(InputStream in) { super(in); resetDigest(); if (in.markSupported() && !digestCanBeCloned) { log.debug("Mark-and-reset disabled on MD5 calculation because the digest implementation does not support cloning. " + "This will limit the SDK's ability to retry requests that failed. Consider pre-calculating the MD5 " + "checksum for the request or switching to a security provider that supports message digest cloning."); } }
/** * Constructor. * @param in input stream */ public MD5DigestCalculatingInputStream(InputStream in) { super(in); digest = newMD5(); }
input = md5DigestStream = new MD5DigestCalculatingInputStream(input); contentMd5 = BinaryUtils.toBase64(md5DigestStream.getMd5Digest());
@Override public void mark(int readlimit) { if (markSupported()) { super.mark(readlimit); digestLastMarked = cloneFrom(digest); } }
/** * Resets the wrapped input stream and the in progress message digest. */ @Override public void reset() throws IOException { if (markSupported()) { super.reset(); if (digestLastMarked == null) { resetDigest(); } else { digest = cloneFrom(digestLastMarked); } } else { throw new IOException("mark/reset not supported"); } }
private void resetDigest() { try { digest = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException("No message digest support for MD5 was found.", e); } digestCanBeCloned = canBeCloned(digest); }