Source:
<code>public void run() { if(blobStore.get() == null) { System.out.println("Creating connection for thread " + Thread.currentThread()); resetBlobstore(username, password, provider, region); } if(container.get() == null) { container.set(UUID.randomUUID().toString()); Location location = getOnlyElement(blobStore.get().listAssignableLocations()); blobStore.get().createContainerInLocation(location, container.get()); System.out.println("Created container " + container.get() + " for thread " + Thread.currentThread() + " in " + location.toString()); } String md5Local, md5Remote; Blob blob = null; FileInputStream fis = null; try { fis = new FileInputStream(file); md5Local = DigestUtils.md5Hex(fis); <START> fis.close(); <END> } catch (java.io.IOException e) { e.printStackTrace(); return; } do { System.out.println("Uploading " + file.getName() + " ; " + FileUtils.sizeOf(file)); try { blob = blobStore.get().blobBuilder(file.getName()) .payload(Payloads.newInputStreamPayload(new BufferedInputStream(new FileInputStream(file)))) .build(); } catch (FileNotFoundException e) { e.printStackTrace(); return; } md5Remote = blobStore.get().putBlob(container.get(), blob); if(md5Local.equals(md5Remote)) { long total = BlobUploaderMain.bytesUploaded.addAndGet(FileUtils.sizeOf(file)); System.out.println("Uploaded MB: " + (int)total / FileUtils.ONE_MB + "MB ; " + (int)((float)BlobUploaderMain.bytesUploaded.get()/BlobUploaderMain.totalBytes)*100 +"%"); return; } else { System.out.println("Retrying " + file.getName()); } } while(true); }</code><technical_language>This is exception-safe, need call close in finally. instead of this yourself, Guava Hashing.md5 BaseEncoding.base16</technical_language>

Target:
public void run() { if (blobStore.get() == null) { System.out.println("Creating connection for thread " + Thread.currentThread()); resetBlobstore(username, password, provider, region); } if (container.get() == null) { container.set(UUID.randomUUID().toString()); Location location = getOnlyElement(blobStore.get().listAssignableLocations()); blobStore.get().createContainerInLocation(location, container.get()); System.out.println("Created container " + container.get() + " for thread " + Thread.currentThread() + " in " + location.toString()); } String md5Local; String md5Remote; Blob blob; try { md5Local = BaseEncoding.base16().encode(Files.hash(file, Hashing.md5()).asBytes()).toLowerCase(); } catch (java.io.IOException e) { e.printStackTrace(); return; } ByteSourcePayload bsp = new ByteSourcePayload(Files.asByteSource(file)); do { System.out.println("Uploading " + file.getName() + " ; " + FileUtils.sizeOf(file)); blob = blobStore.get().blobBuilder(file.getName()) .payload(bsp) .build(); md5Remote = blobStore.get().putBlob(container.get(), blob).toLowerCase(); if (md5Local.equals(md5Remote)) { long total = BlobUploaderMain.bytesUploaded.addAndGet(FileUtils.sizeOf(file)); System.out.println("Uploaded MB: " + (int)total / FileUtils.ONE_MB + "MB ; " + (int)((float)BlobUploaderMain.bytesUploaded.get() / BlobUploaderMain.totalBytes) * 100 + "%"); bsp.release(); return; } else { System.out.printf("md5 mismatch %s vs %s, retrying %s", md5Local, md5Remote, file.getName()); } } while(true); }