Java Code Examples for org.apache.commons.lang3.StringUtils#stripAll()

The following examples show how to use org.apache.commons.lang3.StringUtils#stripAll() . 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: DateModificator.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 2
Source File: DatabaseHelper.java    From hadoop-ozone with Apache License 2.0 4 votes vote down vote up
@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;
}
 
Example 3
Source File: Configuration.java    From deeplearning4j with Apache License 2.0 3 votes vote down vote up
/**
 * 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, ","));
    }
}
 
Example 4
Source File: Configuration.java    From deeplearning4j with Apache License 2.0 2 votes vote down vote up
/**
 * 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, ","));
}