Code example for RandomAccessFile

Methods: readInt, seek

0
  /** 
   * Returns the Element for the given offset. 
   */ 
  private Element readElement(int position) throws IOException {
    if (position == 0) return Element.NULL;
    raf.seek(position);
    return new Element(position, raf.readInt());
  } 
 
  /** Atomically initializes a new file. */ 
  private static void initialize(File file) throws IOException {
    // Use a temp file so we don't leave a partially-initialized file. 
    File tempFile = new File(file.getPath() + ".tmp");
    RandomAccessFile raf = open(tempFile);
    try { 
      raf.setLength(INITIAL_LENGTH);
      raf.seek(0);
      byte[] headerBuffer = new byte[16];
      writeInts(headerBuffer, INITIAL_LENGTH, 0, 0, 0);
      raf.write(headerBuffer);
    } finally {