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

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

本文整理了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

  1. public static void setEnvFromInputString(Map<String, String> env,
  2. String envString, String classPathSeparator) {
  3. if (envString != null && envString.length() > 0) {
  4. String childEnvs[] = envString.split(",");
  5. Pattern p = Pattern.compile(Shell.getEnvironmentVariableRegex());
  6. for (String cEnv : childEnvs) {
  7. String[] parts = cEnv.split("="); // split on '='
  8. Matcher m = p.matcher(parts[1]);
  9. StringBuffer sb = new StringBuffer();
  10. while (m.find()) {
  11. String var = m.group(1);
  12. // replace $env with the child's env constructed by tt's
  13. String replace = env.get(var);
  14. // if this key is not configured by the tt for the child .. get it
  15. // from the tt's env
  16. if (replace == null)
  17. replace = System.getenv(var);
  18. // the env key is note present anywhere .. simply set it
  19. if (replace == null)
  20. replace = "";
  21. m.appendReplacement(sb, Matcher.quoteReplacement(replace));
  22. }
  23. m.appendTail(sb);
  24. addToEnvironment(env, parts[0], sb.toString(), classPathSeparator);
  25. }
  26. }
  27. }

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

  1. public static void setEnvFromInputString(Map<String, String> env,
  2. String envString, String classPathSeparator) {
  3. if (envString != null && envString.length() > 0) {
  4. String childEnvs[] = envString.split(",");
  5. Pattern p = Pattern.compile(Shell.getEnvironmentVariableRegex());
  6. for (String cEnv : childEnvs) {
  7. String[] parts = cEnv.split("="); // split on '='
  8. Matcher m = p.matcher(parts[1]);
  9. StringBuffer sb = new StringBuffer();
  10. while (m.find()) {
  11. String var = m.group(1);
  12. // replace $env with the child's env constructed by tt's
  13. String replace = env.get(var);
  14. // if this key is not configured by the tt for the child .. get it
  15. // from the tt's env
  16. if (replace == null)
  17. replace = System.getenv(var);
  18. // the env key is note present anywhere .. simply set it
  19. if (replace == null)
  20. replace = "";
  21. m.appendReplacement(sb, Matcher.quoteReplacement(replace));
  22. }
  23. m.appendTail(sb);
  24. addToEnvironment(env, parts[0], sb.toString(), classPathSeparator);
  25. }
  26. }
  27. }

相关文章