本文整理了Java中org.agrona.IoUtil.ensureDirectoryExists()
方法的一些代码示例,展示了IoUtil.ensureDirectoryExists()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IoUtil.ensureDirectoryExists()
方法的具体详情如下:
包路径:org.agrona.IoUtil
类名称:IoUtil
方法名:ensureDirectoryExists
[英]Create a directory if it doesn't already exist.
[中]如果目录不存在,请创建一个目录。
代码示例来源:origin: real-logic/aeron
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;
}
代码示例来源:origin: real-logic/agrona
/**
* 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;
}
代码示例来源:origin: real-logic/aeron
@Before
public void createDataDir()
{
IoUtil.ensureDirectoryExists(DATA_DIR, "data");
rawLogFactory = new RawLogFactory(
DATA_DIR.getAbsolutePath(), PAGE_SIZE, PERFORM_STORAGE_CHECKS, mock(ErrorHandler.class));
}
代码示例来源:origin: real-logic/agrona
IoUtil.ensureDirectoryExists(directory, directory.toString());
代码示例来源:origin: real-logic/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");
}
代码示例来源:origin: real-logic/artio
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);
}
代码示例来源:origin: io.aeron/aeron-driver
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;
}
代码示例来源:origin: io.aeron/aeron-all
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;
}
代码示例来源:origin: org.agrona/Agrona
/**
* 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;
}
代码示例来源:origin: org.agrona/agrona
/**
* 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;
}
代码示例来源:origin: org.agrona/agrona
IoUtil.ensureDirectoryExists(directory, directory.toString());
代码示例来源:origin: io.aeron/aeron-driver
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");
}
代码示例来源:origin: io.aeron/aeron-all
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");
}
代码示例来源:origin: real-logic/artio
@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);
}
}
内容来源于网络,如有侵权,请联系作者删除!