本文整理汇总了Java中java.nio.file.attribute.FileOwnerAttributeView.setOwner方法的典型用法代码示例。如果您正苦于以下问题:Java FileOwnerAttributeView.setOwner方法的具体用法?Java FileOwnerAttributeView.setOwner怎么用?Java FileOwnerAttributeView.setOwner使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.file.attribute.FileOwnerAttributeView
的用法示例。
在下文中一共展示了FileOwnerAttributeView.setOwner方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testReadOwner
import java.nio.file.attribute.FileOwnerAttributeView; //导入方法依赖的package包/类
@Test
public void testReadOwner() throws Exception {
for(Path path : Arrays.asList(
Files.createDirectory(root.resolve("dir")),
Files.createFile(root.resolve("file")))) {
FileOwnerAttributeView view = Files.getFileAttributeView(path, FileOwnerAttributeView.class);
assertNotNull(view.getOwner());
view.setOwner(view.getOwner());
UserPrincipal owner = (UserPrincipal) Files.getAttribute(path, "owner:owner");
assertNotNull(owner);
}
}
示例2: testView
import java.nio.file.attribute.FileOwnerAttributeView; //导入方法依赖的package包/类
@Test
public void testView() throws IOException {
FileOwnerAttributeView view = provider.view(fileLookup(), NO_INHERITED_VIEWS);
assertThat(view).isNotNull();
assertThat(view.name()).isEqualTo("owner");
assertThat(view.getOwner()).isEqualTo(createUserPrincipal("user"));
view.setOwner(createUserPrincipal("root"));
assertThat(view.getOwner()).isEqualTo(createUserPrincipal("root"));
assertThat(file.getAttribute("owner", "owner")).isEqualTo(createUserPrincipal("root"));
}
示例3: setOwner
import java.nio.file.attribute.FileOwnerAttributeView; //导入方法依赖的package包/类
/**
* 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;
}
示例4: setOwner
import java.nio.file.attribute.FileOwnerAttributeView; //导入方法依赖的package包/类
/**
* 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;
}