java.io.RandomAccessFile.getFD()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(226)

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

RandomAccessFile.getFD介绍

[英]Gets this file's FileDescriptor. This represents the operating system resource for this random access file.
[中]获取此文件的FileDescriptor。这表示此随机访问文件的操作系统资源。

代码示例

代码示例来源:origin: apache/hive

public FadvisedChunkedFile(RandomAccessFile file, long position, long count,
  int chunkSize, boolean manageOsCache, int readaheadLength,
  ReadaheadPool readaheadPool, String identifier) throws IOException {
 super(file, position, count, chunkSize);
 this.manageOsCache = manageOsCache;
 this.readaheadLength = readaheadLength;
 this.readaheadPool = readaheadPool;
 this.fd = file.getFD();
 this.identifier = identifier;
}

代码示例来源:origin: apache/geode

public synchronized FileDescriptor getFD() throws IOException {
 return this.raf.getFD();
}

代码示例来源:origin: lingochamp/FileDownloader

FileDownloadRandomAccessFile(File file) throws IOException {
  randomAccess = new RandomAccessFile(file, "rw");
  fd = randomAccess.getFD();
  out = new BufferedOutputStream(new FileOutputStream(randomAccess.getFD()));
}

代码示例来源:origin: atomix/atomix

@Override
public Bytes flush() {
 try {
  randomAccessFile.getFD().sync();
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
 return this;
}

代码示例来源:origin: apache/geode

/**
 * Test Method to be used only for testing purposes. Gets the underlying File object for the Oplog
 * . Oplog class uses this File object to obtain the RandomAccessFile object. Before returning the
 * File object , the dat present in the buffers of the RandomAccessFile object is flushed.
 * Otherwise, for windows the actual file length does not match with the File size obtained from
 * the File object
 */
File getOplogFile() throws SyncFailedException, IOException {
 synchronized (this.crf) {
  if (!this.crf.RAFClosed) {
   this.crf.raf.getFD().sync();
  }
  return this.crf.f;
 }
}

代码示例来源:origin: MindorksOpenSource/PRDownloader

private FileDownloadRandomAccessFile(File file) throws IOException {
  randomAccess = new RandomAccessFile(file, "rw");
  fd = randomAccess.getFD();
  out = new BufferedOutputStream(new FileOutputStream(randomAccess.getFD()));
}

代码示例来源:origin: com.h2database/h2

@Override
public void force(boolean metaData) throws IOException {
  String m = SysProperties.SYNC_METHOD;
  if ("".equals(m)) {
    // do nothing
  } else if ("sync".equals(m)) {
    file.getFD().sync();
  } else if ("force".equals(m)) {
    file.getChannel().force(true);
  } else if ("forceFalse".equals(m)) {
    file.getChannel().force(false);
  } else {
    file.getFD().sync();
  }
}

代码示例来源:origin: apache/flume

public void close() {
  try {
   fileHandle.getFD().sync();
   fileHandle.close();
  } catch (IOException e) {
   LOG.error("Could not close file handle to file " +
     fileHandle.toString(), e);
  }
 }
}

代码示例来源:origin: robolectric/robolectric

@Implementation
protected FileDescriptor getFileDescriptor() {
 try {
  return file.getFD();
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: robolectric/robolectric

@Implementation(maxSdk = P)
 protected static FileDescriptor openFileDescriptor(String file, int mode) throws IOException {
  RandomAccessFile randomAccessFile =
    new RandomAccessFile(file, mode == ParcelFileDescriptor.MODE_READ_ONLY ? "r" : "rw");
  return randomAccessFile.getFD();
 }
}

代码示例来源:origin: com.h2database/h2

@Override
public void force(boolean metaData) throws IOException {
  mapped.force();
  file.getFD().sync();
}

代码示例来源:origin: apache/hive

public FadvisedFileRegion(RandomAccessFile file, long position, long count,
  boolean manageOsCache, int readaheadLength, ReadaheadPool readaheadPool,
  String identifier, int shuffleBufferSize, 
  boolean shuffleTransferToAllowed, boolean canEvictAfterTransfer) throws IOException {
 super(file.getChannel(), position, count);
 this.manageOsCache = manageOsCache;
 this.readaheadLength = readaheadLength;
 this.readaheadPool = readaheadPool;
 this.fd = file.getFD();
 this.identifier = identifier;
 this.fileChannel = file.getChannel();
 this.count = count;
 this.position = position;
 this.shuffleBufferSize = shuffleBufferSize;
 this.shuffleTransferToAllowed = shuffleTransferToAllowed;
 // To indicate whether the pages should be thrown away or not.
 this.canEvictAfterTransfer = canEvictAfterTransfer;
}

代码示例来源:origin: lealone/Lealone

@Override
public void force(boolean metaData) throws IOException {
  mapped.force();
  file.getFD().sync();
}

代码示例来源:origin: robolectric/robolectric

@Implementation
protected int getFd() {
 try {
  return ReflectionHelpers.getField(file.getFD(), "fd");
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: gocd/gocd

public synchronized void writeToConfigXmlFile(String content) {
  FileChannel channel = null;
  FileOutputStream outputStream = null;
  FileLock lock = null;
  try {
    RandomAccessFile randomAccessFile = new RandomAccessFile(fileLocation(), "rw");
    channel = randomAccessFile.getChannel();
    lock = channel.lock();
    randomAccessFile.seek(0);
    randomAccessFile.setLength(0);
    outputStream = new FileOutputStream(randomAccessFile.getFD());
    IOUtils.write(content, outputStream, UTF_8);
  } catch (Exception e) {
    throw new RuntimeException(e);
  } finally {
    if (channel != null && lock != null) {
      try {
        lock.release();
        channel.close();
        IOUtils.closeQuietly(outputStream);
      } catch (IOException e) {
        LOGGER.error("Error occured when releasing file lock and closing file.", e);
      }
    }
  }
}

代码示例来源:origin: pockethub/PocketHub

/**
 * Get size of image
 *
 * @param imagePath
 * @return size
 */
public static Point getSize(final String imagePath) {
  final Options options = new Options();
  options.inJustDecodeBounds = true;
  RandomAccessFile file = null;
  try {
    file = new RandomAccessFile(imagePath, "r");
    BitmapFactory.decodeFileDescriptor(file.getFD(), null, options);
    return new Point(options.outWidth, options.outHeight);
  } catch (IOException e) {
    Log.d(TAG, e.getMessage(), e);
    return null;
  } finally {
    if (file != null) {
      try {
        file.close();
      } catch (IOException e) {
        Log.d(TAG, e.getMessage(), e);
      }
    }
  }
}

代码示例来源:origin: robolectric/robolectric

@Implementation
protected static FileDescriptor nCreate(String name, int size) throws ErrnoException {
 maybeThrow(fakeCreateException);
 TempDirectory tempDirectory = RuntimeEnvironment.getTempDirectory();
 try {
  // Give each instance its own private file.
  File sharedMemoryFile =
    Files.createTempFile(
        tempDirectory.createIfNotExists("SharedMemory"), "shmem-" + name, ".tmp")
      .toFile();
  RandomAccessFile randomAccessFile = new RandomAccessFile(sharedMemoryFile, "rw");
  randomAccessFile.setLength(0);
  randomAccessFile.setLength(size);
  filesByFd.put(randomAccessFile.getFD(), sharedMemoryFile);
  return randomAccessFile.getFD();
 } catch (IOException e) {
  throw new RuntimeException("Unable to create file descriptior", e);
 }
}

代码示例来源:origin: robolectric/robolectric

@Implementation
protected FileDescriptor open(String path, int flags, int mode) throws ErrnoException {
 try {
  RandomAccessFile randomAccessFile = new RandomAccessFile(path, modeToString(mode));
  return randomAccessFile.getFD();
 } catch (IOException e) {
  Log.e("ShadowLinux", "open failed for " + path, e);
  throw new ErrnoException("open", OsConstants.EIO);
 }
}

代码示例来源:origin: robovm/robovm

public int fill(Inflater inflater, int nativeEndBufSize) throws IOException {
    synchronized (sharedRaf) {
      int len = Math.min((int) (endOffset - offset), nativeEndBufSize);
      int cnt = inflater.setFileInput(sharedRaf.getFD(), offset, nativeEndBufSize);
      // setFileInput read from the file, so we need to get the OS and RAFStream back
      // in sync...
      skip(cnt);
      return len;
    }
  }
}

代码示例来源:origin: apache/activemq

public FileDescriptor getFD() throws IOException {
  try {
    return getRaf().getFD();
  } catch (IOException ioe) {
    handleException();
    throw ioe;
  }
}

相关文章