下面列出了org.apache.commons.lang3.StringUtils#stripAll ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static List<DateModificator> parse(String modifyPattern) {
if (StringUtils.isNotBlank(modifyPattern)) {
List<DateModificator> result = new ArrayList<>();
String[] array = StringUtils.stripAll(StringUtils.split(modifyPattern, ':'));
for (String item : array) {
if (StringUtils.isNoneEmpty(item)) {
Strategy strategy = searchStrategy(item);
if (strategy != null) {
String[] pair = StringUtils.stripAll(StringUtils.split(item, strategy.symbol));
if (pair.length == 2) {
DateComponent dateComponent = DateComponent.parse(pair[0]);
if (dateComponent != null) {
try {
long value = Long.parseLong(pair[1]);
result.add(new DateModificator(strategy, dateComponent, value));
} catch (NumberFormatException e) {
throw new RuntimeException("Field value should be long: '" + pair[1] + "' in '" + modifyPattern + "'");
}
} else {
throw new RuntimeException("Unknown field specified: '" + pair[0] + "'. Expected " + Arrays.toString(DateComponent.values()) + ".");
}
} else {
throw new RuntimeException("Invalid field format: '" + item + "' in '" + modifyPattern + "'");
}
} else {
throw new RuntimeException("Invalid field format. Action missed: '" + item + "' in '" + modifyPattern + "'. Expected [+-=]");
}
}
}
return result;
}
return Collections.emptyList();
}
@SuppressWarnings("squid:S3776")
private static ArrayList<AuditEntry> parseAuditLogs(String filePath)
throws IOException {
ArrayList<AuditEntry> listResult = new ArrayList<>();
try (FileInputStream fis = new FileInputStream(filePath);
InputStreamReader isr = new InputStreamReader(fis, UTF_8);
BufferedReader bReader = new BufferedReader(isr)) {
String currentLine = bReader.readLine();
String nextLine = bReader.readLine();
String[] entry;
AuditEntry tempEntry = null;
while (true) {
if (tempEntry == null){
tempEntry = new AuditEntry();
}
if (currentLine == null) {
break;
} else {
if (!currentLine.matches(ParserConsts.DATE_REGEX)){
tempEntry.appendException(currentLine);
} else {
entry = StringUtils.stripAll(currentLine.split("\\|"));
String[] ops =
entry[5].substring(entry[5].indexOf('=') + 1).split(" ", 2);
tempEntry = new AuditEntry.Builder()
.setTimestamp(entry[0])
.setLevel(entry[1])
.setLogger(entry[2])
.setUser(entry[3].substring(entry[3].indexOf('=') + 1))
.setIp(entry[4].substring(entry[4].indexOf('=') + 1))
.setOp(ops[0])
.setParams(ops[1])
.setResult(entry[6].substring(entry[6].indexOf('=') + 1))
.build();
if (entry.length == 8){
tempEntry.setException(entry[7]);
}
}
if (nextLine == null || nextLine.matches(ParserConsts.DATE_REGEX)){
listResult.add(tempEntry);
tempEntry = null;
}
currentLine = nextLine;
nextLine = bReader.readLine();
}
}
}
return listResult;
}
/**
* Get the comma delimited values of the <code>name</code> property as
* an array of <code>String</code>s, trimmed of the leading and trailing whitespace.
* If no such property is specified then default value is returned.
*
* @param name property name.
* @param defaultValue The default value
* @return property value as an array of trimmed <code>String</code>s,
* or default value.
*/
public String[] getTrimmedStrings(String name, String... defaultValue) {
String valueString = get(name);
if (null == valueString) {
return defaultValue;
} else {
return StringUtils.stripAll(StringUtils.split(valueString, ","));
}
}
/**
* Get the comma delimited values of the <code>name</code> property as
* an array of <code>String</code>s, trimmed of the leading and trailing whitespace.
* If no such property is specified then an empty array is returned.
*
* @param name property name.
* @return property value as an array of trimmed <code>String</code>s,
* or empty array.
*/
public String[] getTrimmedStrings(String name) {
String valueString = get(name);
return StringUtils.stripAll(StringUtils.split(valueString, ","));
}