本文整理了Java中org.apache.commons.text.StringEscapeUtils.escapeCsv()
方法的一些代码示例,展示了StringEscapeUtils.escapeCsv()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringEscapeUtils.escapeCsv()
方法的具体详情如下:
包路径:org.apache.commons.text.StringEscapeUtils
类名称:StringEscapeUtils
方法名:escapeCsv
暂无
代码示例来源:origin: jeremylong/DependencyCheck
/**
* Formats text for CSV format. This includes trimming whitespace, replace
* line breaks with spaces, and if necessary quotes the text and/or escapes
* contained quotes.
*
* @param text the text to escape and quote
* @return the escaped and quoted text
*/
public String csv(String text) {
if (text == null || text.isEmpty()) {
return "\"\"";
}
final String str = text.trim().replace("\n", " ");
if (str.length() == 0) {
return "\"\"";
}
return StringEscapeUtils.escapeCsv(str);
}
代码示例来源:origin: neo4j/neo4j
sb.append( escapeCsv( "Process PID" ) ).append( ',' )
.append( escapeCsv( "Process Name" ) ).append( ',' )
.append( escapeCsv( "Process Time" ) ).append( ',' )
.append( escapeCsv( "User" ) ).append( ',' )
.append( escapeCsv( "Virtual Memory" ) ).append( ',' )
.append( escapeCsv( "Physical Memory" ) ).append( ',' )
.append( escapeCsv( "CPU usage" ) ).append( ',' )
.append( escapeCsv( "Start Time" ) ).append( ',' )
.append( escapeCsv( "Priority" ) ).append( ',' )
.append( escapeCsv( "Full command" ) ).append( '\n' );
.append( escapeCsv( processInfo.getName() ) ).append( ',' )
.append( processInfo.getTime() ).append( ',' )
.append( escapeCsv( processInfo.getUser() ) ).append( ',' )
.append( processInfo.getVirtualMemory() ).append( ',' )
.append( processInfo.getPhysicalMemory() ).append( ',' )
.append( processInfo.getStartTime() ).append( ',' )
.append( processInfo.getStartTime() ).append( ',' )
.append( escapeCsv( processInfo.getCommand() ) ).append( '\n' );
代码示例来源:origin: jeremylong/DependencyCheck
/**
* Takes a set of Identifiers, filters them to just CPEs, and formats them
* for display in a CSV.
*
* @param ids the set of identifiers
* @return the formatted list of CPE identifiers
*/
public String csvCpe(Set<Identifier> ids) {
if (ids == null || ids.isEmpty()) {
return "\"\"";
}
boolean addComma = false;
final StringBuilder sb = new StringBuilder();
for (Identifier id : ids) {
if ("cpe".equals(id.getType())) {
if (addComma) {
sb.append(", ");
} else {
addComma = true;
}
sb.append(id.getValue());
}
}
if (sb.length() == 0) {
return "\"\"";
}
return StringEscapeUtils.escapeCsv(sb.toString());
}
代码示例来源:origin: jeremylong/DependencyCheck
/**
* Takes a set of Identifiers, filters them to none CPE, and formats them
* for display in a CSV.
*
* @param ids the set of identifiers
* @return the formatted list of none CPE identifiers
*/
public String csvIdentifiers(Set<Identifier> ids) {
if (ids == null || ids.isEmpty()) {
return "\"\"";
}
boolean addComma = false;
final StringBuilder sb = new StringBuilder();
for (Identifier id : ids) {
if (!"cpe".equals(id.getType())) {
if (addComma) {
sb.append(", ");
} else {
addComma = true;
}
sb.append(id.getValue());
}
}
if (sb.length() == 0) {
return "\"\"";
}
return StringEscapeUtils.escapeCsv(sb.toString());
}
代码示例来源:origin: jeremylong/DependencyCheck
/**
* Takes a set of Identifiers, filters them to just CPEs, and formats them
* for confidence display in a CSV.
*
* @param ids the set of identifiers
* @return the formatted list of confidence
*/
public String csvCpeConfidence(Set<Identifier> ids) {
if (ids == null || ids.isEmpty()) {
return "\"\"";
}
boolean addComma = false;
final StringBuilder sb = new StringBuilder();
for (Identifier id : ids) {
if ("cpe".equals(id.getType())) {
if (addComma) {
sb.append(", ");
} else {
addComma = true;
}
sb.append(id.getConfidence());
}
}
if (sb.length() == 0) {
return "\"\"";
}
return StringEscapeUtils.escapeCsv(sb.toString());
}
代码示例来源:origin: jeremylong/DependencyCheck
/**
* Takes a set of Identifiers, filters them to just GAVs, and formats them
* for display in a CSV.
*
* @param ids the set of identifiers
* @return the formatted list of GAV identifiers
*/
public String csvGav(Set<Identifier> ids) {
if (ids == null || ids.isEmpty()) {
return "\"\"";
}
boolean addComma = false;
final StringBuilder sb = new StringBuilder();
for (Identifier id : ids) {
if ("maven".equals(id.getType()) || "npm".equals(id.getType())) {
if (addComma) {
sb.append(", ");
} else {
addComma = true;
}
sb.append(id.getValue());
}
}
if (sb.length() == 0) {
return "\"\"";
}
return StringEscapeUtils.escapeCsv(sb.toString());
}
}
代码示例来源:origin: apache/nifi
sb.append("\"");
if (outputOptions.isEscape()) {
sb.append(StringEscapeUtils.escapeCsv(valueString));
} else {
sb.append(valueString);
} else {
if (outputOptions.isEscape()) {
rowValues.add(StringEscapeUtils.escapeCsv(valueString));
} else {
rowValues.add(valueString);
String complexValueString = rs.getString(i);
if (complexValueString != null) {
rowValues.add(StringEscapeUtils.escapeCsv(complexValueString));
} else {
rowValues.add("");
case SQLXML:
if (value != null) {
rowValues.add(StringEscapeUtils.escapeCsv(((java.sql.SQLXML) value).getString()));
} else {
rowValues.add("");
代码示例来源:origin: apache/nifi
sb.append("\"");
if (outputOptions.isEscape()) {
sb.append(StringEscapeUtils.escapeCsv(valueString));
} else {
sb.append(valueString);
} else {
if (outputOptions.isEscape()) {
rowValues.add(StringEscapeUtils.escapeCsv(valueString));
} else {
rowValues.add(valueString);
String complexValueString = rs.getString(i);
if (complexValueString != null) {
rowValues.add(StringEscapeUtils.escapeCsv(complexValueString));
} else {
rowValues.add("");
case SQLXML:
if (value != null) {
rowValues.add(StringEscapeUtils.escapeCsv(((java.sql.SQLXML) value).getString()));
} else {
rowValues.add("");
代码示例来源:origin: apache/nifi
final StringBuilder sbValues = new StringBuilder();
for (final Map.Entry<String,String> attr : atrList.entrySet()) {
sbValues.append(StringEscapeUtils.escapeCsv(attr.getValue()));
sbValues.append(index++ < atrListSize ? OUTPUT_SEPARATOR : "");
index = 0;
for (final Map.Entry<String,String> attr : atrList.entrySet()) {
sbNames.append(StringEscapeUtils.escapeCsv(attr.getKey()));
sbNames.append(index++ < atrListSize ? OUTPUT_SEPARATOR : "");
代码示例来源:origin: org.apache.hadoop/hadoop-hdfs
private void append(StringBuffer buffer, String field) {
buffer.append(delimiter);
String escapedField = StringEscapeUtils.escapeCsv(field);
if (escapedField.contains(CRLF)) {
escapedField = escapedField.replace(CRLF, "%x0D%x0A");
} else if (escapedField.contains(StringUtils.LF)) {
escapedField = escapedField.replace(StringUtils.LF, "%x0A");
}
buffer.append(escapedField);
}
代码示例来源:origin: lenskit/lenskit
@Override
public synchronized void writeRow(List<?> row) throws IOException {
Preconditions.checkState(writer != null, "writer has been closed");
if (layout != null) {
checkRowWidth(row.size());
}
boolean first = true;
for (Object val: row) {
if (!first) {
writer.write(',');
}
first = false;
if (val instanceof Number) {
writer.write(val.toString());
} else if (val != null) {
writer.write(escapeCsv(val.toString()));
}
}
writer.newLine();
}
代码示例来源:origin: org.apache.commons/commons-text
@Test
public void testEscapeCsvString() {
assertEquals("foo.bar", StringEscapeUtils.escapeCsv("foo.bar"));
assertEquals("\"foo,bar\"", StringEscapeUtils.escapeCsv("foo,bar"));
assertEquals("\"foo\nbar\"", StringEscapeUtils.escapeCsv("foo\nbar"));
assertEquals("\"foo\rbar\"", StringEscapeUtils.escapeCsv("foo\rbar"));
assertEquals("\"foo\"\"bar\"", StringEscapeUtils.escapeCsv("foo\"bar"));
assertEquals("foo\uD84C\uDFB4bar", StringEscapeUtils.escapeCsv("foo\uD84C\uDFB4bar"));
assertEquals("", StringEscapeUtils.escapeCsv(""));
assertNull(StringEscapeUtils.escapeCsv(null));
}
代码示例来源:origin: pwm-project/pwm
public static String escapeCsv( final String input )
{
return StringEscapeUtils.escapeCsv( input );
}
代码示例来源:origin: org.owasp/dependency-check-core
/**
* Formats text for CSV format. This includes trimming whitespace, replace
* line breaks with spaces, and if necessary quotes the text and/or escapes
* contained quotes.
*
* @param text the text to escape and quote
* @return the escaped and quoted text
*/
public String csv(String text) {
if (text == null || text.isEmpty()) {
return "\"\"";
}
final String str = text.trim().replace("\n", " ");
if (str.length() == 0) {
return "\"\"";
}
return StringEscapeUtils.escapeCsv(str);
}
代码示例来源:origin: org.ligoj.bootstrap/bootstrap-core
/**
* Write a field
*/
private void writeField(final Object o, final String header)
throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, IOException {
final String value = BeanUtilsBean.getInstance().getProperty(o, header);
if (value != null) {
writer.write(StringEscapeUtils.escapeCsv(value));
}
}
代码示例来源:origin: org.neo4j/neo4j-dbms
sb.append( escapeCsv( "Process PID" ) ).append( ',' )
.append( escapeCsv( "Process Name" ) ).append( ',' )
.append( escapeCsv( "Process Time" ) ).append( ',' )
.append( escapeCsv( "User" ) ).append( ',' )
.append( escapeCsv( "Virtual Memory" ) ).append( ',' )
.append( escapeCsv( "Physical Memory" ) ).append( ',' )
.append( escapeCsv( "CPU usage" ) ).append( ',' )
.append( escapeCsv( "Start Time" ) ).append( ',' )
.append( escapeCsv( "Priority" ) ).append( ',' )
.append( escapeCsv( "Full command" ) ).append( '\n' );
.append( escapeCsv( processInfo.getName() ) ).append( ',' )
.append( processInfo.getTime() ).append( ',' )
.append( escapeCsv( processInfo.getUser() ) ).append( ',' )
.append( processInfo.getVirtualMemory() ).append( ',' )
.append( processInfo.getPhysicalMemory() ).append( ',' )
.append( processInfo.getStartTime() ).append( ',' )
.append( processInfo.getStartTime() ).append( ',' )
.append( escapeCsv( processInfo.getCommand() ) ).append( '\n' );
代码示例来源:origin: org.owasp/dependency-check-core
/**
* Takes a set of Identifiers, filters them to none CPE, and formats them
* for display in a CSV.
*
* @param ids the set of identifiers
* @return the formatted list of none CPE identifiers
*/
public String csvIdentifiers(Set<Identifier> ids) {
if (ids == null || ids.isEmpty()) {
return "\"\"";
}
boolean addComma = false;
final StringBuilder sb = new StringBuilder();
for (Identifier id : ids) {
if (!"cpe".equals(id.getType())) {
if (addComma) {
sb.append(", ");
} else {
addComma = true;
}
sb.append(id.getValue());
}
}
if (sb.length() == 0) {
return "\"\"";
}
return StringEscapeUtils.escapeCsv(sb.toString());
}
代码示例来源:origin: org.owasp/dependency-check-core
/**
* Takes a set of Identifiers, filters them to just CPEs, and formats them
* for display in a CSV.
*
* @param ids the set of identifiers
* @return the formatted list of CPE identifiers
*/
public String csvCpe(Set<Identifier> ids) {
if (ids == null || ids.isEmpty()) {
return "\"\"";
}
boolean addComma = false;
final StringBuilder sb = new StringBuilder();
for (Identifier id : ids) {
if ("cpe".equals(id.getType())) {
if (addComma) {
sb.append(", ");
} else {
addComma = true;
}
sb.append(id.getValue());
}
}
if (sb.length() == 0) {
return "\"\"";
}
return StringEscapeUtils.escapeCsv(sb.toString());
}
代码示例来源:origin: org.owasp/dependency-check-core
/**
* Takes a set of Identifiers, filters them to just CPEs, and formats them
* for confidence display in a CSV.
*
* @param ids the set of identifiers
* @return the formatted list of confidence
*/
public String csvCpeConfidence(Set<Identifier> ids) {
if (ids == null || ids.isEmpty()) {
return "\"\"";
}
boolean addComma = false;
final StringBuilder sb = new StringBuilder();
for (Identifier id : ids) {
if ("cpe".equals(id.getType())) {
if (addComma) {
sb.append(", ");
} else {
addComma = true;
}
sb.append(id.getConfidence());
}
}
if (sb.length() == 0) {
return "\"\"";
}
return StringEscapeUtils.escapeCsv(sb.toString());
}
代码示例来源:origin: com.infotel.seleniumRobot/core
protected String encodeString(String message, String format) {
if (encoded) {
return message;
}
String newMessage;
switch (format) {
case "xml":
newMessage = StringEscapeUtils.escapeXml11(message);
break;
case "csv":
newMessage = StringEscapeUtils.escapeCsv(message);
break;
case "html":
newMessage = StringEscapeUtils.escapeHtml4(message);
break;
case "json":
newMessage = StringEscapeUtils.escapeJson(message);
break;
default:
throw new CustomSeleniumTestsException("only escaping of 'xml', 'html', 'csv', 'json' is allowed");
}
return newMessage;
}
内容来源于网络,如有侵权,请联系作者删除!