Java Code Examples for java.nio.file.attribute.FileOwnerAttributeView#getOwner()

The following examples show how to use java.nio.file.attribute.FileOwnerAttributeView#getOwner() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileDataStoreFactory.java    From google-http-java-client with Apache License 2.0 4 votes vote down vote up
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);
  }
}
 
Example 2
Source File: Files.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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();
}
 
Example 3
Source File: Files.java    From jdk8u-dev-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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();
}
 
Example 4
Source File: Files.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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();
}
 
Example 5
Source File: Files.java    From jdk8u_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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();
}
 
Example 6
Source File: Files.java    From openjdk-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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();
}
 
Example 7
Source File: Files.java    From openjdk-8-source with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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();
}
 
Example 8
Source File: Files.java    From hottub with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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();
}
 
Example 9
Source File: Files.java    From Java8CN with Apache License 2.0 3 votes vote down vote up
/**
 * 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();
}
 
Example 10
Source File: Files.java    From jdk1.8-source-analysis with Apache License 2.0 3 votes vote down vote up
/**
 * 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();
}
 
Example 11
Source File: Files.java    From openjdk-jdk9 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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();
}
 
Example 12
Source File: Files.java    From Bytecoder with Apache License 2.0 3 votes vote down vote up
/**
 * 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();
}
 
Example 13
Source File: Files.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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();
}
 
Example 14
Source File: Files.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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();
}
 
Example 15
Source File: Files.java    From JDKSourceCode1.8 with MIT License 3 votes vote down vote up
/**
 * 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();
}
 
Example 16
Source File: Files.java    From jdk8u60 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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();
}
 
Example 17
Source File: Files.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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();
}
 
Example 18
Source File: Files.java    From dragonwell8_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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();
}