code: public static void readAndWriteStreams(InputStream inputStream,OutputStream outputStream) throws IOException
      {
          byte[] buffer=new byte[5000];
          int read=-1;
          try
          {
              do
              {
                  //read next buffer
                  read=inputStream.read(buffer);
                  
                  if(read!=-1)
                  {
                      //write to in memory stream
                      outputStream.write(buffer,0,read);
                  }
              }while(read!=-1);
          }
          finally
          {
              //close streams
              IOHelper.closeResource(inputStream);
              IOHelper.closeResource(outputStream);
          }
      }
docs: Reads the data from the input stream and writes to the
  output stream.
  
  @param   inputStream
  The inputStream to read from
  @param   outputStream
  The output stream to write to
  @throws  IOException
  Any IO exception