List of usage examples for java.lang String endsWith
public boolean endsWith(String suffix)
From source file:com.facebook.stetho.inspector.domstorage.SharedPreferencesHelper.java
public static List<String> getSharedPreferenceTags(Context context) { ArrayList<String> tags = new ArrayList<String>(); String rootPath = context.getApplicationInfo().dataDir + "/shared_prefs"; File root = new File(rootPath); if (root.exists()) { for (File file : root.listFiles()) { String fileName = file.getName(); if (fileName.endsWith(PREFS_SUFFIX)) { tags.add(fileName.substring(0, fileName.length() - PREFS_SUFFIX.length())); }//from ww w. j av a 2s . co m } } return tags; }
From source file:Main.java
/** * getKalturaDomain returns the current domain. This function strips off all trailing / characters and the protocol. * @link APIHelpers.loadProtocol(context) * @param context/* w ww. j ava2 s.c o m*/ * @return */ public static String getKalturaDomain(Context context) { if (context == null) { return ""; } SharedPreferences sharedPreferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); String domain = sharedPreferences.getString(SHARED_PREFERENCES_KALTURA_DOMAIN, ""); while (domain != null && domain.endsWith("/")) { domain = domain.substring(0, domain.length() - 1); } return domain; }
From source file:Main.java
private static boolean isImageFormat(String fileName) { if (fileName == null) { return false; }/*from ww w .j av a 2s . com*/ fileName = fileName.toLowerCase(); if (fileName.endsWith(".jpg") || fileName.endsWith(".jpeg") || fileName.endsWith(".png") || fileName.endsWith(".bmp") || fileName.endsWith(".jpe") || fileName.endsWith(".gif") || fileName.endsWith(".wbmp")) { return true; } return false; }
From source file:com.qpark.eip.core.model.analysis.operation.GetFlowOperation.java
/** * Translate the pattern do SQL <i>like</i>. * * @param namePattern// w w w. j a v a 2 s . c o m * the given name pattern. * @return the translated pattern. */ private static Optional<String> translateNamePattern(final String namePattern) { Optional<String> value = Optional.empty(); if (Objects.nonNull(namePattern)) { String s = namePattern.replace('*', '%'); if (!s.endsWith("%")) { s = String.format("%s%s", s, "%"); } if (!s.startsWith("%")) { s = String.format("%s%s", "%", s); } value = Optional.of(s); } return value; }
From source file:com.github.caldav4j.util.UrlUtils.java
public static String ensureTrailingSlash(String s) { return (s.endsWith("/")) ? s : s.concat("/"); }
From source file:codeOrchestra.lcs.license.ActivationReporter.java
private static String getFingerPrint() { StringBuilder resultSB = new StringBuilder(); try {/* ww w . j a va 2s . c om*/ for (final Enumeration<NetworkInterface> interfaces = NetworkInterface .getNetworkInterfaces(); interfaces.hasMoreElements();) { final NetworkInterface networkInterface = (NetworkInterface) interfaces.nextElement(); if (networkInterface.isLoopback()) { continue; } byte[] mac = networkInterface.getHardwareAddress(); if (mac == null) { continue; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < mac.length; i++) { sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : "")); } if ("00-00-00-00-00-00-00-E0".equals(sb.toString())) { continue; } resultSB.append(sb); if (interfaces.hasMoreElements()) { resultSB.append("|"); } } } catch (Exception e) { // ignore } String result = resultSB.toString(); if (result.endsWith("|")) { return result.substring(0, result.length() - 1); } return result; }
From source file:com.gargoylesoftware.htmlunit.util.WebClientUtils.java
/** * Attaches a visual (GUI) debugger to the specified client. * @param client the client to which the visual debugger is to be attached * @see <a href="http://www.mozilla.org/rhino/debugger.html">Mozilla Rhino Debugger Documentation</a> *//* w w w. j av a2 s .c o m*/ public static void attachVisualDebugger(final WebClient client) { final ScopeProvider sp = null; final HtmlUnitContextFactory cf = client.getJavaScriptEngine().getContextFactory(); final Main main = Main.mainEmbedded(cf, sp, "HtmlUnit JavaScript Debugger"); main.getDebugFrame().setExtendedState(Frame.MAXIMIZED_BOTH); final SourceProvider sourceProvider = new SourceProvider() { @Override public String getSource(final DebuggableScript script) { String sourceName = script.getSourceName(); if (sourceName.endsWith("(eval)") || sourceName.endsWith("(Function)")) { return null; // script is result of eval call. Rhino already knows the source and we don't } if (sourceName.startsWith("script in ")) { sourceName = StringUtils.substringBetween(sourceName, "script in ", " from"); for (final WebWindow ww : client.getWebWindows()) { final WebResponse wr = ww.getEnclosedPage().getWebResponse(); if (sourceName.equals(wr.getWebRequest().getUrl().toString())) { return wr.getContentAsString(); } } } return null; } }; main.setSourceProvider(sourceProvider); }
From source file:Main.java
/** * Makes a best guess to infer the type from a file name. * * @param fileName Name of the file. It can include the path of the file. * @return One of {@link #TYPE_DASH}, {@link #TYPE_SS}, {@link #TYPE_HLS} or {@link #TYPE_OTHER}. *//*from w ww. j av a2 s . c om*/ public static int inferContentType(String fileName) { if (fileName == null) { return TYPE_OTHER; } else if (fileName.endsWith(".mpd")) { return TYPE_DASH; } else if (fileName.endsWith(".ism")) { return TYPE_SS; } else if (fileName.endsWith(".m3u8")) { return TYPE_HLS; } else { return TYPE_OTHER; } }
From source file:com.mqtt.curl.mqtt.util.Base64Util.java
/** * Translates the specified Base64 string into a byte array. * * @param s the Base64 string (not null) * @return the byte array (not null)/*w w w. ja v a2s . c o m*/ */ public static byte[] decodeMyself(String s) { int delta = s.endsWith("==") ? 2 : s.endsWith("=") ? 1 : 0; byte[] buffer = new byte[s.length() * 3 / 4 - delta]; int mask = 0xFF; int index = 0; for (int i = 0; i < s.length(); i += 4) { int c0 = toInt[s.charAt(i)]; int c1 = toInt[s.charAt(i + 1)]; buffer[index++] = (byte) (((c0 << 2) | (c1 >> 4)) & mask); if (index >= buffer.length) { return buffer; } int c2 = toInt[s.charAt(i + 2)]; buffer[index++] = (byte) (((c1 << 4) | (c2 >> 2)) & mask); if (index >= buffer.length) { return buffer; } int c3 = toInt[s.charAt(i + 3)]; buffer[index++] = (byte) (((c2 << 6) | c3) & mask); } return buffer; }
From source file:local.edg.ClassDB.java
/** * Generates a data base with class informations about a given application * //w w w . j a va 2 s . c o m * @param appClasses * The classes of the application as directories to class-files or as path to jar-files. * * @return Data base with class information. */ public static Map<String, Class> create(String[] appClasses) { ClassDbVisitor cv = new ClassDbVisitor(); for (String s : appClasses) { File f = new File(s); if (f.isDirectory()) { Collection<File> files = FileUtils.listFiles(f, new String[] { "class" }, true); for (File cf : files) { try { ClassReader cr = new ClassReader(new FileInputStream(cf)); cr.accept(cv, 0); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } else if (f.isFile() && s.toLowerCase().endsWith(".jar")) { try { ZipFile zf = new ZipFile(f); Enumeration<? extends ZipEntry> en = zf.entries(); while (en.hasMoreElements()) { ZipEntry e = en.nextElement(); String name = e.getName(); if (name.endsWith(".class")) { new ClassReader(zf.getInputStream(e)).accept(cv, 0); } } } catch (IOException e1) { e1.printStackTrace(); } } } return cv.getClassDb(); }