public boolean flushSome(int maxPages) { myFile.flushSomePages(maxPages); if (!myFile.isDirty()) { force(); return true; } return false; }
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); }
public DataTable(final File filePath, final PagePool pool) throws IOException { myFile = new RandomAccessDataFile(filePath, pool); if (myFile.length() == 0) { markDirty(); } else { readInHeader(filePath); } }
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; }
public void writeBytes(long address, byte[] bytes, int off, int len) { markDirty(); myFile.put(address, bytes, off, len); }
public void readBytes(long address, byte[] bytes) { myFile.get(address, bytes, 0, bytes.length); }
public boolean isCompactNecessary() { return ((double) myWasteSize) / myFile.length() > 0.25 && myWasteSize > 3 * FileUtil.MEGABYTE; }
public long getFileSize() { return myFile.length(); }
private void fillInHeader(int magic, int wasteSize) { myFile.putInt(HEADER_MAGIC_OFFSET, magic); myFile.putInt(HEADER_WASTE_SIZE_OFFSET, wasteSize); }
public boolean isDirty() { return myIsDirty || myFile.isDirty(); }
public void force() { markClean(); myFile.force(); }
public void dispose() { if (!myFile.isDisposed()) { markClean(); myFile.dispose(); } }