code: protected OutputStream getAsynchronousOutputStream(
  			final OutputStream outputStream) throws IOException {
  		final int SIZE = 1024 * 1024 * 10;
  		final PipedOutputStream pos = new PipedOutputStream();
  		final PipedInputStream pis = new PipedInputStream(pos, SIZE);
  
  		final FinishableRunnable run = new FinishableRunnable() {
  
  			volatile boolean finish = false;
  			volatile boolean hasFinished = false;
  
  			@Override
  			public void finish() {
  				this.finish = true;
  				while (!this.hasFinished) {
  					// loop until thread is really finished
  				}
  			}
  
  			@Override
  			public void run() {
  				try {
  					byte[] bytes = new byte[SIZE];
  					// Note that we finish really gently here, writing all data
  					// that is still in the input first (in theory, new data
  					// could arrive asynchronously, so that the thread never
  					// finishes, but this is not the intended mode of
  					// operation).
  					for (int len; (!this.finish || pis.available() > 0)
  							&& (len = pis.read(bytes)) > 0;) {
  						outputStream.write(bytes, 0, len);
  					}
  				} catch (IOException e) {
  					e.printStackTrace();
  				} finally {
  					close(pis);
  					close(outputStream);
  					this.hasFinished = true;
  				}
  			}
  		};
  
  		new Thread(run, "async-output-stream").start();
  
  		this.outputStreams.add(new Closeable() {
  			@Override
  			public void close() throws IOException {
  				run.finish();
  			}
  		});
  
  		return pos;
  	}
docs: Creates a separate thread for writing into the given output stream and
  returns a pipe output stream that can be used to pass data to this
  thread.
  <p>
  This code is inspired by
  http://stackoverflow.com/questions/12532073/gzipoutputstream
  -that-does-its-compression-in-a-separate-thread
  
  @param outputStream
  the stream to write to in the thread
  @return a new stream that data should be written to
  @throws IOException
  if the pipes could not be created for some reason