Java Utililty Methods FileStore

List of utility methods to do FileStore

Description

The list of methods to do FileStore are organized into topic(s).

Method

StringgetStorageName(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;
URIgetTopResourceInVolume(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) {
...
booleanisPosixFileStore(Path path)
is Posix File Store
return Files.isSymbolicLink(path) || Files.getFileStore(path).supportsFileAttributeView("posix");
booleanisPosixFileSystem()
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;
...
booleanspinsLinux(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';