code: public static long copy(final InputStream input, final OutputStream output)
              throws IOException {
          // guard against null streams
          if (input == null) {
              throw new InvalidArgument("input", input);
          }
          if (output == null) {
              throw new InvalidArgument("output", output);
          }
  
          byte[] buf = new byte[4096];
          long count = 0;
          int bytesRead = 0;
          while ((bytesRead = input.read(buf)) != -1) {
              output.write(buf, 0, bytesRead);
              count += bytesRead;
          }
  
          return count;
      }
docs: Copy bytes from the {@link InputStream input stream} to the
  {@link OutputStream output stream} in 4 kilobyte increments.
  
  @param input the {@link InputStream input stream} to read from, which
  cannot be null
  @param output the {@link OutputStream output stream} to write to, which
  cannot be null
  @return the number of {@code bytes} read
  @throws IOException Thrown if an IO error occurred while copying data
  @throws InvalidArgument Thrown if either {@code input} or {@code output}
  is {@code null}