Java Code Examples for org.apache.commons.lang.StringUtils.stripEnd()

The following are Jave code examples for showing how to use stripEnd() of the org.apache.commons.lang.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: dble   File: ItemFuncTrim.java   Source Code and License Vote up 6 votes
@Override
public String valStr() {
    String toTrim = args.get(0).valStr();
    if (nullValue = args.get(0).isNullValue())
        return null;
    String remove = null;
    if (getArgCount() == 2) {
        remove = args.get(1).valStr();
        if (nullValue = args.get(1).isNullValue())
            return null;
    }
    String ret = null;
    if (mTrimLeading)
        ret = StringUtils.stripStart(toTrim, remove);
    if (mTrimTrailing)
        ret = StringUtils.stripEnd(toTrim, remove);
    return ret;
}
 
Example 2
Project: pai   File: HadoopUtils.java   Source Code and License Vote up 5 votes
private static LocalResource convertToLocalResource(String hdfsPath, LocalResourceVisibility visibility) throws Exception {
  // Directory resource path must not end with /, otherwise localization will hang.
  hdfsPath = StringUtils.stripEnd(hdfsPath, HDFS_PATH_SEPARATOR);
  String extension = FilenameUtils.getExtension(hdfsPath).toLowerCase();
  LocalResourceType type;
  if (extension.equals(".zip") ||
      extension.equals(".tgz") ||
      extension.equals(".tar") ||
      extension.equals(".tar.gz")) {
    type = LocalResourceType.ARCHIVE;
  } else {
    type = LocalResourceType.FILE;
  }

  // Currently only HDFS URI is supported
  // Note Non APPLICATION LocalResourceVisibility may introduce conflicts if multiple
  // Applications' Containers on the same node write the same data in the resource directory.
  try {
    FileStatus fileStatus = getFileStatusInHdfs(hdfsPath);
    FileContext fileContext = FileContext.getFileContext(conf);
    return LocalResource.newInstance(
        ConverterUtils.getYarnUrlFromPath(fileContext
            .getDefaultFileSystem().resolvePath(fileStatus.getPath())),
        type, visibility, fileStatus.getLen(), fileStatus.getModificationTime());
  } catch (IllegalArgumentException e) {
    // hdfsPath may be from user, so it may be illegal.
    throw new NonTransientException("Path is illegal.", e);
  }
}
 
Example 3
Project: monarch   File: PreprocessorUtils.java   Source Code and License Vote up 5 votes
public static TrimmedInput simpleTrim(String input) {
  if (input != null) {
    // First remove the trailing white spaces, we do not need those
    if (!containsOnlyWhiteSpaces(input)) {
      input = StringUtils.stripEnd(input, null);
    }
    String output = input.trim();
    return new TrimmedInput(output, input.length() - output.length());
  } else {
    return null;
  }
}
 
Example 4
Project: pai   File: HadoopUtils.java   Source Code and License Vote up 4 votes
public static String getHdfsNodePath(String parentNodePath, String nodeName) {
  return (StringUtils.stripEnd(parentNodePath, HDFS_PATH_SEPARATOR) +
      HDFS_PATH_SEPARATOR +
      StringUtils.stripStart(nodeName, HDFS_PATH_SEPARATOR));
}
 
Example 5
Project: pai   File: ZookeeperStoreStructure.java   Source Code and License Vote up 4 votes
public static String getNodePath(String parentNodePath, String nodeName) {
  return (StringUtils.stripEnd(parentNodePath, PATH_SEPARATOR) +
      PATH_SEPARATOR +
      StringUtils.stripStart(nodeName, PATH_SEPARATOR));
}
 
Example 6
Project: pai   File: WebStructure.java   Source Code and License Vote up 4 votes
public static String getNodePath(String parentNodePath, String nodeName) {
  return (StringUtils.stripEnd(parentNodePath, PATH_SEPARATOR) +
      PATH_SEPARATOR +
      StringUtils.stripStart(nodeName, PATH_SEPARATOR));
}
 
Example 7
Project: monarch   File: PreprocessorUtils.java   Source Code and License Vote up 4 votes
/**
 * 
 * This function will trim the given input string. It will not only remove the spaces and tabs at
 * the end but also compress multiple spaces and tabs to a single space
 * 
 * @param input The input string on which the trim operation needs to be performed
 * @param retainLineSeparator whether to retain the line separator.
 * 
 * @return String
 */
public static TrimmedInput trim(final String input, final boolean retainLineSeparator) {
  if (input != null) {
    String inputCopy = input;
    StringBuffer output = new StringBuffer();
    // First remove the trailing white spaces, we do not need those
    inputCopy = StringUtils.stripEnd(inputCopy, null);
    // As this parser is for optionParsing, we also need to remove
    // the trailing optionSpecifiers provided it has previous
    // options. Remove the trailing LONG_OPTION_SPECIFIERs
    // in a loop. It is necessary to check for previous options for
    // the case of non-mandatory arguments.
    // "^(.*)(\\s-+)$" - something that ends with a space followed by a series of hyphens.
    while (Pattern.matches("^(.*)(\\s-+)$", inputCopy)) {
      inputCopy = StringUtils.removeEnd(inputCopy, SyntaxConstants.SHORT_OPTION_SPECIFIER);

      // Again we need to trim the trailing white spaces
      // As we are in a loop
      inputCopy = StringUtils.stripEnd(inputCopy, null);
    }
    // Here we made use of the String class function trim to remove the
    // space and tabs if any at the
    // beginning and the end of the string
    int noOfSpacesRemoved = 0;
    {
      int length = inputCopy.length();
      inputCopy = inputCopy.trim();
      noOfSpacesRemoved += length - inputCopy.length();
    }
    // Now we need to compress the multiple spaces and tabs to single space
    // and tabs but we also need to ignore the white spaces inside the
    // quotes and parentheses

    StringBuffer buffer = new StringBuffer();

    boolean startWhiteSpace = false;
    for (int i = 0; i < inputCopy.length(); i++) {
      char ch = inputCopy.charAt(i);
      buffer.append(ch);
      if (PreprocessorUtils.isWhitespace(ch)) {
        if (PreprocessorUtils.isSyntaxValid(buffer.toString())) {
          if (startWhiteSpace) {
            noOfSpacesRemoved++;
          } else {
            startWhiteSpace = true;
            if (ch == '\n') {
              if (retainLineSeparator) {
                output.append("\n");
              }
            } else {
              output.append(" ");
            }
          }
          buffer.delete(0, buffer.length());
        } else {
          output.append(ch);
        }
      } else {
        startWhiteSpace = false;
        output.append(ch);
      }
    }
    return new TrimmedInput(output.toString(), noOfSpacesRemoved);
  } else {
    return null;
  }
}