List of usage examples for java.lang String regionMatches
public boolean regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len)
From source file:org.gradle.internal.FileUtils.java
private static boolean endsWithIgnoreCase(String subject, String suffix) { return subject.regionMatches(true, subject.length() - suffix.length(), suffix, 0, suffix.length()); }
From source file:Main.java
/** * <p>Check if a String starts with a specified prefix (optionally case insensitive).</p> * * @see java.lang.String#startsWith(String) * @param str the String to check, may be null * @param prefix the prefix to find, may be null * @param ignoreCase inidicates whether the compare should ignore case * (case insensitive) or not.//from w w w. jav a2s. com * @return <code>true</code> if the String starts with the prefix or * both <code>null</code> */ private static boolean startsWith(String str, String prefix, boolean ignoreCase) { if (str == null || prefix == null) { return (str == null && prefix == null); } if (prefix.length() > str.length()) { return false; } return str.regionMatches(ignoreCase, 0, prefix, 0, prefix.length()); }
From source file:org.orbeon.oxf.util.SystemUtils.java
/** * @param c Reciever of java.io.File's gathered from sun.boot.class.path elements * as well as the contents of the dirs named in java.ext.dirs. *///from w w w . j a va 2 s . c om public static void gatherSystemPaths(final Collection c) { final String bootcp = System.getProperty("sun.boot.class.path"); gatherPaths(c, bootcp); final String extDirProp = System.getProperty("java.ext.dirs"); final File[] extDirs = pathToFiles(extDirProp); for (int i = 0; i < extDirs.length; i++) { final File[] jars = extDirs[i].listFiles(); if (jars != null) { // jars can be null when java.ext.dirs points to a non-existant directory for (int j = 0; j < jars.length; j++) { final File fil = jars[j]; final String fnam = fil.toString(); final int fnamLen = fnam.length(); if (fnamLen < 5) continue; if (fnam.regionMatches(true, fnamLen - 4, ".jar", 0, 4)) { c.add(fil); } else if (fnam.regionMatches(true, fnamLen - 4, ".zip", 0, 4)) { c.add(fil); } } } } }
From source file:Main.java
/** * Check if a String ends with a specified suffix (optionally case insensitive). * * @see java.lang.String#endsWith(String) * @param str the String to check, may be null * @param suffix the suffix to find, may be null * @param ignoreCase inidicates whether the compare should ignore case * (case insensitive) or not./*from w ww . ja v a 2 s . com*/ * @return <code>true</code> if the String starts with the prefix or * both <code>null</code> */ private static boolean endsWith(String str, String suffix, boolean ignoreCase) { if (str == null || suffix == null) { return (str == null && suffix == null); } if (suffix.length() > str.length()) { return false; } int strOffset = str.length() - suffix.length(); return str.regionMatches(ignoreCase, strOffset, suffix, 0, suffix.length()); }
From source file:pt.webdetails.cpf.Util.java
/** * Helper method that given a path of a resource, allows us to infer on the appropriate IReadAccess object for it * * @param resourcePath the path to a resource * @param factory the IReadAccess factory * @param pluginId the plugin's id * @param pluginSystemDir the plugin's base system directory * @param pluginRepoDir the plugin's base repository directory * @return appropriate IReadAccess object for the given resource *///from ww w . java2 s . co m public static IReadAccess getAppropriateReadAccess(final String resourcePath, final IContentAccessFactory factory, final String pluginId, final String pluginSystemDir, final String pluginRepoDir) { if (StringUtils.isEmpty(resourcePath) || StringUtils.isEmpty(pluginId) || StringUtils.isEmpty(pluginSystemDir) || StringUtils.isEmpty(pluginRepoDir) || factory == null) { return null; } String id = pluginId.endsWith(SEPARATOR) ? pluginId : pluginId + SEPARATOR; String repoDir = pluginRepoDir.endsWith(SEPARATOR) ? pluginRepoDir : pluginRepoDir + SEPARATOR; String systemDir = pluginSystemDir.endsWith(SEPARATOR) ? pluginSystemDir : pluginSystemDir + SEPARATOR; // remove leading and trailing SEPARATOR *and* also performs String.trim() String resource = StringUtils.strip(resourcePath, SEPARATOR); if (resource.regionMatches(true, 0, systemDir, 0, systemDir.length())) { resource = resource.replaceFirst(systemDir, ""); // trim the 'system' if (resource.regionMatches(true, 0, id, 0, id.length())) { // system dir - this plugin id return factory.getPluginSystemReader(null); } else { // system dir - some other plugin id; lets find out which one String otherPluginId = resource.substring(0, resource.indexOf(SEPARATOR)); return factory.getOtherPluginSystemReader(otherPluginId, null); } } else if (resource.regionMatches(true, 0, repoDir, 0, repoDir.length())) { // plugin repository dir return factory.getPluginRepositoryReader(null); } else { // one of two: // A - already trimmed system resource (ex: 'resources/templates/1-empty-structure.cdfde') for the pluginId // B - user solution resource (ex: 'public/plugin-samples/pentaho-cdf-dd/styles/my-style.css') if (factory.getPluginSystemReader(null).fileExists(resourcePath)) { return factory.getPluginSystemReader(null); } else if (factory.getUserContentAccess(null).fileExists(resourcePath)) { // user solution dir return factory.getUserContentAccess(null); } } return null; // reaching this point, there's not much more left to be done, and null is returned }
From source file:org.lockss.util.HeaderUtil.java
static boolean isCachableContentType(String contentType) { if (contentType == null) { return false; }/*from w w w . j ava 2 s . c o m*/ int pos = -1; while ((pos = contentType.indexOf('=', pos + 1)) >= 0) { if (pos - CLEN < 0 || !contentType.regionMatches(true, pos - CLEN, "charset", 0, CLEN)) { return false; } if ((pos - CLEN >= 1) && isTokenChar(contentType.charAt(pos - CLEN - 1))) { return false; } } return true; }
From source file:forge.card.BoosterGenerator.java
@SuppressWarnings("unchecked") public static PrintSheet makeSheet(String sheetKey, Iterable<PaperCard> src) { PrintSheet ps = new PrintSheet(sheetKey); String[] sKey = TextUtil.splitWithParenthesis(sheetKey, ' ', 2); Predicate<PaperCard> setPred = (Predicate<PaperCard>) (sKey.length > 1 ? IPaperCard.Predicates.printedInSets(sKey[1].split(" ")) : Predicates.alwaysTrue());//from w w w . j a v a 2 s.c o m List<String> operators = new LinkedList<>(Arrays.asList(TextUtil.splitWithParenthesis(sKey[0], ':'))); Predicate<PaperCard> extraPred = buildExtraPredicate(operators); // source replacement operators - if one is applied setPredicate will be ignored Iterator<String> itMod = operators.iterator(); while (itMod.hasNext()) { String mainCode = itMod.next(); if (mainCode.regionMatches(true, 0, "fromSheet", 0, 9)) { // custom print sheet String sheetName = StringUtils.strip(mainCode.substring(9), "()\" "); src = StaticData.instance().getPrintSheets().get(sheetName).toFlatList(); setPred = Predicates.alwaysTrue(); } else if (mainCode.startsWith("promo")) { // get exactly the named cards, that's a tiny inlined print sheet String list = StringUtils.strip(mainCode.substring(5), "() "); String[] cardNames = TextUtil.splitWithParenthesis(list, ',', '"', '"'); List<PaperCard> srcList = new ArrayList<>(); for (String cardName : cardNames) { srcList.add(StaticData.instance().getCommonCards().getCard(cardName)); } src = srcList; setPred = Predicates.alwaysTrue(); } else { continue; } itMod.remove(); } // only special operators should remain by now - the ones that could not be turned into one predicate String mainCode = operators.isEmpty() ? null : operators.get(0).trim(); if (null == mainCode || mainCode.equalsIgnoreCase(BoosterSlots.ANY)) { // no restriction on rarity Predicate<PaperCard> predicate = Predicates.and(setPred, extraPred); ps.addAll(Iterables.filter(src, predicate)); } else if (mainCode.equalsIgnoreCase(BoosterSlots.UNCOMMON_RARE)) { // for sets like ARN, where U1 cards are considered rare and U3 are uncommon Predicate<PaperCard> predicateRares = Predicates.and(setPred, IPaperCard.Predicates.Presets.IS_RARE, extraPred); ps.addAll(Iterables.filter(src, predicateRares)); Predicate<PaperCard> predicateUncommon = Predicates.and(setPred, IPaperCard.Predicates.Presets.IS_UNCOMMON, extraPred); ps.addAll(Iterables.filter(src, predicateUncommon), 3); } else if (mainCode.equalsIgnoreCase(BoosterSlots.RARE_MYTHIC)) { // Typical ratio of rares to mythics is 53:15, changing to 35:10 in smaller sets. // To achieve the desired 1:8 are all mythics are added once, and all rares added twice per print sheet. Predicate<PaperCard> predicateMythic = Predicates.and(setPred, IPaperCard.Predicates.Presets.IS_MYTHIC_RARE, extraPred); ps.addAll(Iterables.filter(src, predicateMythic)); Predicate<PaperCard> predicateRare = Predicates.and(setPred, IPaperCard.Predicates.Presets.IS_RARE, extraPred); ps.addAll(Iterables.filter(src, predicateRare), 2); } else { throw new IllegalArgumentException("Booster generator: operator could not be parsed - " + mainCode); } return ps; }
From source file:org.orbeon.oxf.util.SystemUtils.java
public static String getJarPath(Class clazz) { String resourceName = StringUtils.replace(clazz.getName(), ".", "/") + ".class"; try {/* w w w .j a v a 2 s. co m*/ URL url = clazz.getClassLoader().getResource(resourceName); if (url == null) throw new IllegalArgumentException("Invalid resource name: " + resourceName); if (url.getProtocol().equals("jar")) { if (url.getProtocol().equals("jar")) { // The current class is in a JAR file String fileName = url.getFile(); int end = fileName.length() - ("!/".length() + resourceName.length()); final String fileSlash = "file:/"; final int fileSlashLen = fileSlash.length(); if (end > fileSlashLen && fileName.regionMatches(true, 0, fileSlash, 0, fileSlashLen)) { fileName = fileName.substring(fileSlashLen, end); File file = new File(fileName); if (!file.exists()) { // Try to decode only if we cannot find the file (see explanation in other method above) fileName = URLDecoder.decode(fileName, "utf-8"); } File jarDirectory = new File(fileName).getParentFile(); if (jarDirectory.isDirectory()) return jarDirectory.getCanonicalPath(); } } } return null; } catch (IOException e) { throw new OXFException(e); } }
From source file:org.apache.any23.extractor.calendar.BaseCalendarExtractor.java
private static IRI type(String originalName) { if (originalName.regionMatches(true, 0, "X-", 0, 2)) { //non-standard class return f.createIRI(ICAL.NS, "X-" + localNameOfType(originalName.substring(2))); }/*from w w w . j a v a 2 s.c o m*/ String name = localNameOfType(originalName); try { return Objects.requireNonNull(vICAL.getClass(name)); } catch (RuntimeException e) { return null; } }
From source file:com.android.browser.DownloadHandler.java
/** * Notify the host application a download should be done, or that * the data should be streamed if a streaming viewer is available. * @param activity Activity requesting the download. * @param url The full url to the content that should be downloaded * @param userAgent User agent of the downloading application. * @param contentDisposition Content-disposition http header, if present. * @param mimetype The mimetype of the content reported by the server * @param referer The referer associated with the downloaded url * @param privateBrowsing If the request is coming from a private browsing tab. *//*from ww w . j a va 2s . c o m*/ public static void onDownloadStart(Activity activity, String url, String userAgent, String contentDisposition, String mimetype, String referer, boolean privateBrowsing) { // if we're dealing wih A/V content that's not explicitly marked // for download, check if it's streamable. if (contentDisposition == null || !contentDisposition.regionMatches(true, 0, "attachment", 0, 10)) { // query the package manager to see if there's a registered handler // that matches. Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse(url), mimetype); ResolveInfo info = activity.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); if (info != null) { ComponentName myName = activity.getComponentName(); // If we resolved to ourselves, we don't want to attempt to // load the url only to try and download it again. if (!myName.getPackageName().equals(info.activityInfo.packageName) || !myName.getClassName().equals(info.activityInfo.name)) { // someone (other than us) knows how to handle this mime // type with this scheme, don't download. try { activity.startActivity(intent); return; } catch (ActivityNotFoundException ex) { if (LOGD_ENABLED) { Log.d(LOGTAG, "activity not found for " + mimetype + " over " + Uri.parse(url).getScheme(), ex); } // Best behavior is to fall back to a download in this // case } } } } onDownloadStartNoStream(activity, url, userAgent, contentDisposition, mimetype, referer, privateBrowsing); }