code: private void appendToFile(RandomAccessFile output, InputStream input)
              throws IOException {
          byte[] buffer = new byte[1024 * 1024];
          int bytesRead = 0;
          do {
              bytesRead = input.read(buffer);
              if (bytesRead < 0)
                  break;
              output.write(buffer, 0, bytesRead);
          } while (bytesRead > 0);
          return;
      }
docs: Writes the data from the given input stream to the given output stream.