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


Java Shell.TOKEN_SEPARATOR_REGEX屬性代碼示例

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


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

示例1: stashOriginalFilePermissions

@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,代碼行數:23,代碼來源:LocalJavaKeyStoreProvider.java

示例2: parsePartialGroupNames

/**
 * Attempt to parse group names given that some names are not resolvable.
 * Use the group id list to identify those that are not resolved.
 *
 * @param groupNames a string representing a list of group names
 * @param groupIDs a string representing a list of group ids
 * @return a linked list of group names
 * @throws PartialGroupNameException
 */
private List<String> parsePartialGroupNames(String groupNames,
    String groupIDs) throws PartialGroupNameException {
  StringTokenizer nameTokenizer =
      new StringTokenizer(groupNames, Shell.TOKEN_SEPARATOR_REGEX);
  StringTokenizer idTokenizer =
      new StringTokenizer(groupIDs, Shell.TOKEN_SEPARATOR_REGEX);
  List<String> groups = new LinkedList<String>();
  while (nameTokenizer.hasMoreTokens()) {
    // check for unresolvable group names.
    if (!idTokenizer.hasMoreTokens()) {
      throw new PartialGroupNameException("Number of group names and ids do"
      + " not match. group name =" + groupNames + ", group id = " + groupIDs);
    }
    String groupName = nameTokenizer.nextToken();
    String groupID = idTokenizer.nextToken();
    if (!StringUtils.isNumeric(groupName) ||
        !groupName.equals(groupID)) {
      // if the group name is non-numeric, it is resolved.
      // if the group name is numeric, but is not the same as group id,
      // regard it as a group name.
      // if unfortunately, some group names are not resolvable, and
      // the group name is the same as the group id, regard it as not
      // resolved.
      groups.add(groupName);
    }
  }
  return groups;
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:37,代碼來源:ShellBasedUnixGroupsMapping.java

示例3: resolveFullGroupNames

/**
 * Split group names into a linked list.
 *
 * @param groupNames a string representing the user's group names
 * @return a linked list of group names
 */
private List<String> resolveFullGroupNames(String groupNames) {
  StringTokenizer tokenizer =
      new StringTokenizer(groupNames, Shell.TOKEN_SEPARATOR_REGEX);
  List<String> groups = new LinkedList<String>();
  while (tokenizer.hasMoreTokens()) {
    groups.add(tokenizer.nextToken());
  }

  return groups;
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:16,代碼來源:ShellBasedUnixGroupsMapping.java

示例4: getUnixGroups

/** 
 * Get the current user's group list from Unix by running the command 'groups'
 * NOTE. For non-existing user it will return EMPTY list
 * @param user user name
 * @return the groups list that the <code>user</code> belongs to. The primary
 *         group is returned first.
 * @throws IOException if encounter any error when running the command
 */
private static List<String> getUnixGroups(final String user) throws IOException {
  String result = "";
  try {
    result = Shell.execCommand(Shell.getGroupsForUserCommand(user));
  } catch (ExitCodeException e) {
    // if we didn't get the group - just return empty list;
    LOG.warn("got exception trying to get groups for user " + user + ": "
        + e.getMessage());
    return new LinkedList<String>();
  }
  
  StringTokenizer tokenizer =
      new StringTokenizer(result, Shell.TOKEN_SEPARATOR_REGEX);
  List<String> groups = new LinkedList<String>();
  while (tokenizer.hasMoreTokens()) {
    groups.add(tokenizer.nextToken());
  }

  // remove duplicated primary group
  if (!Shell.WINDOWS) {
    for (int i = 1; i < groups.size(); i++) {
      if (groups.get(i).equals(groups.get(0))) {
        groups.remove(i);
        break;
      }
    }
  }

  return groups;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:38,代碼來源:ShellBasedUnixGroupsMapping.java


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