Java Code Examples for org.apache.commons.text.StringEscapeUtils#escapeJava()
The following examples show how to use
org.apache.commons.text.StringEscapeUtils#escapeJava() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ASTComparison.java From LoggerPlusPlus with GNU Affero General Public License v3.0 | 6 votes |
private String convertObjectToString(Object obj){ if(obj instanceof Pattern){ if(booleanOperator == BooleanOperator.MATCHES) return "\"" + obj + "\""; else return "/" + obj + "/"; }else if(obj instanceof String){ return "\"" + StringEscapeUtils.escapeJava((String) obj) + "\""; }else if(obj instanceof Set){ StringBuilder sb = new StringBuilder(); sb.append("["); sb.append(((Set) obj).stream().map(item -> { if(item instanceof String) return "\"" + item + "\""; else return String.valueOf(item); }).collect(Collectors.joining(", "))); sb.append("]"); return sb.toString(); }else if(obj instanceof Date){ return "\"" + LogProcessor.LOGGER_DATE_FORMAT.format(obj) + "\""; } return String.valueOf(obj); }
Example 2
Source File: GenericJsonBodyThen.java From spring-cloud-contract with Apache License 2.0 | 6 votes |
@Override public MethodVisitor<Then> apply(SingleContractMetadata metadata) { BodyMatchers bodyMatchers = this.bodyParser.responseBodyMatchers(metadata); Object convertedResponseBody = this.bodyParser.convertResponseBody(metadata); ContentType contentType = metadata.getOutputTestContentType(); if (TEXT != contentType && FORM != contentType && DEFINED != contentType) { boolean dontParseStrings = contentType == JSON && convertedResponseBody instanceof Map; Function parsingClosure = dontParseStrings ? Function.identity() : MapConverter.JSON_PARSING_FUNCTION; convertedResponseBody = MapConverter.getTestSideValues(convertedResponseBody, parsingClosure); } else { convertedResponseBody = StringEscapeUtils .escapeJava(convertedResponseBody.toString()); } addJsonBodyVerification(metadata, convertedResponseBody, bodyMatchers); return this; }
Example 3
Source File: RegexProperty.java From spring-cloud-contract with Apache License 2.0 | 5 votes |
public Object generateAndEscapeJavaStringIfNeeded() { Object generated = generate(); if (isNumber()) { return generated; } return StringEscapeUtils.escapeJava(String.valueOf(generated)); }
Example 4
Source File: ComparisonBuilder.java From spring-cloud-contract with Apache License 2.0 | 4 votes |
default String matches(Pattern pattern) { String escapedPattern = StringEscapeUtils.escapeJava(pattern.pattern()); return ".matches(" + bodyParser().quotedEscapedShortText(escapedPattern) + ")"; }
Example 5
Source File: CommonsEntityProvider.java From sakai with Educational Community License v2.0 | 4 votes |
private String escape(String unescaped) { return StringEscapeUtils.escapeJava(unescaped); }
Example 6
Source File: CommonsEntityProvider.java From sakai with Educational Community License v2.0 | 4 votes |
private String escape(String unescaped) { return StringEscapeUtils.escapeJava(unescaped); }
Example 7
Source File: TextParser.java From skywalking with Apache License 2.0 | 4 votes |
private boolean parseLine(String line, Context ctx) { if (line.isEmpty()) { return false; } if (line.charAt(0) == '#') { String[] parts = line.split("[ \t]+", 4); if (parts.length < 3) { return false; } if (parts[1].equals("HELP")) { if (!parts[2].equals(ctx.name)) { if (!ctx.name.isEmpty()) { this.lastLineReadFromStream = line; return true; } ctx.clear(); ctx.name = parts[2]; ctx.type = MetricType.GAUGE; ctx.allowedNames.add(parts[2]); } if (parts.length == 4) { ctx.help = StringEscapeUtils.escapeJava(parts[3]); } } else if (parts[1].equals("TYPE")) { if (!parts[2].equals(ctx.name)) { if (!ctx.name.isEmpty()) { this.lastLineReadFromStream = line; return true; } ctx.clear(); ctx.name = parts[2]; } ctx.addAllowedNames(parts[3]); } return false; } TextSample sample = TextSample.parse(line); if (!ctx.allowedNames.contains(sample.getName())) { if (!ctx.name.isEmpty()) { this.lastLineReadFromStream = line; return true; } ctx.clear(); LOG.debug("Ignoring an unexpected metric: {}", line); } else { ctx.samples.add(sample); } return false; }
Example 8
Source File: Field.java From vespa with Apache License 2.0 | 4 votes |
private Query common(String relation, Annotation annotation, String value, String[] others) { Object v = "\"" + StringEscapeUtils.escapeJava(value) + "\""; Object[] o = Stream.of(others).map(s -> "\"" + StringEscapeUtils.escapeJava(s) + "\"").toArray(); return common(relation, annotation, v, o); }
Example 9
Source File: Field.java From vespa with Apache License 2.0 | 4 votes |
private Query common(String relation, Annotation annotation, String value) { Object v = "\"" + StringEscapeUtils.escapeJava(value) + "\""; return common(relation, annotation, v, values.toArray()); }
Example 10
Source File: GroovyComparisonBuilder.java From spring-cloud-contract with Apache License 2.0 | 4 votes |
@Override default String matches(Pattern pattern) { String escapedPattern = StringEscapeUtils.escapeJava(pattern.pattern()); return matchesEscaped(escapedPattern); }
Example 11
Source File: BesuCommandTest.java From besu with Apache License 2.0 | 4 votes |
private static String escapeTomlString(final String s) { return StringEscapeUtils.escapeJava(s); }
Example 12
Source File: BodyMethodGeneration.java From spring-cloud-contract with Apache License 2.0 | 4 votes |
default String quotedAndEscaped(String string) { return '"' + StringEscapeUtils.escapeJava(string) + '"'; }
Example 13
Source File: TestSideRequestTemplateModel.java From spring-cloud-contract with Apache License 2.0 | 4 votes |
private static String trimmedAndEscapedBody(Object body) { String rawBody = getBodyAsRawJson(body); return StringEscapeUtils.escapeJava(rawBody); }
Example 14
Source File: ContentHelper.java From spring-cloud-contract with Apache License 2.0 | 4 votes |
private static String quotedAndEscaped(String string) { return '"' + StringEscapeUtils.escapeJava(string) + '"'; }
Example 15
Source File: BodyParser.java From spring-cloud-contract with Apache License 2.0 | 4 votes |
default String escape(String text) { return StringEscapeUtils.escapeJava(text); }
Example 16
Source File: StaticUtil.java From sailfish-core with Apache License 2.0 | 4 votes |
public static IFilter regexFilter(long line, String column, String condition, Object... args) { return new RegexMvelFilter(line, column, StringEscapeUtils.escapeJava(condition), toMap(args)); }
Example 17
Source File: Encoder.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Escaped the given JSON content using Java String rules. * * Assumes " is used as quote char and not used inside values and does * not escape '. * * @param object the String. * @return the escaped representation. */ public String jsonEncode( String object ) { return StringEscapeUtils.escapeJava( object ); }
Example 18
Source File: StringUtility.java From jstarcraft-core with Apache License 2.0 | 2 votes |
/** * 对字符串执行Java加密 * * @param string * @return */ public static final String escapeJava(String string) { return StringEscapeUtils.escapeJava(string); }
Example 19
Source File: StringUtils.java From Rel with Apache License 2.0 | votes |
/** Quote the given string by replacing unprintable characters by escape sequences. @param s the string to be quoted. @return a quoted string. */ public static String quote(String s) { return StringEscapeUtils.escapeJava(s); }