本文整理汇总了Java中org.apache.commons.lang3.StringUtils.chomp方法的典型用法代码示例。如果您正苦于以下问题:Java StringUtils.chomp方法的具体用法?Java StringUtils.chomp怎么用?Java StringUtils.chomp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang3.StringUtils
的用法示例。
在下文中一共展示了StringUtils.chomp方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: protocolCommandSent
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
@Override
public void protocolCommandSent(final ProtocolCommandEvent event) {
final String message = StringUtils.chomp(event.getMessage());
if(message.startsWith(FTPCmd.PASS.name())) {
this.log(Type.request, String.format("%s %s", FTPCmd.PASS.name(),
StringUtils.repeat("*", StringUtils.length(StringUtils.removeStart(message, FTPCmd.PASS.name())))));
}
else {
this.log(Type.request, message);
}
}
示例2: getModificationTime
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
@Override
public String getModificationTime(final String file) throws IOException {
final String status = super.getModificationTime(file);
if(null == status) {
throw new FTPException(this.getReplyCode(), this.getReplyString());
}
return StringUtils.chomp(status.substring(3).trim());
}
示例3: splitIntoMainSections
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
private MutableList<Pair<String, String>> splitIntoMainSections(String text, ImmutableList<String> elementsToCheck, String elementPrefix) {
MutableList<Pair<String, String>> outerSections = Lists.mutable.empty();
String nextSectionName = null;
boolean startOfSearch = true;
// here, we go in a loop searching for the next referenc of "[elementPrefix] [sectionName]", e.g. //// CHANGE
// By each of those points, we split those into separate text sections and return back to the client.
// We aim to preserve the line breaks found when parsing the sections
while (text != null) {
String currentSectionName = nextSectionName;
String currentSectionText;
int earliestIndex = Integer.MAX_VALUE;
for (String firstLevelElement : elementsToCheck) {
// on the first search, the text may start w/ the section; hence, we set the search fromIndex param to 0.
// Subsequently, the index picks up at the beginning of the next section; hence, we must start
// the search at the next character, so the fromIndex param is 1
int index = text.indexOf(elementPrefix + " " + firstLevelElement, startOfSearch ? 0 : 1);
if (index != -1 && index < earliestIndex) {
earliestIndex = index;
nextSectionName = firstLevelElement;
}
}
startOfSearch = false;
if (earliestIndex == Integer.MAX_VALUE) {
currentSectionText = StringUtils.chomp(text);
text = null;
} else {
currentSectionText = StringUtils.chomp(text.substring(0, earliestIndex));
text = text.substring(earliestIndex);
}
outerSections.add(Tuples.pair(currentSectionName, currentSectionText));
}
return outerSections;
}
示例4: parseString
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
private ImmutableList<TextMarkupDocumentSection> parseString(String text, MutableList<String> elementsToCheck, boolean recurse,
String elementPrefix) {
MutableList<TextMarkupDocumentSection> sections = Lists.mutable.empty();
while (true) {
int earliestIndex = Integer.MAX_VALUE;
for (String firstLevelElement : elementsToCheck) {
int index = text.indexOf(elementPrefix + " " + firstLevelElement, 1);
if (index != -1 && index < earliestIndex) {
earliestIndex = index;
}
}
if (earliestIndex == Integer.MAX_VALUE) {
sections.add(new TextMarkupDocumentSection(null, text));
break;
} else {
sections.add(new TextMarkupDocumentSection(null, text.substring(0, earliestIndex)));
text = text.substring(earliestIndex);
}
}
for (TextMarkupDocumentSection section : sections) {
MutableMap<String, String> attrs = Maps.mutable.empty();
MutableSet<String> toggles = Sets.mutable.empty();
String content = StringUtils.chomp(section.getContent());
String[] contents = content.split("\\r?\\n", 2);
String firstLine = contents[0];
for (String elementToCheck : elementsToCheck) {
if (firstLine.startsWith(elementPrefix + " " + elementToCheck)) {
section.setName(elementToCheck);
String[] args = StringUtils.splitByWholeSeparator(firstLine, " ");
for (String arg : args) {
if (arg.contains("=")) {
String[] attr = arg.split("=");
if (attr.length > 2) {
throw new IllegalArgumentException("Cannot mark = multiple times in a parameter - "
+ firstLine);
}
String attrVal = attr[1];
if (attrVal.startsWith("\"") && attrVal.endsWith("\"")) {
attrVal = attrVal.substring(1, attrVal.length() - 1);
}
attrs.put(attr[0], attrVal);
} else {
toggles.add(arg);
}
}
if (contents.length > 1) {
content = contents[1];
} else {
content = null;
}
}
}
section.setAttrs(attrs.toImmutable());
section.setToggles(toggles.toImmutable());
if (!recurse) {
section.setContent(content);
} else if (content != null) {
ImmutableList<TextMarkupDocumentSection> subsections = this.parseString(content, this.secondLevelElements, false, "//");
if (subsections.size() == 1) {
section.setContent(content);
} else {
section.setContent(subsections.get(0).getContent());
section.setSubsections(subsections.subList(1, subsections.size()));
}
} else {
section.setContent(null);
}
}
return sections.toImmutable();
}