code: public static int copy(final InputStream is, final OutputStream os,
              final WriteListener listener) throws IOException {
          if (is == null) {
              throw new NullPointerException("null input stream.");
          }
          if (os == null) {
              throw new NullPointerException("null output stream.");
          }
          final byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
          int count = 0;
          int n = 0;
          while (-1 != (n = is.read(buffer))) {
              os.write(buffer, 0, n);
              listener.onBytesRead(n);
              count += n;
          }
          LOG.trace("Wrote " + count + " bytes.");
          return count;
      }
docs: Copy bytes from an <code>InputStream</code> to an
  <code>OutputStream</code>.
  <p>
  This method buffers the input internally, so there is no need to use a
  <code>BufferedInputStream</code>.
  
  @param is The <code>InputStream</code> to read from
  @param os The <code>OutputStream</code> to write to
  @param listener The listener for write events.
  @return the number of bytes copied
  @throws NullPointerException if the input or output is <code>null</code>
  @throws IOException if an I/O error occurs