code: public static void transfer(InputStream in, OutputStream out, TransferCallback cb) throws IOException
      {
          byte[] bytes = new byte[TRANSFER_BUFFER];
          int count;
          while ((count = in.read(bytes)) != -1)
          {
              out.write(bytes, 0, count);
              if (cb != null)
              {
                  cb.bytesTransferred(bytes, count);
                  if (cb.isCancelled())
                  {
                      break;
                  }
              }
          }
      }
docs: Transfers bytes from an input stream to an output stream.
  Callers of this method are responsible for closing the streams
  since they are the ones that opened the streams.