org.apache.commons.lang.StringEscapeUtils.escapeJava()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(209)

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

StringEscapeUtils.escapeJava介绍

[英]Escapes the characters in a String using Java String rules to a Writer.

A null string input has no effect.
[中]使用Java字符串规则将String中的字符转义为Writer
null字符串输入无效。

代码示例

代码示例来源:origin: commons-lang/commons-lang

/**
 * <p>Escapes any values it finds into their String form.</p>
 *
 * <p>So a tab becomes the characters <code>'\\'</code> and
 * <code>'t'</code>.</p>
 *
 * <p>As of Lang 2.0, this calls {@link StringEscapeUtils#escapeJava(String)}
 * behind the scenes.
 * </p>
 * @see StringEscapeUtils#escapeJava(java.lang.String)
 * @param str String to escape values in
 * @return String with escaped values
 * @throws NullPointerException if str is <code>null</code>
 * @deprecated Use {@link StringEscapeUtils#escapeJava(String)}
 *             This method will be removed in Commons Lang 3.0
 */
public static String escape(String str) {
  return StringEscapeUtils.escapeJava(str);
}

代码示例来源:origin: apache/drill

/**
 * Display key, value pairs of the parameters. The characters will be escaped
 * including unicode if escapeUnicode is true; otherwise the characters other
 * than unicode will be escaped.
 */
private static void displayAllParameters(Map<String, String> params, StringBuilder tableInfo,
  boolean escapeUnicode, boolean isOutputPadded) {
 List<String> keys = new ArrayList<String>(params.keySet());
 Collections.sort(keys);
 for (String key : keys) {
  tableInfo.append(FIELD_DELIM); // Ensures all params are indented.
  formatOutput(key,
    escapeUnicode ? StringEscapeUtils.escapeJava(params.get(key))
      : HiveStringUtils.escapeJava(params.get(key)),
    tableInfo, isOutputPadded);
 }
}

代码示例来源:origin: apache/hive

/**
 * Display key, value pairs of the parameters. The characters will be escaped
 * including unicode if escapeUnicode is true; otherwise the characters other
 * than unicode will be escaped.
 */
private static void displayAllParameters(Map<String, String> params, StringBuilder tableInfo,
  boolean escapeUnicode, boolean isOutputPadded) {
 List<String> keys = new ArrayList<String>(params.keySet());
 Collections.sort(keys);
 for (String key : keys) {
  String value = params.get(key);
  if (key.equals(StatsSetupConst.NUM_ERASURE_CODED_FILES)) {
   if ("0".equals(value)) {
    continue;
   }
  }
  tableInfo.append(FIELD_DELIM); // Ensures all params are indented.
  formatOutput(key,
    escapeUnicode ? StringEscapeUtils.escapeJava(value)
      : HiveStringUtils.escapeJava(value),
    tableInfo, isOutputPadded);
 }
}

代码示例来源:origin: apache/drill

StringBuilder str = new StringBuilder();
MetaDataFormatUtils.formatOutput(StatsSetupConst.COLUMN_STATS_ACCURATE,
  isFormatted ? StringEscapeUtils.escapeJava(statsState) : HiveStringUtils.escapeJava(statsState),
  str, isOutputPadded);
output = output.concat(str.toString());

代码示例来源:origin: apache/hive

StringBuilder str = new StringBuilder();
MetaDataFormatUtils.formatOutput(StatsSetupConst.COLUMN_STATS_ACCURATE,
  isFormatted ? StringEscapeUtils.escapeJava(statsState) : HiveStringUtils.escapeJava(statsState),
  str, isOutputPadded);
output = output.concat(str.toString());

代码示例来源:origin: org.zaproxy/zap

/**
 * 
 * @param value
 * @param toQuote
 * @return 
 */
@Override
public String getEscapedValue(String value, boolean toQuote) {
  return StringEscapeUtils.escapeJava(value);
}

代码示例来源:origin: com.fluxtion.extension/fluxtion-fu-text-builder

public String getEscapedChar() {
  switch (rawChar) {
    case '\'':
      return "\\'";
  }
  return StringEscapeUtils.escapeJava("" + rawChar);
}

代码示例来源:origin: org.jenkins-ci.plugins/credentials

/**
 * {@inheritDoc}
 */
@Override
public String describe() {
  return String.format("(id == \"%s\")", StringEscapeUtils.escapeJava(id));
}

代码示例来源:origin: org.jenkins-ci.plugins/credentials

/**
 * {@inheritDoc}
 */
@Override
public String describe() {
  return String.format("(username == \"%s\")", StringEscapeUtils.escapeJava(username));
}

代码示例来源:origin: org.gradle/gradle-base-services

/**
 * Escapes the toString() representation of {@code obj} for use in a literal string.
 * This is useful for interpolating variables into script strings, as well as in other situations.
 */
public static String escapeString(Object obj) {
  return obj == null ? null : StringEscapeUtils.escapeJava(obj.toString());
}

代码示例来源:origin: jenkinsci/credentials-plugin

/**
 * {@inheritDoc}
 */
@Override
public String describe() {
  return String.format("(id == \"%s\")", StringEscapeUtils.escapeJava(id));
}

代码示例来源:origin: org.apache.tez/tez-dag

private static String wrapSafeString(String label) {
 if (label.indexOf(',') >= 0) {
  if (label.length()>14) {
   label = label.replaceAll(",", ",\n");
  }
 }
 label = "\"" + StringEscapeUtils.escapeJava(label) + "\"";
 return label;
}

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

private static String wrapSafeString(String label) {
 if (label.indexOf(',') >= 0) {
  if (label.length()>14) {
   label = label.replaceAll(",", ",\n");
  }
 }
 label = "\"" + StringEscapeUtils.escapeJava(label) + "\"";
 return label;
}

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

private static String wrapSafeString(String label) {
 if (label.indexOf(',') >= 0) {
  if (label.length()>14) {
   label = label.replaceAll(",", ",\n");
  }
 }
 label = "\"" + StringEscapeUtils.escapeJava(label) + "\"";
 return label;
}

代码示例来源:origin: intermine/intermine

@Override
  public String formatFooter(String errorMessage, int errorCode) {
    StringBuilder sb = new StringBuilder();
    if (errorCode >= 400) {
      sb.append("\"error\":\"" + escapeJava(errorMessage) + "\"");
      sb.append(",\"statusCode\":" + errorCode);
    }
    sb.append("}");
    return sb.toString();
  }
}

代码示例来源:origin: org.intermine/intermine-jbrowse-endpoint

@Override
  public String formatFooter(String errorMessage, int errorCode) {
    StringBuilder sb = new StringBuilder();
    if (errorCode >= 400) {
      sb.append("\"error\":\"" + escapeJava(errorMessage) + "\"");
      sb.append(",\"statusCode\":" + errorCode);
    }
    sb.append("}");
    return sb.toString();
  }
}

代码示例来源:origin: com.manydesigns/elements

public void writeKeyValue(String key, String value) {
  String rawValue = MessageFormat.format("\"{0}\"",
      StringEscapeUtils.escapeJava(value));
  writeKeyRawValue(key, rawValue);
}

代码示例来源:origin: com.atlassian.jira/jira-api

private String formatFieldValue(Object fieldValue, Long periodOffSet)
{
  if (periodOffSet == null)
  {
    String fieldStr = (String) fieldValue;
    if (fieldStr.startsWith("-"))
    {
      fieldStr = fieldStr.substring(1);
    }
    return StringEscapeUtils.escapeJava(fieldStr);
  }
  return prettyPrint(periodOffSet);
}

代码示例来源:origin: org.marketcetera/core

@Override
public String marshal
  (Message msg)
{
  if (msg==null) {
    return null;
  }
  return StringEscapeUtils.escapeJava(msg.toString());
}

代码示例来源:origin: net.fortytwo.extendo/extendo-brain

public Process execute(EmacsFunction function, String argument) throws InterruptedException, IOException {
    String expr = function.getRequiresArgument()
        ? "(" + function.getName() + " \"" + StringEscapeUtils.escapeJava(argument) + "\")"
        : "(" + function.getName() + ")";
    expr = "(exo-emacsclient-eval (lambda () " + expr + "))";
    Process p = Runtime.getRuntime().exec(new String[]{executable, "-e", expr});
    p.waitFor();
    return p;
  }
};

相关文章