當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。