java.nio.file.Files.getFileStore()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(107)

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

Files.getFileStore介绍

暂无

代码示例

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

@Override
public long getStorageCapacity() throws IOException {
  long capacity = 0L;
  for (final File file : flowFileRepositoryPaths) {
    capacity += Files.getFileStore(file.toPath()).getTotalSpace();
  }
  return capacity;
}

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

@Override
public String getFileStoreName() {
  final Path path = flowFileRepositoryPaths.iterator().next().toPath();
  try {
    return Files.getFileStore(path).name();
  } catch (IOException e) {
    return null;
  }
}

代码示例来源:origin: oracle/helidon

private DiskSpaceHealthCheck(Builder builder) {
  try {
    this.fileStore = Files.getFileStore(builder.path);
  } catch (IOException e) {
    throw new HealthCheckException("Failed to obtain file store for path " + builder.path.toAbsolutePath(), e);
  }
  this.thresholdPercent = builder.threshold;
}

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

@Override
public long getUsableStorageSpace() throws IOException {
  long usableSpace = 0L;
  for (final File file : flowFileRepositoryPaths) {
    usableSpace += Files.getFileStore(file.toPath()).getUsableSpace();
  }
  return usableSpace;
}

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

@Override
public String getContainerFileStoreName(final String containerName) {
  final Path path = containers.get(containerName);
  try {
    return Files.getFileStore(path).name();
  } catch (IOException e) {
    return null;
  }
}

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

/**
 * Get the file store type of a path. for example, /dev/sdd1(store name) /w2-gst-dev40d(mount
 * point) ext4(type)
 *
 * @return file store type
 */
public String getFileStoreType(final String path) {
 File diskFile = new File(path);
 if (!diskFile.exists()) {
  diskFile = diskFile.getParentFile();
 }
 Path currentPath = diskFile.toPath();
 if (currentPath.isAbsolute() && Files.exists(currentPath)) {
  try {
   FileStore store = Files.getFileStore(currentPath);
   return store.type();
  } catch (IOException e) {
   return null;
  }
 }
 return null;
}

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

@Override
public String getContainerFileStoreName(final String containerName) {
  final Map<String, File> map = config.getStorageDirectories();
  final File container = map.get(containerName);
  if (container == null) {
    return null;
  }
  try {
    return Files.getFileStore(container.toPath()).name();
  } catch (IOException e) {
    return null;
  }
}

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

@Override
public String getContainerFileStoreName(final String containerName) {
  final Map<String, File> map = configuration.getStorageDirectories();
  final File container = map.get(containerName);
  if (container == null) {
    return null;
  }
  try {
    return Files.getFileStore(container.toPath()).name();
  } catch (IOException e) {
    return null;
  }
}

代码示例来源:origin: oracle/helidon

@Inject
DiskSpaceHealthCheck(
    @ConfigProperty(name = CONFIG_KEY_PATH, defaultValue = DEFAULT_PATH) File path,
    @ConfigProperty(name = CONFIG_KEY_THRESHOLD_PERCENT, defaultValue = "99.999") double thresholdPercent
) {
  try {
    this.fileStore = Files.getFileStore(path.toPath());
  } catch (IOException e) {
    throw new HealthCheckException("Failed to obtain file store for path " + path.getAbsolutePath(), e);
  }
  this.thresholdPercent = thresholdPercent;
}

代码示例来源:origin: prestodb/presto

private boolean hasEnoughDiskSpace(Path path)
  {
    try {
      FileStore fileStore = getFileStore(path);
      return fileStore.getUsableSpace() > fileStore.getTotalSpace() * (1.0 - maxUsedSpaceThreshold);
    }
    catch (IOException e) {
      throw new PrestoException(OUT_OF_SPILL_SPACE, "Cannot determine free space for spill", e);
    }
  }
}

代码示例来源:origin: Alluxio/alluxio

private boolean addDirectoryInfo(String path, long quota, Map<String, MountedStorage> storageMap)
  throws IOException {
 File file = new File(path);
 if (!file.exists()) {
  System.err.format("Path %s does not exist.%n", path);
  return false;
 }
 if (!file.isDirectory()) {
  System.err.format("Path %s is not a valid directory.%n", path);
  return false;
 }
 long directorySize = FileUtils.sizeOfDirectory(file);
 // gets mounted FileStore that backs the directory of the given path
 FileStore store = Files.getFileStore(Paths.get(path));
 MountedStorage storage = storageMap.get(store.name());
 if (storage == null) {
  storage = new MountedStorage(store);
  storageMap.put(store.name(), storage);
 }
 storage.addDirectoryInfo(path, quota, directorySize);
 return true;
}

代码示例来源: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: eclipse-vertx/vert.x

public FileSystemProps perform() {
  try {
   Path target = vertx.resolveFile(path).toPath();
   FileStore fs = Files.getFileStore(target);
   return new FileSystemPropsImpl(fs.getTotalSpace(), fs.getUnallocatedSpace(), fs.getUsableSpace());
  } catch (IOException e) {
   throw new FileSystemException(e);
  }
 }
};

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

FileStore fileStore = Files.getFileStore( pathOnDevice );
String name = fileStore.name();
if ( name.equals( "tmpfs" ) || name.equals( "hugetlbfs" ) )

代码示例来源:origin: org.apache.lucene/lucene-core

static FileStore getFileStore(Path path) throws IOException {
 FileStore store = Files.getFileStore(path);
 String mount = getMountPoint(store);
 // find the "matching" FileStore from system list, it's the one we want, but only return
 // that if it's unambiguous (only one matching):
 FileStore sameMountPoint = null;
 for (FileStore fs : path.getFileSystem().getFileStores()) {
  if (mount.equals(getMountPoint(fs))) {
   if (sameMountPoint == null) {
    sameMountPoint = fs;
   } else {
    // more than one filesystem has the same mount point; something is wrong!
    // fall back to crappy one we got from Files.getFileStore
    return store;
   }
  }
 }
 if (sameMountPoint != null) {
  // ok, we found only one, use it:
  return sameMountPoint;
 } else {
  // fall back to crappy one we got from Files.getFileStore
  return store;    
 }
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

public void test(final String[] args) {
  System.setProperty("log4j.skipJansi", "false"); // LOG4J2-2087: explicitly enable
  // System.out.println(System.getProperty("java.class.path"));
  final String config = args == null || args.length == 0 ? "target/test-classes/log4j2-console-xex-ansi.xml"
      : args[0];
  final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(), config);
  final Logger logger = LogManager.getLogger(ConsoleAppenderJAnsiXExceptionMain.class);
  try {
    Files.getFileStore(Paths.get("?BOGUS?"));
  } catch (final Exception e) {
    final IllegalArgumentException logE = new IllegalArgumentException("Bad argument foo", e);
    logger.error("Gotcha!", logE);
  } finally {
    Configurator.shutdown(ctx);
  }
}

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

protected Map<String, String> getAttributesFromFile(final Path file) {
  Map<String, String> attributes = new HashMap<>();
  try {
    FileStore store = Files.getFileStore(file);
    if (store.supportsFileAttributeView("basic")) {
      try {

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

FileStore store = Files.getFileStore(filePath);

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

final Path absolutePath = file1.toPath().toAbsolutePath();
final String absolutePathString = absolutePath.getParent().toString() + File.separator;
final FileStore store = Files.getFileStore(file1Path);
final DateFormat formatter = new SimpleDateFormat(ListFile.FILE_MODIFY_DATE_ATTR_FORMAT, Locale.US);
final String time3Formatted = formatter.format(time3rounded);

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

fos = new FileOutputStream(file2);
fos.close();
FileStore store = Files.getFileStore(file2.toPath());
if (store.supportsFileAttributeView("dos")) {
  Files.setAttribute(file2.toPath(), "dos:hidden", true);

相关文章

微信公众号

最新文章

更多