use of java.nio.file.attribute.FileOwnerAttributeView in project j2objc by google.
the class Files method setOwner.
/**
* Updates the file owner.
*
* <p> The {@code path} parameter is associated with a file system that
* supports {@link FileOwnerAttributeView}. This file attribute view provides
* access to a file attribute that is the owner of the file.
*
* <p> <b>Usage Example:</b>
* Suppose we want to make "joe" the owner of a file:
* <pre>
* Path path = ...
* UserPrincipalLookupService lookupService =
* provider(path).getUserPrincipalLookupService();
* UserPrincipal joe = lookupService.lookupPrincipalByName("joe");
* Files.setOwner(path, joe);
* </pre>
*
* @param path
* The path to the file
* @param owner
* The new file owner
*
* @return The path
*
* @throws UnsupportedOperationException
* if the associated file system does not support the {@code
* FileOwnerAttributeView}
* @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.
*
* @see FileSystem#getUserPrincipalLookupService
* @see java.nio.file.attribute.UserPrincipalLookupService
*/
public static Path setOwner(Path path, UserPrincipal owner) throws IOException {
FileOwnerAttributeView view = getFileAttributeView(path, FileOwnerAttributeView.class);
if (view == null)
throw new UnsupportedOperationException();
view.setOwner(owner);
return path;
}
use of java.nio.file.attribute.FileOwnerAttributeView in project OpenClinica by OpenClinica.
the class SystemController method displayOwnerShipForTomcatSubDirectories.
public ArrayList<HashMap<String, Object>> displayOwnerShipForTomcatSubDirectories(File dir) throws IOException {
ArrayList<HashMap<String, Object>> listOfHashMaps = new ArrayList<>();
HashMap<String, Object> hashMap = null;
File[] files = dir.listFiles();
for (File file : files) {
if (file.isDirectory()) {
hashMap = new HashMap<String, Object>();
hashMap.put("Read Access", getReadAccess(file));
hashMap.put("Write Access", getWriteAccess(file));
Path path = Paths.get(file.getCanonicalPath());
FileOwnerAttributeView ownerAttributeView = Files.getFileAttributeView(path, FileOwnerAttributeView.class);
UserPrincipal owner = ownerAttributeView.getOwner();
// hashMap.put("ownership", owner.getName());
hashMap.put("Folder Name", file.getName());
listOfHashMaps.add(hashMap);
int dirCount = getNumberOfSubFolders(file.getCanonicalPath().toString());
if (dirCount != 0) {
// hashMap.put("Sub Folders", displayOwnerShipForTomcatSubDirectories(file));
}
}
}
return listOfHashMaps;
}
use of java.nio.file.attribute.FileOwnerAttributeView in project jdk8u_jdk by JetBrains.
the class Files method setOwner.
/**
* Updates the file owner.
*
* <p> The {@code path} parameter is associated with a file system that
* supports {@link FileOwnerAttributeView}. This file attribute view provides
* access to a file attribute that is the owner of the file.
*
* <p> <b>Usage Example:</b>
* Suppose we want to make "joe" the owner of a file:
* <pre>
* Path path = ...
* UserPrincipalLookupService lookupService =
* provider(path).getUserPrincipalLookupService();
* UserPrincipal joe = lookupService.lookupPrincipalByName("joe");
* Files.setOwner(path, joe);
* </pre>
*
* @param path
* The path to the file
* @param owner
* The new file owner
*
* @return The path
*
* @throws UnsupportedOperationException
* if the associated file system does not support the {@code
* FileOwnerAttributeView}
* @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.
*
* @see FileSystem#getUserPrincipalLookupService
* @see java.nio.file.attribute.UserPrincipalLookupService
*/
public static Path setOwner(Path path, UserPrincipal owner) throws IOException {
FileOwnerAttributeView view = getFileAttributeView(path, FileOwnerAttributeView.class);
if (view == null)
throw new UnsupportedOperationException();
view.setOwner(owner);
return path;
}
use of java.nio.file.attribute.FileOwnerAttributeView in project processdash by dtuma.
the class WhoAmI method identifyUserFromFileIO.
private void identifyUserFromFileIO() {
try {
File f = File.createTempFile("whoami", ".tmp");
Path path = Paths.get(f.getAbsolutePath());
FileOwnerAttributeView ownerAttributeView = Files.getFileAttributeView(path, FileOwnerAttributeView.class);
UserPrincipal owner = ownerAttributeView.getOwner();
this.username = discardDomain(owner.getName());
f.delete();
logger.info("From NIO, current user is " + username);
} catch (Throwable t) {
// this will fail on Java 1.6. Try the next option
}
}
use of java.nio.file.attribute.FileOwnerAttributeView in project Bytecoder by mirkosertic.
the class Files method setOwner.
/**
* Updates the file owner.
*
* <p> The {@code path} parameter is associated with a file system that
* supports {@link FileOwnerAttributeView}. This file attribute view provides
* access to a file attribute that is the owner of the file.
*
* <p> <b>Usage Example:</b>
* Suppose we want to make "joe" the owner of a file:
* <pre>
* Path path = ...
* UserPrincipalLookupService lookupService =
* provider(path).getUserPrincipalLookupService();
* UserPrincipal joe = lookupService.lookupPrincipalByName("joe");
* Files.setOwner(path, joe);
* </pre>
*
* @param path
* The path to the file
* @param owner
* The new file owner
*
* @return The given path
*
* @throws UnsupportedOperationException
* if the associated file system does not support the {@code
* FileOwnerAttributeView}
* @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}{@code ("accessUserInformation")}
* or its {@link SecurityManager#checkWrite(String) checkWrite}
* method denies write access to the file.
*
* @see FileSystem#getUserPrincipalLookupService
* @see java.nio.file.attribute.UserPrincipalLookupService
*/
public static Path setOwner(Path path, UserPrincipal owner) throws IOException {
FileOwnerAttributeView view = getFileAttributeView(path, FileOwnerAttributeView.class);
if (view == null)
throw new UnsupportedOperationException();
view.setOwner(owner);
return path;
}
Aggregations