예제 #1
0
  /**
   * Reads a block from disk.
   *
   * @param b block to fetch
   */
  private void readBlock(final int b) {
    if (!bm.cursor(b)) return;

    final Buffer bf = bm.current();
    try {
      if (bf.dirty) writeBlock(bf);
      bf.pos = b;
      if (b >= blocks) {
        blocks = b + 1;
      } else {
        file.seek(bf.pos * IO.BLOCKSIZE);
        file.readFully(bf.data);
      }
    } catch (final IOException ex) {
      Util.stack(ex);
    }
  }
예제 #2
0
 /**
  * Writes the specified block to disk and resets the dirty flag.
  *
  * @param bf buffer to write
  * @throws IOException I/O exception
  */
 private void writeBlock(final Buffer bf) throws IOException {
   file.seek(bf.pos * IO.BLOCKSIZE);
   file.write(bf.data);
   bf.dirty = false;
 }