本文整理了Java中org.apache.commons.text.StringEscapeUtils.escapeJava()
方法的一些代码示例,展示了StringEscapeUtils.escapeJava()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringEscapeUtils.escapeJava()
方法的具体详情如下:
包路径:org.apache.commons.text.StringEscapeUtils
类名称:StringEscapeUtils
方法名:escapeJava
暂无
代码示例来源:origin: jamesdbloom/mockserver
public static String serializeNottableString(NottableString nottableString) {
if (nottableString.isNot()) {
return "not(\"" + StringEscapeUtils.escapeJava(nottableString.getValue()) + "\")";
} else {
return "\"" + StringEscapeUtils.escapeJava(nottableString.getValue()) + "\"";
}
}
}
代码示例来源:origin: jamesdbloom/mockserver
@Override
public String serialize(int numberOfSpacesToIndent, HttpTemplate httpTemplate) {
StringBuffer output = new StringBuffer();
if (httpTemplate != null) {
appendNewLineAndIndent(numberOfSpacesToIndent * INDENT_SIZE, output).append("template(HttpTemplate.TemplateType." + httpTemplate.getTemplateType().name() + ")");
if (!Strings.isNullOrEmpty(httpTemplate.getTemplate())) {
appendNewLineAndIndent((numberOfSpacesToIndent + 1) * INDENT_SIZE, output).append(".withTemplate(\"").append(StringEscapeUtils.escapeJava(httpTemplate.getTemplate())).append("\")");
}
if (httpTemplate.getDelay() != null) {
appendNewLineAndIndent((numberOfSpacesToIndent + 1) * INDENT_SIZE, output).append(".withDelay(").append(new DelayToJavaSerializer().serialize(0, httpTemplate.getDelay())).append(")");
}
}
return output.toString();
}
代码示例来源:origin: neo4j/neo4j
append( "\"" ).append( StringEscapeUtils.escapeJava( (String) value ) ).append( '"' );
代码示例来源:origin: neo4j/neo4j
if ( message != null )
builder.append( '\'' ).append( escapeJava( message ) ).append( '\'' );
builder.append( escapeJava( "" + arg ) );
if ( throwable != null )
builder.append( '\'' ).append( escapeJava( throwable.toString() ) ).append( '\'' );
代码示例来源:origin: jamesdbloom/mockserver
appendNewLineAndIndent((numberOfSpacesToIndent + 1) * INDENT_SIZE, output).append(".withReasonPhrase(\"").append(StringEscapeUtils.escapeJava(httpResponse.getReasonPhrase())).append("\")");
output.append(".withBody(new Base64Converter().base64StringToBytes(\"").append(base64Converter.bytesToBase64String(body.getRawBytes())).append("\"))");
} else {
appendNewLineAndIndent((numberOfSpacesToIndent + 1) * INDENT_SIZE, output).append(".withBody(\"").append(StringEscapeUtils.escapeJava(httpResponse.getBodyAsString())).append("\")");
代码示例来源:origin: jamesdbloom/mockserver
output.append(".withBody(");
JsonBody jsonBody = (JsonBody) request.getBody();
output.append("new JsonBody(\"").append(StringEscapeUtils.escapeJava(jsonBody.getValue())).append("\", JsonBodyMatchType.").append(jsonBody.getMatchType()).append(")");
output.append(")");
} else if (request.getBody() instanceof JsonPathBody) {
output.append(".withBody(");
JsonPathBody jsonPathBody = (JsonPathBody) request.getBody();
output.append("new JsonPathBody(\"").append(StringEscapeUtils.escapeJava(jsonPathBody.getValue())).append("\")");
output.append(")");
} else if (request.getBody() instanceof JsonSchemaBody) {
output.append(".withBody(");
JsonSchemaBody jsonSchemaBody = (JsonSchemaBody) request.getBody();
output.append("new JsonSchemaBody(\"").append(StringEscapeUtils.escapeJava(jsonSchemaBody.getValue())).append("\")");
output.append(")");
} else if (request.getBody() instanceof XmlBody) {
output.append(".withBody(");
XmlBody xmlBody = (XmlBody) request.getBody();
output.append("new XmlBody(\"").append(StringEscapeUtils.escapeJava(xmlBody.getValue())).append("\")");
output.append(")");
} else if (request.getBody() instanceof XPathBody) {
output.append(".withBody(");
XPathBody xPathBody = (XPathBody) request.getBody();
output.append("new XPathBody(\"").append(StringEscapeUtils.escapeJava(xPathBody.getValue())).append("\")");
output.append(")");
} else if (request.getBody() instanceof XmlSchemaBody) {
代码示例来源:origin: lenskit/lenskit
@Override
public DescriptionWriter putField(String name, String value) {
builder.append(getIndent())
.append(name)
.append(": ")
.append(StringEscapeUtils.escapeJava(value))
.append('\n');
return this;
}
代码示例来源:origin: lenskit/lenskit
public ComponentNodeBuilder addParameter(Annotation param, Object value) {
StringBuilder lbl = new StringBuilder();
lbl.append(shortAnnotation(param))
.append(": ");
if (value instanceof String) {
lbl.append('"')
.append(escapeJava(value.toString()))
.append('"');
} else {
lbl.append(value);
}
parameters.add(lbl.toString());
return this;
}
代码示例来源:origin: org.apache.hadoop/hadoop-hdfs
(auditLog.isInfoEnabled() && !debugCmdSet.contains(cmd))) {
final StringBuilder sb = STRING_BUILDER.get();
src = escapeJava(src);
dst = escapeJava(dst);
sb.setLength(0);
sb.append("allowed=").append(succeeded).append("\t");
代码示例来源:origin: org.apache.commons/commons-text
private void assertUnescapeJava(final String unescaped, final String original, final String message)
throws IOException {
final String expected = unescaped;
final String actual = StringEscapeUtils.unescapeJava(original);
assertEquals(expected, actual, "unescape(String) failed"
+ (message == null ? "" : (": " + message))
+ ": expected '" + StringEscapeUtils.escapeJava(expected)
// we escape this so we can see it in the error message
+ "' actual '" + StringEscapeUtils.escapeJava(actual) + "'");
final StringWriter writer = new StringWriter();
StringEscapeUtils.UNESCAPE_JAVA.translate(original, writer);
assertEquals(unescaped, writer.toString());
}
代码示例来源:origin: org.apache.commons/commons-text
private void assertEscapeJava(final String expected, final String original, String message) throws IOException {
final String converted = StringEscapeUtils.escapeJava(original);
message = "escapeJava(String) failed" + (message == null ? "" : (": " + message));
assertEquals(expected, converted, message);
final StringWriter writer = new StringWriter();
StringEscapeUtils.ESCAPE_JAVA.translate(original, writer);
assertEquals(expected, writer.toString());
}
代码示例来源:origin: org.apache.commons/commons-text
/**
* Tests https://issues.apache.org/jira/browse/LANG-421
*/
@Test
public void testEscapeJavaWithSlash() {
final String input = "String with a slash (/) in it";
final String expected = input;
final String actual = StringEscapeUtils.escapeJava(input);
/**
* In 2.4 StringEscapeUtils.escapeJava(String) escapes '/' characters, which are not a valid character
* to escape in a Java string.
*/
assertEquals(expected, actual);
}
代码示例来源:origin: org.apache.commons/commons-text
/**
* Tests https://issues.apache.org/jira/browse/LANG-911
*/
@Test
public void testLang911() {
final String bellsTest = "\ud83d\udc80\ud83d\udd14";
final String value = StringEscapeUtils.escapeJava(bellsTest);
final String valueTest = StringEscapeUtils.unescapeJava(value);
assertEquals(bellsTest, valueTest);
}
代码示例来源:origin: pwm-project/pwm
public static String escapeJava( final String input )
{
return StringEscapeUtils.escapeJava( input );
}
代码示例来源:origin: vmi/selenese-runner-java
@Override
public String toString() {
return "SeleniumPattern[" + type + ":" + StringEscapeUtils.escapeJava(stringPattern) + "]";
}
}
代码示例来源:origin: org.jgrapht/jgrapht-io
private String quoted(final String s)
{
boolean escapeStringAsJava = parameters.contains(Parameter.ESCAPE_STRINGS_AS_JAVA);
if (escapeStringAsJava) {
return "\"" + StringEscapeUtils.escapeJava(s) + "\"";
} else {
return "\"" + s + "\"";
}
}
代码示例来源:origin: org.apache.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: com.github.mike10004/virtual-har-server-har-bridge
@Nullable
private static String quote(@Nullable Object value) {
if (value == null) {
return null;
}
return String.format("\"%s\"", StringEscapeUtils.escapeJava(StringUtils.abbreviateMiddle(value.toString(), "[...]", 64)));
}
}
代码示例来源:origin: org.mock-server/mockserver-core
public static String serializeNottableString(NottableString nottableString) {
if (nottableString.isNot()) {
return "not(\"" + StringEscapeUtils.escapeJava(nottableString.getValue()) + "\")";
} else {
return "\"" + StringEscapeUtils.escapeJava(nottableString.getValue()) + "\"";
}
}
}
代码示例来源:origin: org.apache.commons/commons-text
@Test
public void testEscapeJava() throws IOException {
assertNull(StringEscapeUtils.escapeJava(null));
try {
StringEscapeUtils.ESCAPE_JAVA.translate(null, null);
内容来源于网络,如有侵权,请联系作者删除!