jnr.posix.POSIX Java Examples

The following examples show how to use jnr.posix.POSIX. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Common.java    From benchmarks with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("UseOfSystemOutOrSystemErr")
protected void reportSpaceUsed(final File dir, final String desc) {
  final File[] files = dir.listFiles();
  if (files == null) {
    return;
  }
  long bytes = 0;
  for (final File f : files) {
    if (f.isDirectory()) {
      throw new UnsupportedOperationException("impl created directory");
    }
    final FileStat stat = POSIX.stat(f.getAbsolutePath());
    bytes += stat.blocks() * S_BLKSIZE;
  }
  out.println("\nBytes\t" + desc + "\t" + bytes + "\t" + dir.getName());
}
 
Example #2
Source File: IOUtils.java    From bazel-buildfarm with Apache License 2.0 5 votes vote down vote up
public static List<JnrDirent> jnrReaddir(POSIX posix, Path path) throws IOException {
  List<JnrDirent> dirents = new ArrayList<>();
  try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) {
    for (Path file : stream) {
      FileStat stat = jnrStatNullable(posix, file.toString());
      dirents.add(new JnrDirent(file.getFileName().toString(), stat));
    }
  }
  return dirents;
}
 
Example #3
Source File: IOUtils.java    From bazel-buildfarm with Apache License 2.0 5 votes vote down vote up
public static FileStat jnrStatNullable(POSIX posix, String path) {
  try {
    return posix.stat(path);
  } catch (Exception e) {
    return null;
  }
}
 
Example #4
Source File: Info.java    From galeb with Apache License 2.0 4 votes vote down vote up
public static int getPid() {
    final POSIX posix = POSIXFactory.getNativePOSIX();
    return posix.getpid();
}
 
Example #5
Source File: Info.java    From galeb with Apache License 2.0 4 votes vote down vote up
public static int getPid() {
    final POSIX posix = POSIXFactory.getNativePOSIX();
    return posix.getpid();
}
 
Example #6
Source File: IOUtils.java    From bazel-buildfarm with Apache License 2.0 4 votes vote down vote up
public static long jnrGetInode(POSIX posix, String path) {
  FileStat fs = posix.lstat(path);
  return fs.ino();
}
 
Example #7
Source File: IOUtils.java    From bazel-buildfarm with Apache License 2.0 4 votes vote down vote up
public static Boolean jnrIsDir(POSIX posix, String path) {
  int fd = posix.open(path, OpenFlags.O_DIRECTORY.intValue(), 0444);
  return fd > 0;
}