本文整理汇总了Java中org.apache.commons.lang.StringUtils.stripEnd方法的典型用法代码示例。如果您正苦于以下问题:Java StringUtils.stripEnd方法的具体用法?Java StringUtils.stripEnd怎么用?Java StringUtils.stripEnd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang.StringUtils
的用法示例。
在下文中一共展示了StringUtils.stripEnd方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: valStr
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
@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;
}
示例2: convertToLocalResource
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
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);
}
}
示例3: simpleTrim
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
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;
}
}
示例4: getHdfsNodePath
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
public static String getHdfsNodePath(String parentNodePath, String nodeName) {
return (StringUtils.stripEnd(parentNodePath, HDFS_PATH_SEPARATOR) +
HDFS_PATH_SEPARATOR +
StringUtils.stripStart(nodeName, HDFS_PATH_SEPARATOR));
}
示例5: getNodePath
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
public static String getNodePath(String parentNodePath, String nodeName) {
return (StringUtils.stripEnd(parentNodePath, PATH_SEPARATOR) +
PATH_SEPARATOR +
StringUtils.stripStart(nodeName, PATH_SEPARATOR));
}
示例6: trim
import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
/**
*
* 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;
}
}