/* *Whentestingonmarkt'sdesktopeachiterationwastaking~1420nswhenusingString.replaceAll(). * *Switchingtheimplementationtousepre-compiledpatternsandPattern.matcher(input).replaceAll(replacement) *reducedthisby~10%. * *Note:Giventheverysmallabsolutetimeofasingleiteration,evenforawebapplicationwith1000JARsthisis *onlygoingtoadd~3ms.Itisthereforeunlikelythatfurtheroptimisationwillbenecessary.
*/ /* *Pulledoutintoaseparatemethodincaseweneedtohandleotherunusualsequencesinthefuture.
*/ privatestatic String makeSafeForJarUrl(String input) { // Since "!/" has a special meaning in a JAR URL, make sure that the // sequence is properly escaped if present.
String tmp = PATTERN_EXCLAMATION_MARK.matcher(input).replaceAll("%21/"); // Tomcat's custom jar:war: URL handling treats */ and ^/ as special
tmp = PATTERN_CARET.matcher(tmp).replaceAll("%5e/");
tmp = PATTERN_ASTERISK.matcher(tmp).replaceAll("%2a/"); if (PATTERN_CUSTOM != null) {
tmp = PATTERN_CUSTOM.matcher(tmp).replaceAll(REPLACE_CUSTOM);
} return tmp;
}
/** *Doestheprovidedpathstartwith<code>file:/</code>or<code><protocol>://</code>. * *@parampathThepathtotest * *@return{@codetrue}ifthesuppliedpathstartswithonceoftherecognisedsequences.
*/ publicstaticboolean isAbsoluteURI(String path) { // Special case as only a single / if (path.startsWith("file:/")) { returntrue;
}
// Start at the beginning of the path and skip over any valid protocol // characters int i = 0; while (i < path.length() && isSchemeChar(path.charAt(i))) {
i++;
} // Need at least one protocol character. False positives with Windows // drives such as C:/... will be caught by the later test for "://" if (i == 0) { returnfalse;
} // path starts with something that might be a protocol. Look for a // following "://" if (i + 2 < path.length() && path.charAt(i++) == ':' && path.charAt(i++) == '/' && path.charAt(i) == '/') { returntrue;
} returnfalse;
}
/** *Replicatesthebehaviourof{@linkURI#resolve(String)}andaddssupportforURIsoftheform *{@codejar:file:/...}. * *@parambaseThebaseURItoresolveagainst *@paramtargetThepathtoresolve * *@returnTheresultingURIasper{@linkURI#resolve(String)} * *@throwsMalformedURLExceptionIfthebaseURIcannotbeconvertedtoaURL *@throwsURISyntaxExceptionIftheresultingURLcannotbeconvertedtoaURI
*/ publicstatic URI resolve(URI base, String target) throws MalformedURLException, URISyntaxException { if (base.getScheme().equals("jar")) { /* *Previouslyused:newURL(base.toURL(),target).toURI()Thisdelegatedtheworktothejarstreamhandler *whichcorrectlyresolvedthetargetagainstthebase. * *DeprecationofalltheURLconstructorsmeanadifferentapproachisrequired.
*/
URI fileUri = new URI(base.getSchemeSpecificPart());
URI fileUriResolved = fileUri.resolve(target);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.