Пример #1
0
 public boolean flushSome(int maxPages) {
   myFile.flushSomePages(maxPages);
   if (!myFile.isDirty()) {
     force();
     return true;
   }
   return false;
 }
Пример #2
0
 private void readInHeader(File filePath) throws IOException {
   int magic = myFile.getInt(HEADER_MAGIC_OFFSET);
   if (magic != SAFELY_CLOSED_MAGIC) {
     myFile.dispose();
     throw new IOException(
         "Records table for '" + filePath + "' haven't been closed correctly. Rebuild required.");
   }
   myWasteSize = myFile.getInt(HEADER_WASTE_SIZE_OFFSET);
 }
Пример #3
0
 public DataTable(final File filePath, final PagePool pool) throws IOException {
   myFile = new RandomAccessDataFile(filePath, pool);
   if (myFile.length() == 0) {
     markDirty();
   } else {
     readInHeader(filePath);
   }
 }
Пример #4
0
  public long allocateSpace(int len) {
    final long result = Math.max(myFile.length(), HEADER_SIZE);

    // Fill them in so we won't give out wrong address from allocateSpace() next time if they still
    // not finished writing to allocated page
    long newLenght = result + len;
    writeBytes(newLenght - 1, new byte[] {0});
    long actualLenght = myFile.length();
    LOG.assertTrue(
        actualLenght == newLenght,
        "Failed to resize the storage at: "
            + myFile.getFile()
            + ". Required: "
            + newLenght
            + ", actual: "
            + actualLenght);
    return result;
  }
Пример #5
0
 public void writeBytes(long address, byte[] bytes, int off, int len) {
   markDirty();
   myFile.put(address, bytes, off, len);
 }
Пример #6
0
 public void readBytes(long address, byte[] bytes) {
   myFile.get(address, bytes, 0, bytes.length);
 }
Пример #7
0
 public boolean isCompactNecessary() {
   return ((double) myWasteSize) / myFile.length() > 0.25 && myWasteSize > 3 * FileUtil.MEGABYTE;
 }
Пример #8
0
 public long getFileSize() {
   return myFile.length();
 }
Пример #9
0
 private void fillInHeader(int magic, int wasteSize) {
   myFile.putInt(HEADER_MAGIC_OFFSET, magic);
   myFile.putInt(HEADER_WASTE_SIZE_OFFSET, wasteSize);
 }
Пример #10
0
 public boolean isDirty() {
   return myIsDirty || myFile.isDirty();
 }
Пример #11
0
 public void force() {
   markClean();
   myFile.force();
 }
Пример #12
0
 public void dispose() {
   if (!myFile.isDisposed()) {
     markClean();
     myFile.dispose();
   }
 }