@Override public long getStorageCapacity() throws IOException { long capacity = 0L; for (final File file : flowFileRepositoryPaths) { capacity += Files.getFileStore(file.toPath()).getTotalSpace(); } return capacity; }
@Override public String getFileStoreName() { final Path path = flowFileRepositoryPaths.iterator().next().toPath(); try { return Files.getFileStore(path).name(); } catch (IOException e) { return null; } }
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; }
@Override public long getUsableStorageSpace() throws IOException { long usableSpace = 0L; for (final File file : flowFileRepositoryPaths) { usableSpace += Files.getFileStore(file.toPath()).getUsableSpace(); } return usableSpace; }
@Override public String getContainerFileStoreName(final String containerName) { final Path path = containers.get(containerName); try { return Files.getFileStore(path).name(); } catch (IOException e) { return null; } }
/** * 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; }
@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; } }
@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; } }
@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; }
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); } } }
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; }
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; }
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); } } };
FileStore fileStore = Files.getFileStore( pathOnDevice ); String name = fileStore.name(); if ( name.equals( "tmpfs" ) || name.equals( "hugetlbfs" ) )
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; } }
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); } }
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 {
FileStore store = Files.getFileStore(filePath);
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);
fos = new FileOutputStream(file2); fos.close(); FileStore store = Files.getFileStore(file2.toPath()); if (store.supportsFileAttributeView("dos")) { Files.setAttribute(file2.toPath(), "dos:hidden", true);