public RawLogFactory( final String dataDirectoryName, final int filePageSize, final boolean checkStorage, final ErrorHandler errorHandler) { this.filePageSize = filePageSize; this.checkStorage = checkStorage; this.errorHandler = errorHandler; final File dataDir = new File(dataDirectoryName); publicationsDir = new File(dataDir, PUBLICATIONS); imagesDir = new File(dataDir, IMAGES); IoUtil.ensureDirectoryExists(publicationsDir, PUBLICATIONS); IoUtil.ensureDirectoryExists(imagesDir, IMAGES); FileStore fs = null; try { if (checkStorage) { fs = Files.getFileStore(dataDir.toPath()); } } catch (final IOException ex) { LangUtil.rethrowUnchecked(ex); } fileStore = fs; }
/** * Create an empty file, and optionally fill with 0s, and return the {@link FileChannel} * * @param file to create * @param length of the file to create * @param fillWithZeros to the length of the file to force allocation. * @return {@link java.nio.channels.FileChannel} for the file */ public static FileChannel createEmptyFile(final File file, final long length, final boolean fillWithZeros) { ensureDirectoryExists(file.getParentFile(), file.getParent()); FileChannel templateFile = null; try { final RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw"); randomAccessFile.setLength(length); templateFile = randomAccessFile.getChannel(); if (fillWithZeros) { fill(templateFile, 0, length, (byte)0); } } catch (final IOException ex) { LangUtil.rethrowUnchecked(ex); } return templateFile; }
@Before public void createDataDir() { IoUtil.ensureDirectoryExists(DATA_DIR, "data"); rawLogFactory = new RawLogFactory( DATA_DIR.getAbsolutePath(), PAGE_SIZE, PERFORM_STORAGE_CHECKS, mock(ErrorHandler.class)); }
IoUtil.ensureDirectoryExists(directory, directory.toString());
private static void ensureDirectoryIsRecreated(final Context ctx) { if (ctx.aeronDirectory().isDirectory()) { if (ctx.warnIfDirectoryExists()) { System.err.println("WARNING: " + ctx.aeronDirectory() + " already exists."); } if (!ctx.dirDeleteOnStart()) { final Consumer<String> logger = ctx.warnIfDirectoryExists() ? System.err::println : (s) -> {}; final MappedByteBuffer cncByteBuffer = ctx.mapExistingCncFile(logger); try { if (CommonContext.isDriverActive(ctx.driverTimeoutMs(), logger, cncByteBuffer)) { throw new ActiveDriverException("active driver detected"); } reportExistingErrors(ctx, cncByteBuffer); } finally { IoUtil.unmap(cncByteBuffer); } } ctx.deleteAeronDirectory(); } IoUtil.ensureDirectoryExists(ctx.aeronDirectory(), "aeron"); }
public static MappedByteBuffer mapNewFile(final File file, final int size) { final File parentDir = file.getParentFile(); IoUtil.ensureDirectoryExists(parentDir, parentDir.getAbsolutePath()); return IoUtil.mapNewFile(file, size); }
public RawLogFactory( final String dataDirectoryName, final int filePageSize, final boolean checkStorage, final ErrorHandler errorHandler) { this.filePageSize = filePageSize; this.checkStorage = checkStorage; this.errorHandler = errorHandler; final File dataDir = new File(dataDirectoryName); publicationsDir = new File(dataDir, PUBLICATIONS); imagesDir = new File(dataDir, IMAGES); IoUtil.ensureDirectoryExists(publicationsDir, PUBLICATIONS); IoUtil.ensureDirectoryExists(imagesDir, IMAGES); FileStore fs = null; try { if (checkStorage) { fs = Files.getFileStore(dataDir.toPath()); } } catch (final IOException ex) { LangUtil.rethrowUnchecked(ex); } fileStore = fs; }
public RawLogFactory( final String dataDirectoryName, final int filePageSize, final boolean checkStorage, final ErrorHandler errorHandler) { this.filePageSize = filePageSize; this.checkStorage = checkStorage; this.errorHandler = errorHandler; final File dataDir = new File(dataDirectoryName); publicationsDir = new File(dataDir, PUBLICATIONS); imagesDir = new File(dataDir, IMAGES); IoUtil.ensureDirectoryExists(publicationsDir, PUBLICATIONS); IoUtil.ensureDirectoryExists(imagesDir, IMAGES); FileStore fs = null; try { if (checkStorage) { fs = Files.getFileStore(dataDir.toPath()); } } catch (final IOException ex) { LangUtil.rethrowUnchecked(ex); } fileStore = fs; }
/** * Create an empty file, fill with 0s, and return the {@link FileChannel} * * @param file to create * @param length of the file to create * @return {@link java.nio.channels.FileChannel} for the file */ public static FileChannel createEmptyFile(final File file, final long length) { ensureDirectoryExists(file.getParentFile(), file.getParent()); FileChannel templateFile = null; try { final RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw"); randomAccessFile.setLength(length); templateFile = randomAccessFile.getChannel(); fill(templateFile, 0, length, (byte)0); } catch (final IOException ex) { LangUtil.rethrowUnchecked(ex); } return templateFile; }
/** * Create an empty file, and optionally fill with 0s, and return the {@link FileChannel} * * @param file to create * @param length of the file to create * @param fillWithZeros to the length of the file to force allocation. * @return {@link java.nio.channels.FileChannel} for the file */ public static FileChannel createEmptyFile(final File file, final long length, final boolean fillWithZeros) { ensureDirectoryExists(file.getParentFile(), file.getParent()); FileChannel templateFile = null; try { final RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw"); randomAccessFile.setLength(length); templateFile = randomAccessFile.getChannel(); if (fillWithZeros) { fill(templateFile, 0, length, (byte)0); } } catch (final IOException ex) { LangUtil.rethrowUnchecked(ex); } return templateFile; }
IoUtil.ensureDirectoryExists(directory, directory.toString());
private static void ensureDirectoryIsRecreated(final Context ctx) { if (ctx.aeronDirectory().isDirectory()) { if (ctx.warnIfDirectoryExists()) { System.err.println("WARNING: " + ctx.aeronDirectory() + " already exists."); } if (!ctx.dirDeleteOnStart()) { final Consumer<String> logger = ctx.warnIfDirectoryExists() ? System.err::println : (s) -> {}; final MappedByteBuffer cncByteBuffer = ctx.mapExistingCncFile(logger); try { if (CommonContext.isDriverActive(ctx.driverTimeoutMs(), logger, cncByteBuffer)) { throw new ActiveDriverException("active driver detected"); } reportExistingErrors(ctx, cncByteBuffer); } finally { IoUtil.unmap(cncByteBuffer); } } ctx.deleteAeronDirectory(); } IoUtil.ensureDirectoryExists(ctx.aeronDirectory(), "aeron"); }
private static void ensureDirectoryIsRecreated(final Context ctx) { if (ctx.aeronDirectory().isDirectory()) { if (ctx.warnIfDirectoryExists()) { System.err.println("WARNING: " + ctx.aeronDirectory() + " already exists."); } if (!ctx.dirDeleteOnStart()) { final Consumer<String> logger = ctx.warnIfDirectoryExists() ? System.err::println : (s) -> {}; final MappedByteBuffer cncByteBuffer = ctx.mapExistingCncFile(logger); try { if (CommonContext.isDriverActive(ctx.driverTimeoutMs(), logger, cncByteBuffer)) { throw new ActiveDriverException("active driver detected"); } reportExistingErrors(ctx, cncByteBuffer); } finally { IoUtil.unmap(cncByteBuffer); } } ctx.deleteAeronDirectory(); } IoUtil.ensureDirectoryExists(ctx.aeronDirectory(), "aeron"); }
@Test(timeout = 20_000L) public void shouldReadRecordsFromBeforeARestart() throws IOException { indexExampleMessage(); // Fake restarting the gateway final File logFile = logFile(SESSION_ID); IoUtil.ensureDirectoryExists(new File(DEFAULT_LOG_FILE_DIR), DEFAULT_LOG_FILE_DIR); logFile.createNewFile(); try { newReplayIndex(); final int msgCount = query(); verifyMappedFile(SESSION_ID, 1); verifyMessagesRead(1); assertEquals(1, msgCount); } finally { IoUtil.delete(new File(DEFAULT_LOG_FILE_DIR), false); } }