Source:
public String putBlob(final String containerName, final Blob blob) throws IOException { String blobKey = blob.getMetadata().getName(); Payload payload = blob.getPayload(); filesystemContainerNameValidator.validate(containerName); filesystemBlobKeyValidator.validate(blobKey); if (getDirectoryBlobSuffix(blobKey) != null) { return putDirectoryBlob(containerName, blob); } File outputFile = getFileForBlobKey(containerName, blobKey); Path outputPath = outputFile.toPath(); HashingInputStream his = null; try { Files.createParentDirs(outputFile); his = new HashingInputStream(Hashing.md5(), payload.openStream()); delete(outputFile); Files.asByteSink(outputFile).writeFrom(his); HashCode actualHashCode = his.hash(); HashCode expectedHashCode = payload.getContentMetadata().getContentMD5AsHashCode(); if (expectedHashCode != null && !actualHashCode.equals(expectedHashCode)) { throw new IOException("MD5 hash code mismatch, actual: " + actualHashCode + " expected: " + expectedHashCode); } payload.getContentMetadata().setContentMD5(actualHashCode); UserDefinedFileAttributeView view = getUserDefinedFileAttributeView(outputPath); if (view != null) { try { view.write(XATTR_CONTENT_MD5, ByteBuffer.wrap(actualHashCode.asBytes())); writeCommonMetadataAttr(view, blob); } catch (IOException e) { logger.debug("xattrs not supported on %s", outputPath); } } setBlobAccess(containerName, blobKey, BlobAccess.PRIVATE); return base16().lowerCase().encode(actualHashCode.asBytes()); } catch (IOException ex) { if (outputFile != null) { try { delete(outputFile); } catch (IOException e) { logger.debug("Could not delete %s", e); } } throw ex; } finally { closeQuietly(his); if (payload != null) { payload.release(); } } }

Target:
public String putBlob(final String containerName, final Blob blob) throws IOException { String blobKey = blob.getMetadata().getName(); Payload payload = blob.getPayload(); filesystemContainerNameValidator.validate(containerName); filesystemBlobKeyValidator.validate(blobKey); if (getDirectoryBlobSuffix(blobKey) != null) { return putDirectoryBlob(containerName, blob); } File outputFile = getFileForBlobKey(containerName, blobKey); Path outputPath = outputFile.toPath(); HashingInputStream his = null; try { Files.createParentDirs(outputFile); his = new HashingInputStream(Hashing.md5(), payload.openStream()); delete(outputFile); Files.asByteSink(outputFile).writeFrom(his); HashCode actualHashCode = his.hash(); HashCode expectedHashCode = payload.getContentMetadata().getContentMD5AsHashCode(); if (expectedHashCode != null && !actualHashCode.equals(expectedHashCode)) { throw new IOException("MD5 hash code mismatch, actual: " + actualHashCode + " expected: " + expectedHashCode); } payload.getContentMetadata().setContentMD5(actualHashCode); UserDefinedFileAttributeView view = getUserDefinedFileAttributeView(outputPath); if (view != null) { try { view.write(XATTR_CONTENT_MD5, ByteBuffer.wrap(actualHashCode.asBytes())); writeCommonMetadataAttr(view, blob); } catch (IOException e) { logger.debug("xattrs not supported on %s", outputPath); } } setBlobAccess(containerName, blobKey, BlobAccess.PRIVATE); return base16().lowerCase().encode(actualHashCode.asBytes()); } catch (IOException ex) { if (outputFile != null) { try { delete(outputFile); } catch (IOException e) { logger.debug("Could not delete %s: %s", outputFile, e); } } throw ex; } finally { closeQuietly(his); if (payload != null) { payload.release(); } } }