类java.nio.file.attribute.FileOwnerAttributeView源码实例Demo

下面列出了怎么用java.nio.file.attribute.FileOwnerAttributeView的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: jumbune   文件: CommandDelegatorMethods.java
/** This method changes the ownership of folder/file to the user provided
 * @param destinationLocation : the location of the path to be owned
 * @param user : the user which needs to own the folder/file
 */
private void changeOwnership(String destinationLocation, String user){
	
	Path path = Paths.get(destinationLocation);
    FileOwnerAttributeView view = Files.getFileAttributeView(path,
        FileOwnerAttributeView.class);
    UserPrincipalLookupService lookupService = FileSystems.getDefault()
        .getUserPrincipalLookupService();
    UserPrincipal userPrincipal;
	try {
		userPrincipal = lookupService.lookupPrincipalByName(user);
		Files.setOwner(path, userPrincipal);
	} catch (IOException e) {
		LOGGER.error("Error while changing ownership of destination location[" + destinationLocation +"]" + "to user[" + user + "]" , e);
	}
}
 
源代码2 项目: cwlexec   文件: CWLParser.java
private static String getFileOwner(File file) {
    String owner = null;
    if (file != null) {
        Path path = Paths.get(file.getAbsolutePath());
        try {
            UserPrincipal user = Files.getFileAttributeView(path, FileOwnerAttributeView.class).getOwner();
            return user.getName();
        } catch (IOException e) {
            logger.warn("Fail to get the owner of {}, ({})", path, e.getMessage());
        }
    }
    return owner;
}
 
源代码3 项目: lucene-solr   文件: SolrCLI.java
public static String userForDir(Path pathToDir) {
  try {
    FileOwnerAttributeView ownerAttributeView = Files.getFileAttributeView(pathToDir, FileOwnerAttributeView.class);
    return ownerAttributeView.getOwner().getName();
  } catch (IOException e) {
    return "N/A";
  }
}
 
源代码4 项目: sftp-fs   文件: SFTPFileSystemProvider.java
/**
 * Returns a file attribute view of a given type.
 * This method works in exactly the manner specified by the {@link Files#getFileAttributeView(Path, Class, LinkOption...)} method.
 * <p>
 * This provider supports {@link BasicFileAttributeView}, {@link FileOwnerAttributeView} and {@link PosixFileAttributeView}.
 * All other classes will result in a {@code null} return value.
 * <p>
 * Note: if the type is {@link BasicFileAttributeView} or a sub type, the last access time and creation time must be {@code null} when calling
 * {@link BasicFileAttributeView#setTimes(FileTime, FileTime, FileTime)}, otherwise an exception will be thrown.
 * When setting the owner or group for the path, the name must be the UID/GID of the owner/group.
 */
@Override
public <V extends FileAttributeView> V getFileAttributeView(Path path, Class<V> type, LinkOption... options) {
    Objects.requireNonNull(type);
    if (type == BasicFileAttributeView.class) {
        return type.cast(new AttributeView("basic", toSFTPPath(path))); //$NON-NLS-1$
    }
    if (type == FileOwnerAttributeView.class) {
        return type.cast(new AttributeView("owner", toSFTPPath(path))); //$NON-NLS-1$
    }
    if (type == PosixFileAttributeView.class) {
        return type.cast(new AttributeView("posix", toSFTPPath(path))); //$NON-NLS-1$
    }
    return null;
}
 
源代码5 项目: jsr203-hadoop   文件: HadoopFileSystem.java
@SuppressWarnings("unchecked")
<V extends FileAttributeView> V getView(HadoopPath path, Class<V> type) {
       if (type == null)
           throw new NullPointerException();
       if (type == BasicFileAttributeView.class)
           return (V)new HadoopBasicFileAttributeView(path, false);
       if (type == HadoopBasicFileAttributeView.class)
           return (V)new HadoopBasicFileAttributeView(path, true);
       if (type == FileOwnerAttributeView.class)
           return (V)new HadoopPosixFileAttributeView(path, false);
       if (type == PosixFileAttributeView.class)
           return (V)new HadoopPosixFileAttributeView(path, true);
       return null;
   }
 
源代码6 项目: jsr203-hadoop   文件: TestFiles.java
@Test
public void getFileAttributeViewFileOwnerAttributeView() throws IOException {
  Path rootPath = Paths.get(clusterUri);
  Path path = Files.createTempFile(rootPath, "test", "tmp");
  FileOwnerAttributeView view = Files.getFileAttributeView(path,
      FileOwnerAttributeView.class);
  Assert.assertNotNull(view);
  Assert.assertEquals("owner", view.name());
}
 
源代码7 项目: wildfly-core   文件: FilePersistenceUtils.java
private static boolean supportsFileOwnerAttributeView(Path path, Class<? extends FileOwnerAttributeView> view) {
    FileStore store;
    try {
        store = Files.getFileStore(path);
    } catch (IOException e) {
        return false;
    }
    return store.supportsFileAttributeView(view);
}
 
源代码8 项目: jimfs   文件: PosixAttributeProvider.java
@Override
public PosixFileAttributeView view(
    FileLookup lookup, ImmutableMap<String, FileAttributeView> inheritedViews) {
  return new View(
      lookup,
      (BasicFileAttributeView) inheritedViews.get("basic"),
      (FileOwnerAttributeView) inheritedViews.get("owner"));
}
 
源代码9 项目: jimfs   文件: OwnerAttributeProviderTest.java
@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"));
}
 
private static void setPermissionsToOwnerOnlyWindows(File file) throws IOException {
  Path path = Paths.get(file.getAbsolutePath());
  FileOwnerAttributeView fileAttributeView =
      Files.getFileAttributeView(path, FileOwnerAttributeView.class);
  UserPrincipal owner = fileAttributeView.getOwner();

  // get view
  AclFileAttributeView view = Files.getFileAttributeView(path, AclFileAttributeView.class);

  // All available entries
  Set<AclEntryPermission> permissions =
      ImmutableSet.of(
          AclEntryPermission.APPEND_DATA,
          AclEntryPermission.DELETE,
          AclEntryPermission.DELETE_CHILD,
          AclEntryPermission.READ_ACL,
          AclEntryPermission.READ_ATTRIBUTES,
          AclEntryPermission.READ_DATA,
          AclEntryPermission.READ_NAMED_ATTRS,
          AclEntryPermission.SYNCHRONIZE,
          AclEntryPermission.WRITE_ACL,
          AclEntryPermission.WRITE_ATTRIBUTES,
          AclEntryPermission.WRITE_DATA,
          AclEntryPermission.WRITE_NAMED_ATTRS,
          AclEntryPermission.WRITE_OWNER);

  // create ACL to give owner everything
  AclEntry entry =
      AclEntry.newBuilder()
          .setType(AclEntryType.ALLOW)
          .setPrincipal(owner)
          .setPermissions(permissions)
          .build();

  // Overwrite the ACL with only this permission
  try {
    view.setAcl(ImmutableList.of(entry));
  } catch (SecurityException ex) {
    throw new IOException("Unable to set permissions for " + file, ex);
  }
}
 
源代码11 项目: jimfs   文件: OwnerAttributeProvider.java
@Override
public Class<FileOwnerAttributeView> viewType() {
  return FileOwnerAttributeView.class;
}
 
源代码12 项目: jimfs   文件: OwnerAttributeProvider.java
@Override
public FileOwnerAttributeView view(
    FileLookup lookup, ImmutableMap<String, FileAttributeView> inheritedViews) {
  return new View(lookup);
}
 
源代码13 项目: jimfs   文件: PosixAttributeProvider.java
protected View(
    FileLookup lookup, BasicFileAttributeView basicView, FileOwnerAttributeView ownerView) {
  super(lookup);
  this.basicView = checkNotNull(basicView);
  this.ownerView = checkNotNull(ownerView);
}
 
源代码14 项目: jimfs   文件: AclAttributeProvider.java
@Override
public AclFileAttributeView view(
    FileLookup lookup, ImmutableMap<String, FileAttributeView> inheritedViews) {
  return new View(lookup, (FileOwnerAttributeView) inheritedViews.get("owner"));
}
 
源代码15 项目: jimfs   文件: AclAttributeProvider.java
public View(FileLookup lookup, FileOwnerAttributeView ownerView) {
  super(lookup);
  this.ownerView = checkNotNull(ownerView);
}
 
源代码16 项目: jdk1.8-source-analysis   文件: Files.java
/**
 * Returns the owner of a file.
 *
 * <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.
 *
 * @param   path
 *          The path to the file
 * @param   options
 *          options indicating how symbolic links are handled
 *
 * @return  A user principal representing the owner of the file
 *
 * @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#checkRead(String) checkRead} method
 *          denies read access to the file.
 */
public static UserPrincipal getOwner(Path path, LinkOption... options) throws IOException {
    FileOwnerAttributeView view =
        getFileAttributeView(path, FileOwnerAttributeView.class, options);
    if (view == null)
        throw new UnsupportedOperationException();
    return view.getOwner();
}
 
源代码17 项目: jdk1.8-source-analysis   文件: Files.java
/**
 * 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;
}
 
源代码18 项目: dragonwell8_jdk   文件: Files.java
/**
 * Returns the owner of a file.
 *
 * <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.
 *
 * @param   path
 *          The path to the file
 * @param   options
 *          options indicating how symbolic links are handled
 *
 * @return  A user principal representing the owner of the file
 *
 * @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#checkRead(String) checkRead} method
 *          denies read access to the file.
 */
public static UserPrincipal getOwner(Path path, LinkOption... options) throws IOException {
    FileOwnerAttributeView view =
        getFileAttributeView(path, FileOwnerAttributeView.class, options);
    if (view == null)
        throw new UnsupportedOperationException();
    return view.getOwner();
}
 
源代码19 项目: dragonwell8_jdk   文件: Files.java
/**
 * 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;
}
 
源代码20 项目: TencentKona-8   文件: Files.java
/**
 * Returns the owner of a file.
 *
 * <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.
 *
 * @param   path
 *          The path to the file
 * @param   options
 *          options indicating how symbolic links are handled
 *
 * @return  A user principal representing the owner of the file
 *
 * @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#checkRead(String) checkRead} method
 *          denies read access to the file.
 */
public static UserPrincipal getOwner(Path path, LinkOption... options) throws IOException {
    FileOwnerAttributeView view =
        getFileAttributeView(path, FileOwnerAttributeView.class, options);
    if (view == null)
        throw new UnsupportedOperationException();
    return view.getOwner();
}
 
源代码21 项目: TencentKona-8   文件: Files.java
/**
 * 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;
}
 
源代码22 项目: jdk8u60   文件: Files.java
/**
 * Returns the owner of a file.
 *
 * <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.
 *
 * @param   path
 *          The path to the file
 * @param   options
 *          options indicating how symbolic links are handled
 *
 * @return  A user principal representing the owner of the file
 *
 * @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#checkRead(String) checkRead} method
 *          denies read access to the file.
 */
public static UserPrincipal getOwner(Path path, LinkOption... options) throws IOException {
    FileOwnerAttributeView view =
        getFileAttributeView(path, FileOwnerAttributeView.class, options);
    if (view == null)
        throw new UnsupportedOperationException();
    return view.getOwner();
}
 
源代码23 项目: jdk8u60   文件: Files.java
/**
 * 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;
}
 
源代码24 项目: JDKSourceCode1.8   文件: Files.java
/**
 * Returns the owner of a file.
 *
 * <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.
 *
 * @param   path
 *          The path to the file
 * @param   options
 *          options indicating how symbolic links are handled
 *
 * @return  A user principal representing the owner of the file
 *
 * @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#checkRead(String) checkRead} method
 *          denies read access to the file.
 */
public static UserPrincipal getOwner(Path path, LinkOption... options) throws IOException {
    FileOwnerAttributeView view =
        getFileAttributeView(path, FileOwnerAttributeView.class, options);
    if (view == null)
        throw new UnsupportedOperationException();
    return view.getOwner();
}
 
源代码25 项目: JDKSourceCode1.8   文件: Files.java
/**
 * 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;
}
 
源代码26 项目: openjdk-jdk8u   文件: Files.java
/**
 * Returns the owner of a file.
 *
 * <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.
 *
 * @param   path
 *          The path to the file
 * @param   options
 *          options indicating how symbolic links are handled
 *
 * @return  A user principal representing the owner of the file
 *
 * @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#checkRead(String) checkRead} method
 *          denies read access to the file.
 */
public static UserPrincipal getOwner(Path path, LinkOption... options) throws IOException {
    FileOwnerAttributeView view =
        getFileAttributeView(path, FileOwnerAttributeView.class, options);
    if (view == null)
        throw new UnsupportedOperationException();
    return view.getOwner();
}
 
源代码27 项目: openjdk-jdk8u   文件: Files.java
/**
 * 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;
}
 
源代码28 项目: openjdk-jdk8u-backup   文件: Files.java
/**
 * Returns the owner of a file.
 *
 * <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.
 *
 * @param   path
 *          The path to the file
 * @param   options
 *          options indicating how symbolic links are handled
 *
 * @return  A user principal representing the owner of the file
 *
 * @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#checkRead(String) checkRead} method
 *          denies read access to the file.
 */
public static UserPrincipal getOwner(Path path, LinkOption... options) throws IOException {
    FileOwnerAttributeView view =
        getFileAttributeView(path, FileOwnerAttributeView.class, options);
    if (view == null)
        throw new UnsupportedOperationException();
    return view.getOwner();
}
 
源代码29 项目: openjdk-jdk8u-backup   文件: Files.java
/**
 * 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;
}
 
源代码30 项目: Bytecoder   文件: Files.java
/**
 * Returns the owner of a file.
 *
 * <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.
 *
 * @param   path
 *          The path to the file
 * @param   options
 *          options indicating how symbolic links are handled
 *
 * @return  A user principal representing the owner of the file
 *
 * @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#checkRead(String) checkRead} method
 *          denies read access to the file.
 */
public static UserPrincipal getOwner(Path path, LinkOption... options) throws IOException {
    FileOwnerAttributeView view =
        getFileAttributeView(path, FileOwnerAttributeView.class, options);
    if (view == null)
        throw new UnsupportedOperationException();
    return view.getOwner();
}
 
 类所在包
 同包方法