當前位置: 首頁>>代碼示例>>Java>>正文


Java PosixFileAttributeView.setGroup方法代碼示例

本文整理匯總了Java中java.nio.file.attribute.PosixFileAttributeView.setGroup方法的典型用法代碼示例。如果您正苦於以下問題:Java PosixFileAttributeView.setGroup方法的具體用法?Java PosixFileAttributeView.setGroup怎麽用?Java PosixFileAttributeView.setGroup使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.nio.file.attribute.PosixFileAttributeView的用法示例。


在下文中一共展示了PosixFileAttributeView.setGroup方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: chown

import java.nio.file.attribute.PosixFileAttributeView; //導入方法依賴的package包/類
@Override
 public void chown(String path, String username, String groupname) throws IOException {
java.nio.file.Path p = FileSystems.getDefault().getPath(path);
PosixFileAttributeView view = Files.getFileAttributeView(p, PosixFileAttributeView.class);
UserPrincipalLookupService service = p.getFileSystem().getUserPrincipalLookupService();
if(!StringUtils.isBlank(username)) {
	view.setOwner(service.lookupPrincipalByName(username));
}
if(!StringUtils.isBlank(groupname)) {
	view.setGroup(service.lookupPrincipalByGroupName(groupname));
}
 }
 
開發者ID:intel-hpdd,項目名稱:lustre-connector-for-hadoop,代碼行數:13,代碼來源:LustreFsJavaImpl.java

示例2: changeGroup

import java.nio.file.attribute.PosixFileAttributeView; //導入方法依賴的package包/類
public static void changeGroup(Path path, String groupName) throws IOException {
    FileSystem fileSystem = FileSystems.getDefault();
    PosixFileAttributeView fileAttributeView = Files.getFileAttributeView(path, PosixFileAttributeView.class);

    if (!fileSystem.provider().getFileStore(path).supportsFileAttributeView(fileAttributeView.name())) {
        throw new UnsupportedOperationException("Not on posix");
    }

    fileAttributeView.setGroup(fileSystem.getUserPrincipalLookupService().lookupPrincipalByGroupName(groupName));
}
 
開發者ID:Sewatech,項目名稱:swutils,代碼行數:11,代碼來源:PosixFiles.java

示例3: chown

import java.nio.file.attribute.PosixFileAttributeView; //導入方法依賴的package包/類
/**
 * @param localFile the local file to use chown on
 * @param owner the file owner to set
 * @param group the file group to set
 * @throws IOException if chown couldn't be edited
 */
public static void chown(File localFile, String owner, String group) throws IOException {
	PosixFileAttributeView view = FileHelper.getFileAttributes(localFile);
	UserPrincipalLookupService lookupService = FileSystems.getDefault().getUserPrincipalLookupService();
	UserPrincipal fileOwner = lookupService.lookupPrincipalByName(owner);
	GroupPrincipal fileGroup = lookupService.lookupPrincipalByGroupName(group);
	view.setOwner(fileOwner);
	view.setGroup(fileGroup);
}
 
開發者ID:cinovo,項目名稱:cloudconductor-agent-redhat,代碼行數:15,代碼來源:FileHelper.java

示例4: testView

import java.nio.file.attribute.PosixFileAttributeView; //導入方法依賴的package包/類
@Test
public void testView() throws IOException {
  file.setAttribute("owner", "owner", createUserPrincipal("user"));

  PosixFileAttributeView view =
      provider.view(
          fileLookup(),
          ImmutableMap.of(
              "basic", new BasicAttributeProvider().view(fileLookup(), NO_INHERITED_VIEWS),
              "owner", new OwnerAttributeProvider().view(fileLookup(), NO_INHERITED_VIEWS)));
  assertNotNull(view);

  assertThat(view.name()).isEqualTo("posix");
  assertThat(view.getOwner()).isEqualTo(createUserPrincipal("user"));

  PosixFileAttributes attrs = view.readAttributes();
  assertThat(attrs.fileKey()).isEqualTo(0);
  assertThat(attrs.owner()).isEqualTo(createUserPrincipal("user"));
  assertThat(attrs.group()).isEqualTo(createGroupPrincipal("group"));
  assertThat(attrs.permissions()).isEqualTo(PosixFilePermissions.fromString("rw-r--r--"));

  view.setOwner(createUserPrincipal("root"));
  assertThat(view.getOwner()).isEqualTo(createUserPrincipal("root"));
  assertThat(file.getAttribute("owner", "owner")).isEqualTo(createUserPrincipal("root"));

  view.setGroup(createGroupPrincipal("root"));
  assertThat(view.readAttributes().group()).isEqualTo(createGroupPrincipal("root"));
  assertThat(file.getAttribute("posix", "group")).isEqualTo(createGroupPrincipal("root"));

  view.setPermissions(PosixFilePermissions.fromString("rwx------"));
  assertThat(view.readAttributes().permissions())
      .isEqualTo(PosixFilePermissions.fromString("rwx------"));
  assertThat(file.getAttribute("posix", "permissions"))
      .isEqualTo(PosixFilePermissions.fromString("rwx------"));
}
 
開發者ID:google,項目名稱:jimfs,代碼行數:36,代碼來源:PosixAttributeProviderTest.java

示例5: setFileGroup

import java.nio.file.attribute.PosixFileAttributeView; //導入方法依賴的package包/類
@Override
public void setFileGroup(String path, String group) throws KMRuntimeException {
    try {
        Path jpath = new File(path).toPath();
        PosixFileAttributeView view = Files.getFileAttributeView(jpath, PosixFileAttributeView.class);
        UserPrincipalLookupService lookupService = FileSystems.getDefault().getUserPrincipalLookupService();
        view.setGroup(lookupService.lookupPrincipalByGroupName(group));
    } catch (IOException e) {
        throw new KMRuntimeException(e.getMessage(), e);
    }
}
 
開發者ID:Kloudtek,項目名稱:kloudmake,代碼行數:12,代碼來源:LocalHost.java

示例6: defineFilePosixAttributeView

import java.nio.file.attribute.PosixFileAttributeView; //導入方法依賴的package包/類
/**
 * Define file posix attribute view on a path/file.
 *
 * @param path Target path
 * @param filePermissions Permissions to apply
 * @param fileOwner File owner
 * @param fileGroup File group
 * @throws IOException If IO error during definition of file attribute view
 */
public static void defineFilePosixAttributeView(final Path path,
        final Set<PosixFilePermission> filePermissions,
        final String fileOwner,
        final String fileGroup) throws IOException {
    final PosixFileAttributeView view = Files.getFileAttributeView(path, PosixFileAttributeView.class);
    if (view != null) {
        final UserPrincipalLookupService lookupService = FileSystems.getDefault()
                .getUserPrincipalLookupService();
        if (fileOwner != null) {
            final UserPrincipal userPrincipal = lookupService.lookupPrincipalByName(fileOwner);
            if (userPrincipal != null) {
                // If not sudoers member, it will throw Operation not permitted
                // Only processes with an effective user ID equal to the user ID
                // of the file or with appropriate privileges may change the ownership of a file.
                // If _POSIX_CHOWN_RESTRICTED is in effect for path
                view.setOwner(userPrincipal);
            }
        }
        if (fileGroup != null) {
            final GroupPrincipal groupPrincipal = lookupService.lookupPrincipalByGroupName(fileGroup);
            if (groupPrincipal != null) {
                // The current user id should be members of this group,
                // if not will raise Operation not permitted
                view.setGroup(groupPrincipal);
            }
        }
        if (filePermissions != null) {
            view.setPermissions(filePermissions);
        }
    }
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:41,代碼來源:FileUtils.java


注:本文中的java.nio.file.attribute.PosixFileAttributeView.setGroup方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。