code: public static void copyStream(final InputStream aInStream, final OutputStream aOutStream) throws IOException {
          final BufferedOutputStream outStream = new BufferedOutputStream(aOutStream);
          final BufferedInputStream inStream = new BufferedInputStream(aInStream);
          final ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
          final byte[] buffer = new byte[1024];
          int bytesRead = 0;
  
          while (true) {
              bytesRead = inStream.read(buffer);
  
              if (bytesRead == -1) {
                  break;
              }
  
              byteStream.write(buffer, 0, bytesRead);
          }
  
          outStream.write(byteStream.toByteArray());
          outStream.flush();
      }
docs: Writes from an input stream to an output stream; you're responsible for closing the <code>InputStream</code>
  and <code>OutputStream</code>.
  
  @param aInStream The stream from which to read
  @param aOutStream The stream from which to write
  @throws IOException If there is trouble reading or writing