org.agrona.IoUtil.createEmptyFile()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(2.1k)|赞(0)|评价(0)|浏览(149)

本文整理了Java中org.agrona.IoUtil.createEmptyFile()方法的一些代码示例,展示了IoUtil.createEmptyFile()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IoUtil.createEmptyFile()方法的具体详情如下:
包路径:org.agrona.IoUtil
类名称:IoUtil
方法名:createEmptyFile

IoUtil.createEmptyFile介绍

[英]Create an empty file, fill with 0s, and return the FileChannel
[中]创建一个空文件,填充0,然后返回FileChannel

代码示例

代码示例来源:origin: real-logic/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)
{
  return createEmptyFile(file, length, true);
}

代码示例来源: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)
{
  return createEmptyFile(file, length, true);
}

代码示例来源:origin: org.agrona/Agrona

/**
 * Create a new file, fill with 0s, and return a {@link java.nio.MappedByteBuffer} for the file
 * <p>
 * The file itself will be closed, but the mapping will persist.
 *
 * @param location of the file to create and map
 * @param size     of the file to create and map
 * @return {@link java.nio.MappedByteBuffer} for the file
 */
public static MappedByteBuffer mapNewFile(final File location, final long size)
{
  MappedByteBuffer mappedByteBuffer = null;
  try (FileChannel channel = createEmptyFile(location, size))
  {
    mappedByteBuffer = channel.map(READ_WRITE, 0, size);
  }
  catch (final IOException ex)
  {
    LangUtil.rethrowUnchecked(ex);
  }
  return mappedByteBuffer;
}

代码示例来源:origin: real-logic/artio

public static MappedFile map(final File bufferFile, final int size)
{
  final FileChannel fileChannel;
  try
  {
    if (bufferFile.exists())
    {
      // NB: closing RAF or FileChannel closes them both
      fileChannel = new RandomAccessFile(bufferFile, "rw").getChannel();
    }
    else
    {
      fileChannel = IoUtil.createEmptyFile(bufferFile, (long)size);
    }
    final MappedByteBuffer mappedBuffer = fileChannel.map(READ_WRITE, 0, fileChannel.size());
    return new MappedFile(bufferFile, fileChannel, new UnsafeBuffer(mappedBuffer));
  }
  catch (final IOException ex)
  {
    LangUtil.rethrowUnchecked(ex);
    return null;
  }
}

相关文章