List of usage examples for java.nio.file.attribute DosFileAttributes isSystem
boolean isSystem();
From source file:Test.java
public static void main(String[] args) throws Exception { Path path = FileSystems.getDefault().getPath("/home/docs/users.txt"); DosFileAttributeView view = Files.getFileAttributeView(path, DosFileAttributeView.class); DosFileAttributes attributes = view.readAttributes(); System.out.println("isArchive: " + attributes.isArchive()); System.out.println("isHidden: " + attributes.isHidden()); System.out.println("isReadOnly: " + attributes.isReadOnly()); System.out.println("isSystem: " + attributes.isSystem()); }
From source file:Main.java
public static void main(String[] args) { DosFileAttributes attr = null; Path path = Paths.get("C:/tutorial/Java/JavaFX", "Topic.txt"); try {//from w w w .j a v a 2s .c om attr = Files.readAttributes(path, DosFileAttributes.class); } catch (IOException e) { System.err.println(e); } System.out.println("Is system ? " + attr.isSystem()); }
From source file:com.nsn.squirrel.tab.utils.PathUtils.java
/** * @param path//from w ww . ja v a 2s . c o m * @return */ public static String getDosAttributesString(Path path) { DosFileAttributeView basicView = Files.getFileAttributeView(path, DosFileAttributeView.class, LinkOption.NOFOLLOW_LINKS); StringBuilder attrs = new StringBuilder(); try { // + all basic attributes DosFileAttributes dosAttrs = basicView.readAttributes(); attrs.append(dosAttrs.isReadOnly() ? "r" : "-"); //$NON-NLS-1$ //$NON-NLS-2$ attrs.append(dosAttrs.isHidden() ? "h" : "-");//$NON-NLS-1$ //$NON-NLS-2$ attrs.append(dosAttrs.isArchive() ? "a" : "-");//$NON-NLS-1$ //$NON-NLS-2$ attrs.append(dosAttrs.isSystem() ? "s" : "-");//$NON-NLS-1$ //$NON-NLS-2$ } catch (IOException e) { log.warn("unable to read DOS attributes.", e); //$NON-NLS-1$ } return attrs.toString(); }
From source file:cane.brothers.e4.commander.utils.PathUtils.java
/** * @param path//from w w w. ja v a 2 s. co m * @return */ public static String getDosAttributesString(Path path) { DosFileAttributeView basicView = Files.getFileAttributeView(path, DosFileAttributeView.class, LinkOption.NOFOLLOW_LINKS); StringBuilder attrs = new StringBuilder(); try { // + all basic attributes DosFileAttributes dosAttrs = basicView.readAttributes(); attrs.append(dosAttrs.isReadOnly() ? "r" : "-"); //$NON-NLS-1$ //$NON-NLS-2$ attrs.append(dosAttrs.isHidden() ? "h" : "-");//$NON-NLS-1$ //$NON-NLS-2$ attrs.append(dosAttrs.isArchive() ? "a" : "-");//$NON-NLS-1$ //$NON-NLS-2$ attrs.append(dosAttrs.isSystem() ? "s" : "-");//$NON-NLS-1$ //$NON-NLS-2$ } catch (IOException e) { log.warn("unable to read DOS attributes.", e); //$NON-NLS-1$ } return attrs.toString(); }
From source file:org.ballerinalang.composer.service.fs.LocalFileSystem.java
private boolean isWindowsSystemFile(Path filePath) throws IOException { if (SystemUtils.IS_OS_WINDOWS) { DosFileAttributes dosAttribs = Files.readAttributes(filePath, DosFileAttributes.class); return dosAttribs.isSystem(); }//from w ww.j ava 2s . c om return false; }
From source file:VOBackupFile.java
/** * Wrapper for metadata of backuped file. * * @param file backuped file//from ww w. j av a 2 s . c o m */ public VOBackupFile(File file) { this.path = file.getAbsolutePath(); this.directory = file.isDirectory(); this.symLink = Files.isSymbolicLink(file.toPath()); this.size = ((file.isDirectory() || symLink) ? 0 : file.length()); this.modify = new Date(file.lastModified()); if (symLink) { try { symlinkTarget = Files.readSymbolicLink(file.toPath()).toString(); } catch (IOException e) { e.printStackTrace(); //TODO Lebeda - oetit do logu } } else { // advanced attributes try { owner = Files.getOwner(file.toPath(), LinkOption.NOFOLLOW_LINKS).getName(); if (Files.getFileStore(file.toPath()).supportsFileAttributeView(DosFileAttributeView.class)) { dosAttr = Boolean.TRUE; final DosFileAttributes dosFileAttributes = Files.readAttributes(file.toPath(), DosFileAttributes.class, LinkOption.NOFOLLOW_LINKS); dosArchive = dosFileAttributes.isArchive(); dosHidden = dosFileAttributes.isHidden(); dosSystem = dosFileAttributes.isSystem(); dosReadOnly = dosFileAttributes.isReadOnly(); } else { dosAttr = Boolean.FALSE; } if (Files.getFileStore(file.toPath()).supportsFileAttributeView(PosixFileAttributeView.class)) { posixAttr = Boolean.TRUE; final PosixFileAttributes posixFileAttributes = Files.readAttributes(file.toPath(), PosixFileAttributes.class, LinkOption.NOFOLLOW_LINKS); posixGroup = posixFileAttributes.group().getName(); posixPermitions = PosixFilePermissions.toString(posixFileAttributes.permissions()); } else { posixAttr = Boolean.FALSE; } } catch (IOException e) { e.printStackTrace(); //Todo implementovat } } }
From source file:de.jwi.jfm.FileWrapper.java
public String getAttributes() throws IOException { FileSystem fileSystem = FileSystems.getDefault(); Set<String> fileSystemViews = fileSystem.supportedFileAttributeViews(); File file = getFile();//www .j av a2s . com Path p = file.toPath(); try { if (fileSystemViews.contains("posix")) { Set<PosixFilePermission> posixFilePermissions = Files.getPosixFilePermissions(p, LinkOption.NOFOLLOW_LINKS); PosixFileAttributes attrs = Files.getFileAttributeView(p, PosixFileAttributeView.class) .readAttributes(); String owner = attrs.owner().toString(); String group = attrs.group().toString(); String permissions = PosixFilePermissions.toString(attrs.permissions()); String res = String.format("%s %s %s", permissions, owner, group); return res; } else if (fileSystemViews.contains("dos")) { StringWriter sw = new StringWriter(); DosFileAttributeView attributeView = Files.getFileAttributeView(p, DosFileAttributeView.class); DosFileAttributes dosFileAttributes = null; dosFileAttributes = attributeView.readAttributes(); if (dosFileAttributes.isArchive()) { sw.append('A'); } if (dosFileAttributes.isHidden()) { sw.append('H'); } if (dosFileAttributes.isReadOnly()) { sw.append('R'); } if (dosFileAttributes.isSystem()) { sw.append('S'); } return sw.toString(); } } catch (Exception e) { e.printStackTrace(); } return ""; }
From source file:org.fim.util.DosFilePermissionsTest.java
@Test public void weCanRetrieveTheStringVersion() { DosFileAttributes dosFileAttributes = mock(DosFileAttributes.class); assertThat(DosFilePermissions.toString(dosFileAttributes)).isEqualTo(""); Mockito.when(dosFileAttributes.isArchive()).thenReturn(true); assertThat(DosFilePermissions.toString(dosFileAttributes)).isEqualTo("A"); Mockito.when(dosFileAttributes.isHidden()).thenReturn(true); assertThat(DosFilePermissions.toString(dosFileAttributes)).isEqualTo("AH"); Mockito.when(dosFileAttributes.isReadOnly()).thenReturn(true); assertThat(DosFilePermissions.toString(dosFileAttributes)).isEqualTo("AHR"); Mockito.when(dosFileAttributes.isSystem()).thenReturn(true); assertThat(DosFilePermissions.toString(dosFileAttributes)).isEqualTo("AHRS"); }
From source file:org.syncany.operations.actions.FileSystemAction.java
protected void setFileAttributes(FileVersion reconstructedFileVersion, File reconstructedFilesAtFinalLocation) throws IOException { if (FileUtil.isWindows()) { if (reconstructedFileVersion.getDosAttributes() != null) { logger.log(Level.INFO, " - Setting DOS attributes: " + reconstructedFileVersion.getDosAttributes() + " ..."); DosFileAttributes dosAttrs = FileUtil .dosAttrsFromString(reconstructedFileVersion.getDosAttributes()); Path filePath = Paths.get(reconstructedFilesAtFinalLocation.getAbsolutePath()); Files.setAttribute(filePath, "dos:readonly", dosAttrs.isReadOnly()); Files.setAttribute(filePath, "dos:hidden", dosAttrs.isHidden()); Files.setAttribute(filePath, "dos:archive", dosAttrs.isArchive()); Files.setAttribute(filePath, "dos:system", dosAttrs.isSystem()); }//from w w w.jav a2s.c o m } else if (FileUtil.isUnixLikeOperatingSystem()) { if (reconstructedFileVersion.getPosixPermissions() != null) { logger.log(Level.INFO, " - Setting POSIX permissions: " + reconstructedFileVersion.getPosixPermissions() + " ..."); Set<PosixFilePermission> posixPerms = PosixFilePermissions .fromString(reconstructedFileVersion.getPosixPermissions()); Path filePath = Paths.get(reconstructedFilesAtFinalLocation.getAbsolutePath()); Files.setPosixFilePermissions(filePath, posixPerms); } } }
From source file:org.syncany.operations.down.actions.FileSystemAction.java
protected void setFileAttributes(FileVersion reconstructedFileVersion, File reconstructedFilesAtFinalLocation) throws IOException { if (EnvironmentUtil.isWindows()) { if (reconstructedFileVersion.getDosAttributes() != null) { logger.log(Level.INFO, " - Setting DOS attributes: " + reconstructedFileVersion.getDosAttributes() + " ..."); DosFileAttributes dosAttrs = FileUtil .dosAttrsFromString(reconstructedFileVersion.getDosAttributes()); Path filePath = Paths.get(reconstructedFilesAtFinalLocation.getAbsolutePath()); try { Files.setAttribute(filePath, "dos:readonly", dosAttrs.isReadOnly()); Files.setAttribute(filePath, "dos:hidden", dosAttrs.isHidden()); Files.setAttribute(filePath, "dos:archive", dosAttrs.isArchive()); Files.setAttribute(filePath, "dos:system", dosAttrs.isSystem()); } catch (IOException e) { logger.log(Level.WARNING, " - WARNING: Cannot set file attributes for " + filePath, e); }// w ww .j ava 2 s . c om } } else if (EnvironmentUtil.isUnixLikeOperatingSystem()) { if (reconstructedFileVersion.getPosixPermissions() != null) { logger.log(Level.INFO, " - Setting POSIX permissions: " + reconstructedFileVersion.getPosixPermissions() + " ..."); Set<PosixFilePermission> posixPerms = PosixFilePermissions .fromString(reconstructedFileVersion.getPosixPermissions()); Path filePath = Paths.get(reconstructedFilesAtFinalLocation.getAbsolutePath()); try { Files.setPosixFilePermissions(filePath, posixPerms); } catch (IOException e) { logger.log(Level.WARNING, " - WARNING: Cannot set file permissions for " + filePath, e); } } } }