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


Java PosixFilePermissions.fromString方法代码示例

本文整理汇总了Java中java.nio.file.attribute.PosixFilePermissions.fromString方法的典型用法代码示例。如果您正苦于以下问题:Java PosixFilePermissions.fromString方法的具体用法?Java PosixFilePermissions.fromString怎么用?Java PosixFilePermissions.fromString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.file.attribute.PosixFilePermissions的用法示例。


在下文中一共展示了PosixFilePermissions.fromString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: stashOriginalFilePermissions

import java.nio.file.attribute.PosixFilePermissions; //导入方法依赖的package包/类
@Override
protected void stashOriginalFilePermissions() throws IOException {
  // save off permissions in case we need to
  // rewrite the keystore in flush()
  if (!Shell.WINDOWS) {
    Path path = Paths.get(file.getCanonicalPath());
    permissions = Files.getPosixFilePermissions(path);
  } else {
    // On Windows, the JDK does not support the POSIX file permission APIs.
    // Instead, we can do a winutils call and translate.
    String[] cmd = Shell.getGetPermissionCommand();
    String[] args = new String[cmd.length + 1];
    System.arraycopy(cmd, 0, args, 0, cmd.length);
    args[cmd.length] = file.getCanonicalPath();
    String out = Shell.execCommand(args);
    StringTokenizer t = new StringTokenizer(out, Shell.TOKEN_SEPARATOR_REGEX);
    // The winutils output consists of 10 characters because of the leading
    // directory indicator, i.e. "drwx------".  The JDK parsing method expects
    // a 9-character string, so remove the leading character.
    String permString = t.nextToken().substring(1);
    permissions = PosixFilePermissions.fromString(permString);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:24,代码来源:LocalJavaKeyStoreProvider.java

示例2: createLocalConfigFile

import java.nio.file.attribute.PosixFilePermissions; //导入方法依赖的package包/类
/**
 * Create localconf folder and properties file necessary to run build task in order to check merge integrity.
 * @param branchName
 */
public void createLocalConfigFile(String branchName) throws Exception {
  String branchPath = SvnUtils.TEMP_FOLDER + "/" + branchName;
  //create localconf directory
  String newDirectoryPath = branchPath + "/localconf";
  if ( !Files.exists( Paths.get(newDirectoryPath))) {
    Set<PosixFilePermission> permissions = PosixFilePermissions.fromString("rwxrwxrwx");
    FileAttribute<Set<PosixFilePermission>> fileAttributes = PosixFilePermissions
        .asFileAttribute(permissions);
    Files.createDirectory(Paths.get(newDirectoryPath), fileAttributes);
  }
  //copy properties template
  Files.copy(
      Paths.get(branchPath + "/common/conf/worldnettps.properties.template"),
      Paths.get(newDirectoryPath + "/worldnettps.properties"),
      StandardCopyOption.REPLACE_EXISTING);
  //setting glassfish directory in properties file
  String appServerDir = PropertiesUtil.getString("appserver.dir");
  String sedCommand = String.format(
      "sed -i '/glassfish.dir/c\\glassfish.dir=%s' localconf/worldnettps.properties", appServerDir);
  CommandExecutor.run( sedCommand, branchPath);
  logger.info("worldnettps.properties file has been created in localconf folder.");
}
 
开发者ID:lpavone,项目名称:SVNAutoMerger,代码行数:27,代码来源:Merger.java

示例3: getPosixPerm

import java.nio.file.attribute.PosixFilePermissions; //导入方法依赖的package包/类
/**
 * 获取Posix权限
 */
public static Set<PosixFilePermission> getPosixPerm(int perm) {
  StringBuilder permStr = new StringBuilder();

  permStr.append(uCanRead(perm) ? "r" : "-");
  permStr.append(uCanWrite(perm) ? "w" : "-");
  permStr.append(uCanExec(perm) ? "x" : "-");
  permStr.append(gCanRead(perm) ? "r" : "-");
  permStr.append(gCanWrite(perm) ? "w" : "-");
  permStr.append(gCanExec(perm) ? "x" : "-");
  permStr.append(oCanRead(perm) ? "r" : "-");
  permStr.append(oCanWrite(perm) ? "w" : "-");
  permStr.append(oCanExec(perm) ? "x" : "-");

  return PosixFilePermissions.fromString(permStr.toString());
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:19,代码来源:FilePerm.java

示例4: setFilePerm

import java.nio.file.attribute.PosixFilePermissions; //导入方法依赖的package包/类
/**
 * 设置文件权限。前提:必须支持PosixFileAttributeView.
 */
public static void setFilePerm(File file, String perm) {
  if (filePermSupported()) {
    try {
      Set<PosixFilePermission> perms = PosixFilePermissions.fromString(perm);
      PosixFileAttributes attr = Files.readAttributes(file.toPath(), PosixFileAttributes.class);
      attr.permissions().clear();
      Files.setPosixFilePermissions(file.toPath(), perms);
    } catch (IOException e) {
      throw new IllegalStateException(e);
    }
  }
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:16,代码来源:FilePerm.java

示例5: setupEnvironment

import java.nio.file.attribute.PosixFilePermissions; //导入方法依赖的package包/类
/**
 * creates and grants permission to daemon files directory
 */
private static void setupEnvironment() {
	final File daemonFilePath = new File("/var/run/iofabric");
	if (!daemonFilePath.exists()) {
		try {
			daemonFilePath.mkdirs();

			UserPrincipalLookupService lookupservice = FileSystems.getDefault().getUserPrincipalLookupService();
			final GroupPrincipal group = lookupservice.lookupPrincipalByGroupName("iofabric");
			Files.getFileAttributeView(daemonFilePath.toPath(), PosixFileAttributeView.class,
					LinkOption.NOFOLLOW_LINKS).setGroup(group);
			Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rwxrwx---");
			Files.setPosixFilePermissions(daemonFilePath.toPath(), perms);
		} catch (Exception e) {
		}
	}

}
 
开发者ID:iotracks,项目名称:iofabric,代码行数:21,代码来源:Start.java

示例6: createDir

import java.nio.file.attribute.PosixFilePermissions; //导入方法依赖的package包/类
public void createDir(String dstPath) {

        Path newdir = FileSystems.getDefault().getPath(dstPath);

        boolean pathExists = Files.exists(newdir,
                new LinkOption[]{LinkOption.NOFOLLOW_LINKS});
        if (!pathExists) {
            Set<PosixFilePermission> perms = PosixFilePermissions
                    .fromString("rwxrwxrwx");
            FileAttribute<Set<PosixFilePermission>> attr = PosixFilePermissions
                    .asFileAttribute(perms);
            try {
                if (osName.indexOf("Windows") == -1) {
                    Files.createDirectories(newdir, attr);
                } else {
                    Files.createDirectories(newdir);
                }
            } catch (Exception e) {
                System.err.println(e);

            }
        }
    }
 
开发者ID:hubinix,项目名称:kamike.fast,代码行数:24,代码来源:MiscUtils.java

示例7: build

import java.nio.file.attribute.PosixFilePermissions; //导入方法依赖的package包/类
@Override
public PosixViewAttributeAction build() {
    if (Strings.isEmpty(basePath)) {
        LOGGER.error("Posix file attribute view action not valid because base path is empty.");
        return null;
    }

    if (filePermissions == null && Strings.isEmpty(filePermissionsString)
                && Strings.isEmpty(fileOwner) && Strings.isEmpty(fileGroup)) {
        LOGGER.error("Posix file attribute view not valid because nor permissions, user or group defined.");
        return null;
    }

    if (!FileUtils.isFilePosixAttributeViewSupported()) {
        LOGGER.warn("Posix file attribute view defined but it is not supported by this files system.");
        return null;
    }

    return new PosixViewAttributeAction(basePath, followLinks, maxDepth, pathConditions,
            subst != null ? subst : configuration.getStrSubstitutor(),
            filePermissions != null ? filePermissions :
                        filePermissionsString != null ? PosixFilePermissions.fromString(filePermissionsString) : null,
            fileOwner,
            fileGroup);
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:26,代码来源:PosixViewAttributeAction.java

示例8: resetRepo

import java.nio.file.attribute.PosixFilePermissions; //导入方法依赖的package包/类
private FileMetaData resetRepo(Task task) throws IOException {
    String taskId = task.getTaskId();
    PathUtil.deleteTaskFiles(taskId, false);
    Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rw-r--r--");
    Files.createFile(PathUtil.getDownloadPath(taskId), PosixFilePermissions.asFileAttribute(perms));
    return fileMetaDataService.createMetaData(task);
}
 
开发者ID:alibaba,项目名称:Dragonfly,代码行数:8,代码来源:CacheDetectorImpl.java

示例9: testExtractToReadOnlyDir

import java.nio.file.attribute.PosixFilePermissions; //导入方法依赖的package包/类
public void testExtractToReadOnlyDir() throws IOException {
    Set<PosixFilePermission> perms = PosixFilePermissions.fromString("r-xr--r--");
    FileAttribute<Set<PosixFilePermission>> atts = PosixFilePermissions.asFileAttribute(perms);
    Path tmp = Files.createTempDirectory(Paths.get("."), getClass().getName(), atts);
    jimage("extract", "--dir", tmp.toString(), getImagePath())
            .assertFailure()
            .assertShowsError();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:JImageExtractTest.java

示例10: ensureExists

import java.nio.file.attribute.PosixFilePermissions; //导入方法依赖的package包/类
public static Path ensureExists(Path folder) throws IOException {
    if (folder != null && !Files.exists(folder)) {
        if (isPosixFileSystem()) {
            Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rwxr-xr-x");
            FileAttribute<Set<PosixFilePermission>> attrs = PosixFilePermissions.asFileAttribute(perms);
            folder = Files.createDirectories(folder, attrs);
        } else {
            folder = Files.createDirectories(folder);
        }

    }
    return folder;
}
 
开发者ID:kraftek,项目名称:awsdownload,代码行数:14,代码来源:Utilities.java

示例11: ensurePermissions

import java.nio.file.attribute.PosixFilePermissions; //导入方法依赖的package包/类
public static Path ensurePermissions(Path file) {
    try {
        if (file != null && Files.exists(file)) {
            if (isPosixFileSystem()) {
                Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rwxr-xr-x");
                file = Files.setPosixFilePermissions(file, perms);
            }
        }
    } catch (IOException ex) {
        Logger.getRootLogger().warn("Cannot set permissions for %s", file.toString());
    }
    return file;
}
 
开发者ID:kraftek,项目名称:awsdownload,代码行数:14,代码来源:Utilities.java

示例12: parsePermissions

import java.nio.file.attribute.PosixFilePermissions; //导入方法依赖的package包/类
/**
 * Parses the given permission to a set of {@link PosixFilePermission}.
 *
 * @param permission the permission as passed to the {@link #createNew(String)} or {@link #getOutputStream(String)}
 *                   methods.
 * @return a new set of {@link PosixFilePermission}.
 */
private Set<PosixFilePermission> parsePermissions(String permission) {
  Set<PosixFilePermission> permissions;
  if (permission.length() == 3) {
    permissions = parseNumericPermissions(permission);
  } else if (permission.length() == 9) {
    permissions = PosixFilePermissions.fromString(permission);
  } else {
    throw new IllegalArgumentException("Invalid permission " + permission +
                                         ". Permission should either be a three digit or nine character string.");
  }

  return permissions;
}
 
开发者ID:apache,项目名称:twill,代码行数:21,代码来源:LocalLocation.java

示例13: parseNumericPermissions

import java.nio.file.attribute.PosixFilePermissions; //导入方法依赖的package包/类
/**
 * Parses a three digit UNIX numeric permission representation to a set of {@link PosixFilePermission}.
 */
private Set<PosixFilePermission> parseNumericPermissions(String permission) {
  String posixPermission = "";
  for (int i = 0; i < 3; i++) {
    int digit = permission.charAt(i) - '0';
    if (digit < 0 || digit > 7) {
      throw new IllegalArgumentException("Invalid permission " + permission +
                                           ". Only digits between 0-7 are allowed.");
    }
    posixPermission += ((digit & 4) != 0) ? "r" : "-";
    posixPermission += ((digit & 2) != 0) ? "w" : "-";
    posixPermission += ((digit & 1) != 0) ? "x" : "-";
  }
  return PosixFilePermissions.fromString(posixPermission);
}
 
开发者ID:apache,项目名称:twill,代码行数:18,代码来源:LocalLocation.java

示例14: setPermissions

import java.nio.file.attribute.PosixFilePermissions; //导入方法依赖的package包/类
/**
 * @param permissions Example: "rwxr-x---" means rwx for owner, rx for group,
 *                    and no permissions for others.
 */
public void setPermissions(Path path, String permissions) {
    Set<PosixFilePermission> permissionSet;
    try {
        permissionSet = PosixFilePermissions.fromString(permissions);
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException("Failed to set permissions '" +
                permissions + "' on path " + path, e);
    }

    uncheck(() -> Files.setPosixFilePermissions(path, permissionSet));
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:16,代码来源:FileSystem.java

示例15: resetPosixPermissions

import java.nio.file.attribute.PosixFilePermissions; //导入方法依赖的package包/类
private boolean resetPosixPermissions(Path file, FileState fileState, PosixFileAttributes posixFileAttributes) throws IOException {
    String permissions = PosixFilePermissions.toString(posixFileAttributes.permissions());
    String previousPermissions = getAttribute(fileState, FileAttribute.PosixFilePermissions);
    if (previousPermissions != null && !Objects.equals(permissions, previousPermissions)) {
        Set<PosixFilePermission> permissionSet = PosixFilePermissions.fromString(previousPermissions);
        Files.getFileAttributeView(file, PosixFileAttributeView.class).setPermissions(permissionSet);
        Logger.out.printf("Set permissions: %s \t%s -> %s%n", fileState.getFileName(), permissions, previousPermissions);
        return true;
    }
    return false;
}
 
开发者ID:evrignaud,项目名称:fim,代码行数:12,代码来源:ResetFileAttributesCommand.java


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