public static VanillaMappedFile readOnly(final File path, long size) throws IOException { return new VanillaMappedFile(path, VanillaMappedMode.RO, size, FileLifecycleListener.FileLifecycleListeners.IGNORE); }
public VanillaMappedFile(final File path, VanillaMappedMode mode, long size, FileLifecycleListener fileLifecycleListener) throws IOException { this.path = path; this.mode = mode; this.size = size; this.fileChannel = fileChannel(path, mode, this.size, fileLifecycleListener); this.fileLifecycleListener = fileLifecycleListener; }
@Override public String path() { return this.mappedFile.path(); }
public static VanillaMappedBytes readWriteBytes(final File path, long size, long index, FileLifecycleListener fileLifecycleListener) throws IOException { VanillaMappedFile vmf = new VanillaMappedFile(path, VanillaMappedMode.RW, -1, fileLifecycleListener); return new VanillaMappedBytes(path, vmf.map(0,size), index, vmf.fileChannel, fileLifecycleListener); } }
protected VanillaMappedBytes acquire0(long index) throws IOException { if (this.mb1 != null) { this.mb1.release(); } this.mb1 = this.mb0; this.mb0 = this.mappedFile.bytes(index * this.blockSize, this.blockSize, index); this.mb0.reserve(); bytes.add(this.mb0); for (int i = bytes.size() - 1; i >= 0; i--) { if (bytes.get(i).unmapped()) { bytes.remove(i); } } return this.mb0; }
public static VanillaMappedBytes readWriteBytes(final File path, long size) throws IOException { return readWriteBytes(path, size, -1); }
public VanillaMappedBytes bytes(long address, long size) throws IOException { return new VanillaMappedBytes(this.path, map(address, size), -1, null, this.fileLifecycleListener); }
@Override public synchronized long size() { return this.mappedFile.size(); }
@Override public synchronized void close() throws IOException { if (this.mb0 != null && !this.mb0.unmapped()) { this.mb0.release(); this.mb0 = null; } if (this.mb1 != null && !this.mb1.unmapped()) { this.mb1.release(); this.mb1 = null; } for (int i = bytes.size() - 1; i >= 0; i--) { bytes.get(i).cleanup(); } this.bytes.clear(); this.mappedFile.close(); } }
private static FileChannel fileChannel(final File path, VanillaMappedMode mapMode, long size, FileLifecycleListener fileLifecycleListener) throws IOException { long start = System.nanoTime(); FileChannel fileChannel = null; try { final RandomAccessFile raf = new RandomAccessFile(path, mapMode.stringValue()); if (size > 0 && raf.length() != size) { if (mapMode.mapValue() != FileChannel.MapMode.READ_WRITE) { throw new IOException("Cannot resize file to " + size + " as mode is not READ_WRITE"); } raf.setLength(size); } fileChannel = raf.getChannel(); } catch (Exception e) { throw wrap(e); } fileLifecycleListener.onEvent(EventType.NEW, path, System.nanoTime() - start); return fileChannel; }
public static VanillaMappedBytes readWriteBytes(final File path, long size, long index, FileLifecycleListener fileLifecycleListener) throws IOException { VanillaMappedFile vmf = new VanillaMappedFile(path, VanillaMappedMode.RW, -1, fileLifecycleListener); return new VanillaMappedBytes(path, vmf.map(0, size), index, vmf.fileChannel, fileLifecycleListener); }
protected VanillaMappedBytes acquire0(long index) throws IOException { if (this.mb1 != null) { this.mb1.release(); } this.mb1 = this.mb0; this.mb0 = this.mappedFile.bytes(index * this.blockSize, this.blockSize, index); this.mb0.reserve(); bytes.add(this.mb0); for (int i = bytes.size() - 1; i >= 0; i--) { if (bytes.get(i).unmapped()) { bytes.remove(i); } } return this.mb0; }
public static VanillaMappedBytes readWriteBytes(final File path, long size, long index) throws IOException { return readWriteBytes(path, size, index, FileLifecycleListener.FileLifecycleListeners.IGNORE); }
public VanillaMappedBytes bytes(long address, long size, long index) throws IOException { return new VanillaMappedBytes(this.path, map(address,size), index, null, this.fileLifecycleListener); }
@Override public synchronized long size() { return this.mappedFile.size(); }
@Override public synchronized void close() throws IOException { if (this.mb0 != null && !this.mb0.unmapped()) { this.mb0.release(); this.mb0 = null; } if (this.mb1 != null && !this.mb1.unmapped()) { this.mb1.release(); this.mb1 = null; } for (int i = bytes.size() - 1; i >= 0; i--) { bytes.get(i).cleanup(); } this.bytes.clear(); this.mappedFile.close(); }
private static FileChannel fileChannel(final File path, VanillaMappedMode mapMode, long size, FileLifecycleListener fileLifecycleListener) throws IOException { long start = System.nanoTime(); FileChannel fileChannel = null; try { final RandomAccessFile raf = new RandomAccessFile(path, mapMode.stringValue()); if (size > 0 && raf.length() != size) { if (mapMode.mapValue() != FileChannel.MapMode.READ_WRITE) { throw new IOException("Cannot resize file to " + size + " as mode is not READ_WRITE"); } raf.setLength(size); } fileChannel = raf.getChannel(); } catch (Exception e) { throw wrap(e); } fileLifecycleListener.onEvent(EventType.NEW, path, System.nanoTime() - start); return fileChannel; }
public static VanillaMappedFile readOnly(final File path, long size) throws IOException { return new VanillaMappedFile(path, VanillaMappedMode.RO, size, FileLifecycleListener.FileLifecycleListeners.IGNORE); }
public static VanillaMappedBytes readWriteBytes(final File path, long size, long index) throws IOException { return readWriteBytes(path, size, index, FileLifecycleListener.FileLifecycleListeners.IGNORE); }