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

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

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

IoUtil.fill介绍

[英]Fill a region of a file with a given byte value.
[中]用给定的字节值填充文件的一个区域。

代码示例

代码示例来源: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: 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;
}

相关文章