当前位置: 首页>>代码示例>>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;未经允许,请勿转载。