code: private void copyStream(InputStream inputStream) throws IOException {
  		OutputStream outputStream = null;
  		try {
  			outputStream = getContext().getOutputStream();
  			byte[] buffer = new byte[65535];
  			int bufferLen;
  			int totalLen = 0;
  			while ((bufferLen = inputStream.read(buffer)) > 0) {
  				outputStream.write(buffer, 0, bufferLen);
  				totalLen += bufferLen;
  			}
  			getContext().getResponse().setContentLength(totalLen);
  		} finally {
  			if (outputStream != null) {
  				outputStream.flush();
  			}
  		}
  	}
docs: Copy resource input stream to HTTP response output stream using
  a 64kib buffer