Source:
public InputStream streamBlob(final String container, final String name, final ExecutorService executor) { final ListeningExecutorService listeningExecutor = MoreExecutors.listeningDecorator(executor); final PipedOutputStream output; final PipedInputStream input; try { output = new PipedOutputStream(); input = new PipedInputStream(output, getMinimumMultipartPartSize() * 5 > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) getMinimumMultipartPartSize() * 5); } catch (IOException e) { throw new RuntimeException(e); } final long contentLength = api .getObjectApi(regionId, container) .getWithoutBody(name) .getPayload() .getContentMetadata() .getContentLength(); final long partSize = getMinimumMultipartPartSize(); final LinkedBlockingQueue<ListenableFuture<byte[]>> results = new LinkedBlockingQueue<ListenableFuture<byte[]>>(); listeningExecutor.submit(new Runnable() { @Override public void run() { ListenableFuture<byte[]> result; long from; for (from = 0; from < contentLength; from = from + partSize) { try { System.out.println(Thread.currentThread() + " writing to output"); result = results.take(); if (result == null) { output.close(); input.close(); throw new RuntimeException("Error downloading file part to stream"); } output.write(result.get()); } catch (Exception e) { System.out.println(e); try { input.close(); } catch (IOException e1) try { output.close(); } catch (IOException e1) throw new RuntimeException(e); } } Closeables2.closeQuietly(output); } }); listeningExecutor.submit(new Runnable() { @Override public void run() { long from; long to; for (from = 0; from < contentLength; from = from + partSize) { to = (from + partSize >= contentLength) ? contentLength - 1 : from + partSize - 1; BlobStreamDownloader b = new BlobStreamDownloader(container, name, from, to); results.add(listeningExecutor.submit(b)); } } }); return input; }

Target:
public InputStream streamBlob(final String container, final String name, final ExecutorService executor) { final ListeningExecutorService listeningExecutor = MoreExecutors.listeningDecorator(executor); final PipedOutputStream output; final PipedInputStream input; try { output = new PipedOutputStream(); input = new PipedInputStream(output, getMinimumMultipartPartSize() * 5 > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) getMinimumMultipartPartSize() * 5); } catch (IOException e) { throw new RuntimeException(e); } final long contentLength = api .getObjectApi(regionId, container) .getWithoutBody(name) .getPayload() .getContentMetadata() .getContentLength(); final long partSize = getMinimumMultipartPartSize(); final LinkedBlockingQueue<ListenableFuture<byte[]>> results = new LinkedBlockingQueue<ListenableFuture<byte[]>>(); listeningExecutor.submit(new Runnable() { @Override public void run() { ListenableFuture<byte[]> result; long from; for (from = 0; from < contentLength; from = from + partSize) { try { logger.debug(Thread.currentThread() + " writing to output"); result = results.take(); if (result == null) { output.close(); input.close(); throw new RuntimeException("Error downloading file part to stream"); } output.write(result.get()); } catch (Exception e) { logger.debug(e.toString()); try { input.close(); } catch (IOException e1) try { output.close(); } catch (IOException e1) throw new RuntimeException(e); } } Closeables2.closeQuietly(output); } }); listeningExecutor.submit(new Runnable() { @Override public void run() { long from; long to; for (from = 0; from < contentLength; from = from + partSize) { to = (from + partSize >= contentLength) ? contentLength - 1 : from + partSize - 1; BlobStreamDownloader b = new BlobStreamDownloader(container, name, from, to); results.add(listeningExecutor.submit(b)); } } }); return input; }