List of usage examples for java.lang String startsWith
public boolean startsWith(String prefix)
From source file:hadoopInstaller.Main.java
private static Integer detectLogLevel(String[] args) { Map<String, Integer> levels = new HashMap<>(8); levels.put("all", SimpleLog.LOG_LEVEL_ALL); //$NON-NLS-1$ levels.put("off", SimpleLog.LOG_LEVEL_OFF); //$NON-NLS-1$ levels.put("trace", SimpleLog.LOG_LEVEL_TRACE); //$NON-NLS-1$ levels.put("debug", SimpleLog.LOG_LEVEL_DEBUG); //$NON-NLS-1$ levels.put("info", SimpleLog.LOG_LEVEL_INFO); //$NON-NLS-1$ levels.put("warn", SimpleLog.LOG_LEVEL_WARN); //$NON-NLS-1$ levels.put("error", SimpleLog.LOG_LEVEL_ERROR); //$NON-NLS-1$ levels.put("fatal", SimpleLog.LOG_LEVEL_FATAL); //$NON-NLS-1$ for (String arg : args) { if (arg.startsWith("-log:")) { //$NON-NLS-1$ String key = arg.substring(5); if (levels.containsKey(key)) { return levels.get(key); }/*ww w. j a v a 2 s. co m*/ } } return SimpleLog.LOG_LEVEL_INFO; }
From source file:Main.java
public static String resolveFileName(Uri uri, Activity activity) { String filename = null;/*from www . ja va 2 s . c om*/ String uriString = uri.toString(); if (uriString.startsWith("content://")) { Cursor cursor = null; try { cursor = activity.getContentResolver().query(uri, null, null, null, null); if (cursor != null && cursor.moveToFirst()) { String mimeType = MimeTypeMap.getSingleton() .getExtensionFromMimeType(activity.getContentResolver().getType(uri)); filename = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)); if (mimeType != null && !filename.endsWith("." + mimeType)) { filename += "." + mimeType; } } } finally { if (cursor != null) { cursor.close(); } } } else if (uriString.startsWith("file://")) { filename = (new File(uriString)).getName(); } return filename; }
From source file:Main.java
public static String getModel(String hwRev) { //TODO: get real data? String model;//from w ww .jav a 2 s . co m if (hwRev.startsWith("snowy")) { model = "pebble_time_black"; } else if (hwRev.startsWith("spalding")) { model = "pebble_time_round_black_20mm"; } else if (hwRev.startsWith("silk")) { model = "pebble2_black"; } else if (hwRev.startsWith("robert")) { model = "pebble_time2_black"; } else { model = "pebble_black"; } return model; }
From source file:Main.java
public static List<String> getAllTables(Uri uri) { List<String> result = new ArrayList<String>(); String mainTable = uri.getLastPathSegment(); result.add(mainTable);/*from w w w . ja v a2s . co m*/ Set<String> queryParameterNames = getQueryParameterNames(uri); Iterator<String> iterator = queryParameterNames.iterator(); while (iterator.hasNext()) { String table = iterator.next(); if (table.startsWith(TABLE)) { result.add(table.replaceFirst(TABLE, "")); } } return result; }
From source file:Main.java
public static String getDeviceName() { String manufacturer = Build.MANUFACTURER; String model = Build.MODEL; if (model.startsWith(manufacturer)) { String temp = capitalize(model); temp = temp.replaceAll(" ", ""); return temp; } else {/*w ww . java2 s.c o m*/ String temp = capitalize(manufacturer) + " " + model; temp = temp.replaceAll(" ", ""); return temp; } }
From source file:com.gopivotal.cloudfoundry.test.support.util.JdbcUrlNormalizer.java
/** * Normalize a JDBC URL to account for differences in underlying implementations when testing. The normalization * algorithm includes removing the {@literal jdbc} prefix and any query parameters, leaving the core part of the URL * (i.e. scheme, host, port, and path)./*from w w w . ja va2 s .c o m*/ * * @param raw the raw URL * * @return a normalized URL */ public static URI normalize(String raw) { String modified = raw; if (modified.startsWith("jdbc:")) { modified = modified.replaceFirst("jdbc:", ""); } if (modified.startsWith("postgres:")) { modified = modified.replaceFirst("postgres:", "postgresql:"); } if (modified.contains("@")) { modified = modified.replaceFirst("/[^/@]*@", "/"); } if (modified.contains("?")) { modified = modified.substring(0, modified.indexOf('?')); } return URI.create(modified); }
From source file:io.stallion.plugins.javascript.JsFileReader.java
public static String readToString(String file, String pluginFolder) { if (!file.startsWith(Settings.instance().getTargetFolder() + "/js") && !file.startsWith(Settings.instance().getTargetFolder() + "/plugins")) { throw new UsageException("You can cannot access the file " + file + " from this location"); }/*from w w w . j av a 2 s . c o m*/ if (!empty(pluginFolder)) { if (!file.startsWith(pluginFolder)) { throw new UsageException("File " + file + " is not in the javascript folder " + pluginFolder); } } if (!file.endsWith(".js")) { throw new UsageException("This is not a .js file: " + file); } try { return FileUtils.readFileToString(new File(file), "UTF-8"); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:Main.java
/** * Return ARGB values in int array//from w ww . j av a 2 s. c o m * @param argb Color in HEX format (either with or without alpha, e.g. * #CCCCCC or #ffCCCCCC. * @return */ private static int[] getARGBComponents(String argb) { if (argb.startsWith("#")) { argb = argb.replace("#", ""); } int alpha = -1, red = -1, green = -1, blue = -1; if (argb.length() == 8) { alpha = Integer.parseInt(argb.substring(0, 2), 16); red = Integer.parseInt(argb.substring(2, 4), 16); green = Integer.parseInt(argb.substring(4, 6), 16); blue = Integer.parseInt(argb.substring(6, 8), 16); } else if (argb.length() == 6) { alpha = 255; red = Integer.parseInt(argb.substring(0, 2), 16); green = Integer.parseInt(argb.substring(2, 4), 16); blue = Integer.parseInt(argb.substring(4, 6), 16); } int[] components = { alpha, red, green, blue }; return components; }
From source file:Main.java
/** * Encodes a path according to URI RFC 2396. * //w ww . jav a 2 s . c o m * If the received path doesn't start with "/", the method adds it. * * @param remoteFilePath Path * @return Encoded path according to RFC 2396, always starting with "/" */ public static String encodePath(String remoteFilePath) { String encodedPath = Uri.encode(remoteFilePath, "/"); if (!encodedPath.startsWith("/")) encodedPath = "/" + encodedPath; return encodedPath; }
From source file:com.mobilecashout.osprey.plugin.RolesUtil.java
public static ImmutablePair<String, String[]> parseCommandRoles(String command) { String[] roles = { "all" }; if (command.startsWith(":")) { String[] parts = command.split("\\s", 2); roles = parts[0].substring(1).split(","); if (parts.length == 2) { command = parts[1];//from w w w. j a v a2 s . c o m } else { command = ""; } } return new ImmutablePair<>(command, roles); }