List of utility methods to do FileStore
boolean | canExecuteExecutable(File file) can Execute Executable if (file.canExecute()) { return true; Set<PosixFilePermission> existingFilePermissions = java.nio.file.Files .getPosixFilePermissions(file.toPath()); Set<java.nio.file.attribute.PosixFilePermission> executePermissions = EnumSet.of(OWNER_EXECUTE, GROUP_EXECUTE, OTHERS_EXECUTE); if (existingFilePermissions.containsAll(executePermissions)) { ... |
Path | createTempFileWithAttributes(Path tempFilePath, File fileName) create Temp File With Attributes Path exisitingFilePath = fileName.toPath(); List<FileAttribute> attributes = new ArrayList<>(2); attributes.addAll(getPosixAttributes(exisitingFilePath)); attributes.addAll(getAclAttributes(exisitingFilePath)); if (!attributes.isEmpty()) { try { return Files.createFile(tempFilePath, attributes.toArray(new FileAttribute<?>[attributes.size()])); } catch (UnsupportedOperationException ex) { ... |
String | diskFree() disk Free String result = ""; long free = 0; File f = new File(System.getProperty("user.dir")); String root = ""; while (f.getParent() != null) { root = f.getParent(); f = new File(root); try { URI rootURI = new URI("file:///"); Path rootPath = Paths.get(rootURI); Path dirPath = rootPath.resolve(root); FileStore dirFileStore = Files.getFileStore(dirPath); free = dirFileStore.getUsableSpace() / 1048576; result = String.valueOf(free) + " mb on " + root; } catch (Exception e) { result = "Error trying to determine free disk space " + e.getLocalizedMessage(); return result; |
Path | ensureExists(Path folder) ensure Exists if (folder != null && !Files.exists(folder)) { if (isPosixFileSystem()) { Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rwxr-xr-x"); FileAttribute<Set<PosixFilePermission>> attrs = PosixFilePermissions.asFileAttribute(perms); folder = Files.createDirectory(folder, attrs); } else { folder = Files.createDirectory(folder); return folder; |
Path | findTopResourceInVolume(FileStore fstore, Path path) find Top Resource In Volume Path parent = path.getParent(); if (parent == null) { return path; } else { FileStore parentStore = FileSystems.getDefault().provider().getFileStore(parent); if (fstore.equals(parentStore)) { return findTopResourceInVolume(fstore, parent); } else { ... |
List | getAclAttributes(Path file) get Acl Attributes if (Files.exists(file) && Files.getFileStore(file).supportsFileAttributeView(AclFileAttributeView.class)) { AclFileAttributeView aclView = Files.getFileAttributeView(file, AclFileAttributeView.class); if (aclView != null) { final List<AclEntry> entries = aclView.getAcl(); return Collections.singletonList(new FileAttribute<List<AclEntry>>() { @Override public List<AclEntry> value() { return entries; ... |
FileStore | getFileStore(Path path) get File Store FileStore store = Files.getFileStore(path); String mount = getMountPoint(store); FileStore sameMountPoint = null; for (FileStore fs : path.getFileSystem().getFileStores()) { if (mount.equals(getMountPoint(fs))) { if (sameMountPoint == null) { sameMountPoint = fs; } else { ... |
FileStore | getFileStore(URI uri) get File Store Path path = Paths.get(uri);
FileStore fstore = path.getFileSystem().provider().getFileStore(path);
return fstore;
|
String | getMountPoint(FileStore store) get Mount Point String desc = store.toString(); int index = desc.lastIndexOf(" ("); if (index != -1) { return desc.substring(0, index); } else { return desc; |
List | getPosixAttributes(Path file) get Posix Attributes if (Files.exists(file) && Files.getFileStore(file).supportsFileAttributeView(PosixFileAttributeView.class)) { PosixFileAttributeView posixView = Files.getFileAttributeView(file, PosixFileAttributeView.class); if (posixView != null) { return Collections.singletonList( PosixFilePermissions.asFileAttribute(posixView.readAttributes().permissions())); return Collections.emptyList(); |