code: public static void writeFully(FileChannel fc, ByteBuffer buf,
        long offset) throws IOException {
      do {
        offset += fc.write(buf, offset);
      } while (buf.remaining() > 0);
    }
docs: Write a ByteBuffer to a FileChannel at a given offset,
  handling short writes.
  
  @param fc               The FileChannel to write to
  @param buf              The input buffer
  @param offset           The offset in the file to start writing at
  @throws IOException     On I/O error