当前位置: 首页>>代码示例>>Java>>正文


Java FileOwnerAttributeView.setOwner方法代码示例

本文整理汇总了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);
    }
    
}
 
开发者ID:sbridges,项目名称:ephemeralfs,代码行数:16,代码来源:OwnerFileAttributesTest.java

示例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"));
}
 
开发者ID:google,项目名称:jimfs,代码行数:13,代码来源:OwnerAttributeProviderTest.java

示例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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:49,代码来源:Files.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:50,代码来源:Files.java


注:本文中的java.nio.file.attribute.FileOwnerAttributeView.setOwner方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。