List of utility methods to do FileStore
String | getStorageName(final File file) Returns a storage name (volume name). Path path = Paths.get(file.getPath());
FileStore fs = Files.getFileStore(path);
String storageName = fs.name();
return storageName;
|
URI | getTopResourceInVolume(URI location) get Top Resource In Volume Path path = Paths.get(location); FileStore fstore = getFileStore(location); Path p = findTopResourceInVolume(fstore, path); try { URI result = new URI(location.getScheme(), location.getUserInfo(), location.getHost(), location.getPort(), p.toUri().getPath(), location.getQuery(), location.getFragment()); return result; } catch (URISyntaxException e) { ... |
boolean | isPosixFileStore(Path path) is Posix File Store return Files.isSymbolicLink(path) || Files.getFileStore(path).supportsFileAttributeView("posix"); |
boolean | isPosixFileSystem() is Posix File System if (supportsPosix == null) { supportsPosix = Boolean.FALSE; FileSystem fileSystem = FileSystems.getDefault(); Iterable<FileStore> fileStores = fileSystem.getFileStores(); for (FileStore fs : fileStores) { supportsPosix = fs.supportsFileAttributeView(PosixFileAttributeView.class); if (supportsPosix) { break; ... |
boolean | spinsLinux(Path path) spins Linux FileStore store = getFileStore(path); if ("tmpfs".equals(store.type())) { return false; String devName = store.name(); if (!devName.startsWith("/")) { return true; devName = path.getRoot().resolve(devName).toRealPath().getFileName().toString(); Path sysinfo = path.getRoot().resolve("sys").resolve("block"); Path devsysinfo = null; int matchlen = 0; try (DirectoryStream<Path> stream = Files.newDirectoryStream(sysinfo)) { for (Path device : stream) { String name = device.getFileName().toString(); if (name.length() > matchlen && devName.startsWith(name)) { devsysinfo = device; matchlen = name.length(); if (devsysinfo == null) { return true; Path rotational = devsysinfo.resolve("queue").resolve("rotational"); try (InputStream stream = Files.newInputStream(rotational)) { return stream.read() == '1'; |