code: static int copyBytes(RandomAccessFile os, InputStream is, int byteLimit, byte[] buffer)
        throws IOException {
      // Yes, this method is exactly the same as the above, just with a different type for `os'.
      int bytesCopied = 0;
      int nrRead;
      while (bytesCopied < byteLimit &&
          (nrRead = is.read(
              buffer,
              0,
              Math.min(buffer.length, byteLimit - bytesCopied))) != -1) {
        os.write(buffer, 0, nrRead);
        bytesCopied += nrRead;
      }
      return bytesCopied;
    }
docs: Copy up to byteLimit bytes from the input stream to the output stream.
  
  @param os Destination stream
  @param is Input stream
  @param byteLimit Maximum number of bytes to copy
  @param buffer IO buffer to use
  @return Number of bytes actually copied