List of usage examples for org.apache.commons.lang3 StringUtils isEmpty
public static boolean isEmpty(final CharSequence cs)
Checks if a CharSequence is empty ("") or null.
StringUtils.isEmpty(null) = true StringUtils.isEmpty("") = true StringUtils.isEmpty(" ") = false StringUtils.isEmpty("bob") = false StringUtils.isEmpty(" bob ") = false
NOTE: This method changed in Lang version 2.0.
From source file:dtu.ds.warnme.app.utils.SecurityUtils.java
public static String hashMD5Base64(String stringToHash) { if (StringUtils.isEmpty(stringToHash)) { return StringUtils.EMPTY; }/*from ww w. j a v a 2 s . co m*/ try { byte[] bytes = stringToHash.getBytes(CHARSET_UTF8); byte[] sha512bytes = DigestUtils.md5(bytes); byte[] base64bytes = Base64.encodeBase64(sha512bytes); return new String(base64bytes, CHARSET_UTF8); } catch (UnsupportedEncodingException e) { Log.e(TAG, "This system does not support required hashing algorithms.", e); throw new IllegalStateException("This system does not support required hashing algorithms.", e); } }
From source file:at.bitfire.davdroid.DavUtils.java
public static String lastSegmentOfUrl(@NonNull String url) { // the list returned by HttpUrl.pathSegments() is unmodifiable, so we have to create a copy List<String> segments = new LinkedList<>(HttpUrl.parse(url).pathSegments()); Collections.reverse(segments); for (String segment : segments) if (!StringUtils.isEmpty(segment)) return segment; return "/"; }
From source file:com.huangyunkun.jviff.config.ConfigManager.java
public static Config getConfigFromFile(String filePath) throws IOException { ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); Config config = mapper.readValue(new File(filePath), Config.class); if (StringUtils.isEmpty(config.getOutputDir())) { config.setOutputDir(Files.createTempDir().getAbsolutePath()); }//from w ww .j a v a2 s . c om return config; }
From source file:com.jdom.util.collections.CollectionsUtil.java
public static Set<String> asSetFromLine(String line, char separator) { List<String> list = (StringUtils.isEmpty(line)) ? Collections.<String>emptyList() : Arrays.asList(StringUtils.split(line, separator)); return new HashSet<String>(list); }
From source file:com.baifendian.swordfish.common.utils.VerifyUtil.java
/** * ?/*from w w w .j a v a 2 s. c o m*/ * * @param str * @param pattern * @return */ public static boolean regexMatches(String str, Pattern pattern) { if (StringUtils.isEmpty(str)) { return false; } return pattern.matcher(str).matches(); }
From source file:io.apiman.manager.api.rest.impl.util.FieldValidator.java
/** * Validates an entity name.//w ww. java 2 s . co m * @param name * @throws InvalidNameException */ public static void validateName(String name) throws InvalidNameException { if (StringUtils.isEmpty(name)) { throw ExceptionFactory.invalidNameException(Messages.i18n.format("FieldValidator.EmptyNameError")); //$NON-NLS-1$ } }
From source file:com.qing.common.util.IPUtils.java
/** * ?IP?s// ww w. j a v a2 s . c o m * * @param request * @return IP? */ public static String getRemoteIp(HttpServletRequest request) { String ipString = request.getHeader("x-forwarded-for"); if (StringUtils.isEmpty(ipString) || "unknown".equalsIgnoreCase(ipString)) { ipString = request.getHeader("Proxy-Client-IP"); } if (StringUtils.isEmpty(ipString) || "unknown".equalsIgnoreCase(ipString)) { ipString = request.getHeader("WL-Proxy-Client-IP"); } if (StringUtils.isEmpty(ipString) || "unknown".equalsIgnoreCase(ipString)) { ipString = request.getRemoteAddr(); } // ??unknownip final String[] arr = ipString.split(","); for (final String str : arr) { if (!"unknown".equalsIgnoreCase(str)) { ipString = str; break; } } return ipString; }
From source file:com.orange.ocara.tools.AssetsHelper.java
/** * Copy the asset at the specified path to this app's data directory. If the * asset is a directory, its contents are also copied. *///w ww . j av a 2 s . c o m public static void copyAsset(AssetManager assetManager, String rootPath, String path, File targetFolder) throws IOException { String fullPath = StringUtils.isEmpty(path) ? rootPath : rootPath + File.separator + path; // If we have a directory, we make it and recurse. If a file, we copy its // contents. try { String[] contents = assetManager.list(fullPath); // The documentation suggests that list throws an IOException, but doesn't // say under what conditions. It'd be nice if it did so when the path was // to a file. That doesn't appear to be the case. If the returned array is // null or has 0 length, we assume the path is to a file. This means empty // directories will get turned into files. if (contents == null || contents.length == 0) { throw new IOException(); } // Recurse on the contents. for (String entry : contents) { String newPath = StringUtils.isEmpty(path) ? entry : path + File.separator + entry; copyAsset(assetManager, rootPath, newPath, targetFolder); } } catch (IOException e) { File file = new File(targetFolder, path); if (file.getParentFile() != null) { file.getParentFile().mkdirs(); } FileUtils.copyInputStreamToFile(assetManager.open(fullPath), file); } }
From source file:com.twosigma.beaker.core.Main.java
public static void main(String[] args) throws Exception { CommandLine options = parseCommandLine(args); final Integer portBase = options.hasOption("port-base") ? Integer.parseInt(options.getOptionValue("port-base")) : findPortBase(PORT_BASE_START_DEFAULT); final Boolean useKerberos = options.hasOption("disable-kerberos") ? !parseBoolean(options.getOptionValue("disable-kerberos")) : USE_KERBEROS_DEFAULT;// w ww .ja va 2s. co m final Boolean openBrowser = options.hasOption("open-browser") ? parseBoolean(options.getOptionValue("open-browser")) : OPEN_BROWSER_DEFAULT; final String useHttpsCert = options.hasOption("use-ssl-cert") ? options.getOptionValue("use-ssl-cert") : null; final String useHttpsKey = options.hasOption("use-ssl-key") ? options.getOptionValue("use-ssl-key") : null; final Boolean publicServer = options.hasOption("public-server"); final Boolean requirePassword = options.hasOption("require-password"); final String password = options.hasOption("password") ? options.getOptionValue("password") : null; final String listenInterface = options.hasOption("listen-interface") ? options.getOptionValue("listen-interface") : null; final Boolean portable = options.hasOption("portable"); final Boolean showZombieLogging = options.hasOption("show-zombie-logging"); // create preferences for beaker core from cli options and others // to be used by BeakerCoreConfigModule to initialize its config BeakerConfigPref beakerCorePref = createBeakerCoreConfigPref(useKerberos, publicServer, false, portBase, options.getOptionValue("default-notebook"), getPluginOptions(options), useHttpsCert, useHttpsKey, requirePassword, password, listenInterface, portable, showZombieLogging); WebAppConfigPref webAppPref = createWebAppConfigPref(portBase + BEAKER_SERVER_PORT_OFFSET, System.getProperty("user.dir") + "/src/main/web"); Injector injector = Guice.createInjector(new DefaultBeakerConfigModule(beakerCorePref), new DefaultWebServerConfigModule(webAppPref), new GeneralUtilsModule(), new WebServerModule(), new SerializerModule(), new GuiceCometdModule(), new URLConfigModule(beakerCorePref)); PluginServiceLocatorRest processStarter = injector.getInstance(PluginServiceLocatorRest.class); processStarter.setAuthToken(beakerCorePref.getAuthToken()); processStarter.start(); BeakerConfig bkConfig = injector.getInstance(BeakerConfig.class); writePID(bkConfig); Server server = injector.getInstance(Server.class); server.start(); // openBrower and show connection instruction message final String initUrl = bkConfig.getBaseURL(); if (openBrowser) { injector.getInstance(GeneralUtils.class).openUrl(initUrl); System.out.println("\nConnecting to " + initUrl); } else { System.out.println("\nBeaker hash " + bkConfig.getHash()); System.out.println("Beaker listening on " + initUrl); } if (publicServer && StringUtils.isEmpty(password)) { System.out.println("Submit this password: " + bkConfig.getPassword()); } System.out.println(""); }
From source file:forge.util.BuildInfo.java
/** * Get the current version of Forge.//from ww w . j a v a 2 s . c om * * @return a String representing the version specifier, or "SVN" if unknown. */ public static final String getVersionString() { String version = BuildInfo.class.getPackage().getImplementationVersion(); if (StringUtils.isEmpty(version)) { return "SVN"; } return version; }