use of java.nio.file.attribute.PosixFileAttributeView in project alluxio by Alluxio.
the class FileUtils method changeLocalFileGroup.
/**
* Changes the local file's group.
*
* @param path that will change owner
* @param group the new group
* @throws IOException if the group is unable to be changed
*/
public static void changeLocalFileGroup(String path, String group) throws IOException {
UserPrincipalLookupService lookupService = FileSystems.getDefault().getUserPrincipalLookupService();
PosixFileAttributeView view = Files.getFileAttributeView(Paths.get(path), PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
GroupPrincipal groupPrincipal = lookupService.lookupPrincipalByGroupName(group);
view.setGroup(groupPrincipal);
}
use of java.nio.file.attribute.PosixFileAttributeView in project jdk8u_jdk by JetBrains.
the class Files method setPosixFilePermissions.
/**
* Sets a file's POSIX permissions.
*
* <p> The {@code path} parameter is associated with a {@code FileSystem}
* that supports the {@link PosixFileAttributeView}. This attribute view
* provides access to file attributes commonly associated with files on file
* systems used by operating systems that implement the Portable Operating
* System Interface (POSIX) family of standards.
*
* @param path
* The path to the file
* @param perms
* The new set of permissions
*
* @return The path
*
* @throws UnsupportedOperationException
* if the associated file system does not support the {@code
* PosixFileAttributeView}
* @throws ClassCastException
* if the sets contains elements that are not of type {@code
* PosixFilePermission}
* @throws IOException
* if an I/O error occurs
* @throws SecurityException
* In the case of the default provider, and a security manager is
* installed, it denies {@link RuntimePermission}<tt>("accessUserInformation")</tt>
* or its {@link SecurityManager#checkWrite(String) checkWrite}
* method denies write access to the file.
*/
public static Path setPosixFilePermissions(Path path, Set<PosixFilePermission> perms) throws IOException {
PosixFileAttributeView view = getFileAttributeView(path, PosixFileAttributeView.class);
if (view == null)
throw new UnsupportedOperationException();
view.setPermissions(perms);
return path;
}
use of java.nio.file.attribute.PosixFileAttributeView in project ignite by apache.
the class IgfsLocalSecondaryFileSystemTestAdapter method permissions.
/**
* {@inheritDoc}
*/
@Override
public String permissions(String path) throws IOException {
Path p = path(path);
PosixFileAttributeView attrView = Files.getFileAttributeView(p, PosixFileAttributeView.class);
if (attrView == null)
throw new UnsupportedOperationException("Posix file attributes not available");
int perm = 0;
for (PosixFilePermission pfp : attrView.readAttributes().permissions()) perm |= (1 << 8 - pfp.ordinal());
return '0' + Integer.toOctalString(perm);
}
Aggregations