下面列出了org.apache.commons.lang3.StringUtils#stripEnd ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public TopicPermissionImpl(@NotNull final String topic, @NotNull final PermissionType type, @NotNull final Qos qos,
@NotNull final MqttActivity activity, @NotNull final Retain retain,
@NotNull final SharedSubscription sharedSubscription, @NotNull final String sharedGroup) {
this.topic = topic;
this.type = type;
this.qos = qos;
this.activity = activity;
this.retain = retain;
this.sharedSubscription = sharedSubscription;
this.sharedGroup = sharedGroup;
//these are used to speed up the evaluation of permissions
final String strippedPermissionTopic = StringUtils.stripEnd(topic, "/");
splitTopic = StringUtils.splitPreserveAllTokens(strippedPermissionTopic, "/");
containsWildcardCharacter = !StringUtils.containsNone(strippedPermissionTopic, "#+");
isRootWildcard = strippedPermissionTopic.contains("#");
endsWithWildcard = StringUtils.endsWith(strippedPermissionTopic, "/#");
}
public boolean matches(@NotNull final String topicSubscription, @NotNull final String actualTopic) throws InvalidTopicException {
if (StringUtils.containsAny(actualTopic, "#+")) {
throw new InvalidTopicException("The actual topic must not contain a wildard character (# or +)");
}
final String subscription = StringUtils.stripEnd(topicSubscription, "/");
String topic = actualTopic;
if (actualTopic.length() > 1) {
topic = StringUtils.stripEnd(actualTopic, "/");
}
if (StringUtils.containsNone(topicSubscription, "#+")) {
return subscription.equals(topic);
}
if (actualTopic.startsWith("$") && !topicSubscription.startsWith("$")) {
return false;
}
return matchesWildcards(subscription, topic);
}
@Override
public String apply(final Integer referenceBuild) {
if (referenceBuild >= currentBuild) {
return "1"; // fallback
}
else {
String cleanUrl = StringUtils.stripEnd(resultUrl, "/");
int subDetailsCount = StringUtils.countMatches(cleanUrl, "/");
String backward = StringUtils.repeat("../", subDetailsCount + 2);
String detailsUrl = StringUtils.substringBefore(cleanUrl, "/");
String url = String.format("%s%d/%s", backward, referenceBuild, detailsUrl);
return a(computeAge(referenceBuild))
.withHref(StringUtils.stripEnd(url, "/")).render();
}
}
public static String formatIndentation(String str, String indentWith) {
str = StringUtils.strip(str);
String[] splits = StringUtils.splitPreserveAllTokens(str, "\n");
int depth = 0;
for (int i = 0; i < splits.length; i++) {
// Unindent leading }'s
String line = StringUtils.strip(splits[i]);
while (line.startsWith("}")) {
line = StringUtils.strip(line.substring(1));
depth--;
}
// Indent line to correct depth
splits[i] = StringUtils.repeat(indentWith, depth) + StringUtils.strip(splits[i]);
splits[i] = StringUtils.stripEnd(splits[i], null); // in case empty line
depth += StringUtils.countMatches(line, "{");
depth -= StringUtils.countMatches(line, "}");
}
return StringUtils.join(splits, "\n");
}
/**
* Helper function for listStatus to find key in TableCache.
*/
private void listStatusFindKeyInTableCache(
Iterator<Map.Entry<CacheKey<String>, CacheValue<OmKeyInfo>>> cacheIter,
String keyArgs, String startCacheKey, boolean recursive,
TreeMap<String, OzoneFileStatus> cacheKeyMap, Set<String> deletedKeySet) {
while (cacheIter.hasNext()) {
Map.Entry<CacheKey<String>, CacheValue<OmKeyInfo>> entry =
cacheIter.next();
String cacheKey = entry.getKey().getCacheKey();
if (cacheKey.equals(keyArgs)) {
continue;
}
OmKeyInfo cacheOmKeyInfo = entry.getValue().getCacheValue();
// cacheOmKeyInfo is null if an entry is deleted in cache
if (cacheOmKeyInfo != null) {
if (cacheKey.startsWith(startCacheKey) &&
cacheKey.compareTo(startCacheKey) >= 0) {
if (!recursive) {
String remainingKey = StringUtils.stripEnd(cacheKey.substring(
startCacheKey.length()), OZONE_URI_DELIMITER);
// For non-recursive, the remaining part of key can't have '/'
if (remainingKey.contains(OZONE_URI_DELIMITER)) {
continue;
}
}
OzoneFileStatus fileStatus = new OzoneFileStatus(
cacheOmKeyInfo, scmBlockSize, !OzoneFSUtils.isFile(cacheKey));
cacheKeyMap.put(cacheKey, fileStatus);
}
} else {
deletedKeySet.add(cacheKey);
}
}
}
@Override
protected String getMacroValue(String str) {
if (servletContext != null) {
return StringUtils.stripEnd(servletContext.getContextPath(), "/");
} else {
return null;
}
}
public String getHiddenText() {
List<String> hiddenFragments = new ArrayList<String>();
for (Fragment fragment : fragments) {
if (fragment.isHidden())
hiddenFragments.add(fragment.getContent());
}
return StringUtils.stripEnd(StringUtils.join(hiddenFragments,"\n"), null);
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append(commit.getHash()).append(": ");
for (LinearRange range: ranges)
builder.append(range).append(", ");
return StringUtils.stripEnd(builder.toString(), ", ");
}
public RemoteRepository( Locale locale, String id, String name, String url, String layout, String userName, String password,
int timeout )
{
super( locale, id, name, layout );
this.url = StringUtils.stripEnd(url,"/");
this.userName = userName;
this.password = password;
this.timeout = timeout;
}
public String output() {
if (isLeftTrim() && isRightTrim()) {
return trim();
} else if (isLeftTrim()) {
return StringUtils.stripStart(content, null);
} else if (isRightTrim()) {
return StringUtils.stripEnd(content, null);
}
return content;
}
/**
* FIXME not sure if this method does extract text from every possible variation
* of a docx...
*/
public static String extractTextFromDocx(String filename) throws Docx4JException, JAXBException {
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(filename));
MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
String pageTxt = "";
for (Object o : documentPart.getContent()) {
if (o == null)
continue;
pageTxt += o.toString() + "\n";
}
return StringUtils.stripEnd(pageTxt, "\n");
}
public RntbdRequestArgs(final RxDocumentServiceRequest serviceRequest, final URI physicalAddress) {
this.sample = Timer.start();
this.activityId = UUID.fromString(serviceRequest.getActivityId());
this.timeCreated = OffsetDateTime.now();
this.nanoTimeCreated = System.nanoTime();
this.lifetime = Stopwatch.createStarted();
this.origin = physicalAddress.getScheme() + "://" + physicalAddress.getAuthority();
this.physicalAddress = physicalAddress;
this.replicaPath = StringUtils.stripEnd(physicalAddress.getPath(), "/");
this.serviceRequest = serviceRequest;
this.transportRequestId = instanceCount.incrementAndGet();
}
public MemTask() {
file = StringUtils.stripEnd(getfileName(), ".java") + file;
initFields(true, getFile());
}
public CpuTask() {
file = StringUtils.stripEnd(getfileName(), ".java") + file;
initFields(true, getFile());
}
public CpuTask(boolean bWriteFile) {
file = StringUtils.stripEnd(getfileName(), ".java") + file;
initFields(bWriteFile, getFile());
}
/**
* <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br>
*
* Gets the request for a submission of this form with the specified SubmittableElement.
* @param submitElement the element that caused the submit to occur
* @return the request
*/
public WebRequest getWebRequest(final SubmittableElement submitElement) {
final HtmlPage htmlPage = (HtmlPage) getPage();
final List<NameValuePair> parameters = getParameterListForSubmit(submitElement);
final HttpMethod method;
final String methodAttribute = getMethodAttribute();
if ("post".equalsIgnoreCase(methodAttribute)) {
method = HttpMethod.POST;
}
else {
if (!"get".equalsIgnoreCase(methodAttribute) && StringUtils.isNotBlank(methodAttribute)) {
notifyIncorrectness("Incorrect submit method >" + getMethodAttribute() + "<. Using >GET<.");
}
method = HttpMethod.GET;
}
final BrowserVersion browser = getPage().getWebClient().getBrowserVersion();
String actionUrl = getActionAttribute();
String anchor = null;
String queryFromFields = "";
if (HttpMethod.GET == method) {
if (actionUrl.contains("#")) {
anchor = StringUtils.substringAfter(actionUrl, "#");
}
final Charset enc = getPage().getCharset();
queryFromFields =
URLEncodedUtils.format(Arrays.asList(NameValuePair.toHttpClient(parameters)), enc);
// action may already contain some query parameters: they have to be removed
actionUrl = StringUtils.substringBefore(actionUrl, "#");
actionUrl = StringUtils.substringBefore(actionUrl, "?");
parameters.clear(); // parameters have been added to query
}
URL url;
try {
if (actionUrl.isEmpty()) {
url = WebClient.expandUrl(htmlPage.getUrl(), actionUrl);
}
else {
url = htmlPage.getFullyQualifiedUrl(actionUrl);
}
if (!queryFromFields.isEmpty()) {
url = UrlUtils.getUrlWithNewQuery(url, queryFromFields);
}
if (HttpMethod.GET == method && browser.hasFeature(FORM_SUBMISSION_URL_WITHOUT_HASH)
&& WebClient.URL_ABOUT_BLANK != url) {
url = UrlUtils.getUrlWithNewRef(url, null);
}
else if (HttpMethod.POST == method
&& browser.hasFeature(FORM_SUBMISSION_URL_WITHOUT_HASH)
&& WebClient.URL_ABOUT_BLANK != url
&& StringUtils.isEmpty(actionUrl)) {
url = UrlUtils.getUrlWithNewRef(url, null);
}
else if (anchor != null
&& WebClient.URL_ABOUT_BLANK != url) {
url = UrlUtils.getUrlWithNewRef(url, anchor);
}
}
catch (final MalformedURLException e) {
throw new IllegalArgumentException("Not a valid url: " + actionUrl);
}
final WebRequest request = new WebRequest(url, method);
request.setAdditionalHeader(HttpHeader.ACCEPT, browser.getHtmlAcceptHeader());
request.setAdditionalHeader(HttpHeader.ACCEPT_ENCODING, "gzip, deflate");
request.setRequestParameters(parameters);
if (HttpMethod.POST == method) {
request.setEncodingType(FormEncodingType.getInstance(getEnctypeAttribute()));
}
request.setCharset(getSubmitCharset());
String referer = htmlPage.getUrl().toExternalForm();
request.setAdditionalHeader(HttpHeader.REFERER, referer);
if (HttpMethod.POST == method
&& browser.hasFeature(FORM_SUBMISSION_HEADER_ORIGIN)) {
referer = StringUtils.stripEnd(referer, "/");
request.setAdditionalHeader(HttpHeader.ORIGIN, referer);
}
if (HttpMethod.POST == method
&& browser.hasFeature(FORM_SUBMISSION_HEADER_CACHE_CONTROL_MAX_AGE)) {
request.setAdditionalHeader(HttpHeader.CACHE_CONTROL, "max-age=0");
}
if (browser.hasFeature(FORM_SUBMISSION_HEADER_CACHE_CONTROL_NO_CACHE)) {
request.setAdditionalHeader(HttpHeader.CACHE_CONTROL, "no-cache");
}
return request;
}
public String getBaseHttpUrl() {
return StringUtils.stripEnd(httpUrl, "/");
}
public CpuTask(boolean bWriteFile, String filename) {
file = StringUtils.stripEnd(getfileName(), ".java") + file;
initFields(bWriteFile, filename);
}
public MemTask(boolean bWriteFile, String filename) {
file = StringUtils.stripEnd(getfileName(), ".java") + file;
initFields(bWriteFile, filename);
}
/**
* Removes the last occurrence of the the given string, including potential
* trailing spaces.
*
* @param string the string, without potential trailing spaces.
* @param remove the text to remove.
* @return the chopped string.
*/
public static String removeLast( String string, String remove )
{
string = StringUtils.stripEnd( string, " " );
return StringUtils.removeEndIgnoreCase( string, remove );
}