code: private void ringWrite(long position, byte[] buffer, int offset, int count) throws IOException {
      position = wrapPosition(position);
      if (position + count <= fileLength) {
        raf.seek(position);
        raf.write(buffer, offset, count);
      } else {
        // The write overlaps the EOF.
        // # of bytes to write before the EOF. Guaranteed to be less than Integer.MAX_VALUE.
        int beforeEof = (int) (fileLength - position);
        raf.seek(position);
        raf.write(buffer, offset, beforeEof);
        raf.seek(headerLength);
        raf.write(buffer, offset + beforeEof, count - beforeEof);
      }
    }
docs: Writes count bytes from buffer to position in file. Automatically wraps write if position is
  past the end of the file or if buffer overlaps it.
  
  @param position in file to write to
  @param buffer to write from
  @param count # of bytes to write