org.apache.hadoop.util.Shell.getEnvironmentVariableRegex()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(2.3k)|赞(0)|评价(0)|浏览(105)

本文整理了Java中org.apache.hadoop.util.Shell.getEnvironmentVariableRegex()方法的一些代码示例,展示了Shell.getEnvironmentVariableRegex()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Shell.getEnvironmentVariableRegex()方法的具体详情如下:
包路径:org.apache.hadoop.util.Shell
类名称:Shell
方法名:getEnvironmentVariableRegex

Shell.getEnvironmentVariableRegex介绍

[英]Return a regular expression string that match environment variables
[中]返回与环境变量匹配的正则表达式字符串

代码示例

代码示例来源:origin: com.github.jiayuhan-it/hadoop-yarn-common

public static void setEnvFromInputString(Map<String, String> env,
  String envString,  String classPathSeparator) {
 if (envString != null && envString.length() > 0) {
  String childEnvs[] = envString.split(",");
  Pattern p = Pattern.compile(Shell.getEnvironmentVariableRegex());
  for (String cEnv : childEnvs) {
   String[] parts = cEnv.split("="); // split on '='
   Matcher m = p.matcher(parts[1]);
   StringBuffer sb = new StringBuffer();
   while (m.find()) {
    String var = m.group(1);
    // replace $env with the child's env constructed by tt's
    String replace = env.get(var);
    // if this key is not configured by the tt for the child .. get it
    // from the tt's env
    if (replace == null)
     replace = System.getenv(var);
    // the env key is note present anywhere .. simply set it
    if (replace == null)
     replace = "";
    m.appendReplacement(sb, Matcher.quoteReplacement(replace));
   }
   m.appendTail(sb);
   addToEnvironment(env, parts[0], sb.toString(), classPathSeparator);
  }
 }
}

代码示例来源:origin: ch.cern.hadoop/hadoop-yarn-common

public static void setEnvFromInputString(Map<String, String> env,
  String envString,  String classPathSeparator) {
 if (envString != null && envString.length() > 0) {
  String childEnvs[] = envString.split(",");
  Pattern p = Pattern.compile(Shell.getEnvironmentVariableRegex());
  for (String cEnv : childEnvs) {
   String[] parts = cEnv.split("="); // split on '='
   Matcher m = p.matcher(parts[1]);
   StringBuffer sb = new StringBuffer();
   while (m.find()) {
    String var = m.group(1);
    // replace $env with the child's env constructed by tt's
    String replace = env.get(var);
    // if this key is not configured by the tt for the child .. get it
    // from the tt's env
    if (replace == null)
     replace = System.getenv(var);
    // the env key is note present anywhere .. simply set it
    if (replace == null)
     replace = "";
    m.appendReplacement(sb, Matcher.quoteReplacement(replace));
   }
   m.appendTail(sb);
   addToEnvironment(env, parts[0], sb.toString(), classPathSeparator);
  }
 }
}

相关文章

微信公众号

最新文章

更多