code: public static long copy(InputStream input, OutputStream output) throws IOException {
          byte[] buffer = new byte[2 * 1024];
          long total = 0;
          int count;
          while ((count = input.read(buffer)) != -1) {
              output.write(buffer, 0, count);
              total += count;
          }
  
          return total;
      }
docs: Copies all data from an InputStream to an OutputStream.
  
  @return the number of bytes copied
  @throws IOException if an I/O error occurs