List of usage examples for java.nio.file FileSystem supportedFileAttributeViews
public abstract Set<String> supportedFileAttributeViews();
From source file:Main.java
public static void main(String[] args) { //list all the supported views in the current file system FileSystem fs = FileSystems.getDefault(); Set<String> views = fs.supportedFileAttributeViews(); for (String view : views) { System.out.println(view); }/*www. j a v a 2 s . c o m*/ }
From source file:Test.java
public static void main(String[] args) { Path path = Paths.get("C:/home/docs/users.txt"); FileSystem fileSystem = path.getFileSystem(); Set<String> supportedViews = fileSystem.supportedFileAttributeViews(); for (String view : supportedViews) { System.out.println(view);/*www. j a v a2s . c om*/ } }
From source file:Main.java
public static void main(String[] args) { Path path = Paths.get("C:/home/docs/users.txt"); FileSystem fileSystem = path.getFileSystem(); Set<String> supportedViews = fileSystem.supportedFileAttributeViews(); for (String view : supportedViews) { System.out.println(view); }// w w w. j a v a 2 s . c o m }
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();//from ww w. j av a 2 s . c o m 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:de.jwi.jfm.Folder.java
private void chmod(File file, String value) throws IOException { Path p = file.toPath();/*from w w w .jav a2 s.c om*/ FileSystem fileSystem = FileSystems.getDefault(); Set<String> fileSystemViews = fileSystem.supportedFileAttributeViews(); if (fileSystemViews.contains("posix")) { Set<PosixFilePermission> posixFilePermissions = PosixFilePermissions.fromString(value); if (posixFilePermissions == null) { throw new IllegalArgumentException(value); } Files.getFileAttributeView(p, PosixFileAttributeView.class).setPermissions(posixFilePermissions); } else if (fileSystemViews.contains("dos")) { } }
From source file:de.tiqsolutions.hdfs.HadoopFileSystemProvider.java
@Override public void copy(Path source, Path target, CopyOption... options) throws IOException { List<CopyOption> optionList = Arrays.asList(options); if (!optionList.contains(StandardCopyOption.REPLACE_EXISTING)) { if (Files.exists(target)) throw new java.nio.file.FileAlreadyExistsException(source.toString(), target.toString(), "could not copy file to destination"); } else {/*from w ww.j a v a 2s . co m*/ Files.deleteIfExists(target); } FileSystem sourceFS = source.getFileSystem(); FileSystem targetFS = target.getFileSystem(); if (optionList.contains(HadoopCopyOption.REMOTE_COPY) && sourceFS.equals(targetFS)) { remoteCopy(source, target, options); return; } try (SeekableByteChannel sourceChannel = sourceFS.provider().newByteChannel(source, EnumSet.of(StandardOpenOption.READ))) { Set<StandardOpenOption> openOptions = EnumSet.of(StandardOpenOption.WRITE); if (optionList.contains(StandardCopyOption.REPLACE_EXISTING)) openOptions.add(StandardOpenOption.CREATE); else openOptions.add(StandardOpenOption.CREATE_NEW); List<FileAttribute<?>> fileAttributes = new ArrayList<>(); if (optionList.contains(StandardCopyOption.COPY_ATTRIBUTES)) { Set<String> sourceAttrViews = sourceFS.supportedFileAttributeViews(); Set<String> targetAttrViews = targetFS.supportedFileAttributeViews(); if (sourceAttrViews.contains(PosixFileAttributeViewImpl.NAME) && targetAttrViews.contains(PosixFileAttributeViewImpl.NAME)) { PosixFileAttributes posixAttributes = sourceFS.provider().readAttributes(source, PosixFileAttributes.class); fileAttributes.add(PosixFilePermissions.asFileAttribute(posixAttributes.permissions())); } if (sourceAttrViews.contains(HadoopFileAttributeViewImpl.NAME) && targetAttrViews.contains(HadoopFileAttributeViewImpl.NAME)) { final HadoopFileAttributes hdfsAttributes = sourceFS.provider().readAttributes(source, HadoopFileAttributes.class); fileAttributes.add(new FileAttribute<Long>() { @Override public String name() { return HadoopFileAttributeViewImpl.NAME + ":blockSize"; } @Override public Long value() { return hdfsAttributes.getBlockSize(); } }); fileAttributes.add(new FileAttribute<Short>() { @Override public String name() { return HadoopFileAttributeViewImpl.NAME + ":replication"; } @Override public Short value() { return hdfsAttributes.getReplication(); } }); } } FileAttribute<?>[] attributes = fileAttributes.toArray(new FileAttribute<?>[fileAttributes.size()]); try (SeekableByteChannel targetChannel = targetFS.provider().newByteChannel(target, openOptions, attributes)) { int buffSize = getConfiguration().getInt(DFSConfigKeys.DFS_STREAM_BUFFER_SIZE_KEY, DFSConfigKeys.DFS_STREAM_BUFFER_SIZE_DEFAULT); ByteBuffer buffer = ByteBuffer.allocate(buffSize); buffer.clear(); while (sourceChannel.read(buffer) > 0) { buffer.flip(); targetChannel.write(buffer); buffer.clear(); } } if (optionList.contains(StandardCopyOption.COPY_ATTRIBUTES)) { BasicFileAttributes attrs = sourceFS.provider().readAttributes(source, BasicFileAttributes.class); BasicFileAttributeView view = targetFS.provider().getFileAttributeView(target, BasicFileAttributeView.class); view.setTimes(attrs.lastModifiedTime(), attrs.lastAccessTime(), attrs.creationTime()); } } }