@NotNull public static MappedFile mappedFile(@NotNull File file, long capacity, long chunkSize, long overlapSize, boolean readOnly) throws IOException { RandomAccessFile raf = new RandomAccessFile(file, readOnly ? "r" : "rw"); // Windows throws an exception when setting the length when you re-open if (raf.length() < capacity) raf.setLength(capacity); return new MappedFile(file, raf, chunkSize, overlapSize, capacity, readOnly); }
@NotNull public static MappedFile of(@NotNull File file, long chunkSize, long overlapSize, boolean readOnly) throws FileNotFoundException { // if (readOnly && OS.isWindows()) { // Jvm.warn().on(MappedFile.class, "Read only mode not supported on Windows, defaulting to read/write"); // readOnly = false; // } @NotNull RandomAccessFile raf = new RandomAccessFile(file, readOnly ? "r" : "rw"); // try { long capacity = /*readOnly ? raf.length() : */DEFAULT_CAPACITY; return new MappedFile(file, raf, chunkSize, overlapSize, capacity, readOnly); /* } catch (IOException e) { Closeable.closeQuietly(raf); @NotNull FileNotFoundException fnfe = new FileNotFoundException("Unable to open " + file); fnfe.initCause(e); throw fnfe; } */ }
@NotNull public MappedFile withSizes(long chunkSize, long overlapSize) { chunkSize = OS.mapAlign(chunkSize); overlapSize = OS.mapAlign(overlapSize); if (chunkSize == this.chunkSize && overlapSize == this.overlapSize) return this; try { return new MappedFile(file, raf, chunkSize, overlapSize, capacity, readOnly); } finally { release(); } }
public static void warmup() { try { Jvm.disableDebugHandler(); @NotNull File file = File.createTempFile("delete", "me"); file.deleteOnExit(); long mapAlignment = OS.mapAlignment(); int chunks = 64; int compileThreshold = Jvm.compileThreshold(); for (int j = 0; j <= compileThreshold; j += chunks) { try { try (@NotNull RandomAccessFile raf = new RandomAccessFile(file, "rw")) { @NotNull MappedFile mappedFile = new MappedFile(file, raf, mapAlignment, 0, mapAlignment * chunks, false); warmup0(mapAlignment, chunks, mappedFile); mappedFile.release(); } Thread.yield(); Files.delete(file.toPath()); } catch (IOException e) { Jvm.debug().on(MappedFile.class, "Error during warmup", e); } } } catch (IOException e) { Jvm.warn().on(MappedFile.class, "Error during warmup", e); } Jvm.resetExceptionHandlers(); }