List of usage examples for java.lang String matches
public boolean matches(String regex)
From source file:com.quatico.base.aem.test.api.values.TestFile.java
public static String path(String... segments) { StringBuilder buf = new StringBuilder(); for (int count = 0, idx = 0; idx < segments.length; idx++) { String cur = segments[idx]; if (StringUtils.isBlank(cur) && count == 0 || StringUtils.isNotBlank(cur) && buf.length() > 1) { buf.append(File.separator); }// w w w .j a v a2s. com if (StringUtils.isNotBlank(cur)) { buf.append(cur); } count++; } String result = buf.toString(); if (result.matches("^\\\\[\\w]{1}:")) { // java.io.File cannot handle leading slashes before drive letters on Windows result = result.substring(1); } return result.replace(ILLEGAL_FILE_SEPARATOR, File.separatorChar); }
From source file:com.google.oacurl.util.LoggingConfig.java
public static void enableWireLog() { // For clarity, override the formatter so that it doesn't print the // date and method name for each line, and then munge the output a little // bit to make it nicer and more curl-like. Formatter wireFormatter = new Formatter() { @Override//from w w w .j av a 2 s . com public String format(LogRecord record) { String message = record.getMessage(); String trimmedMessage = message.substring(">> \"".length(), message.length() - 1); if (trimmedMessage.matches("[0-9a-f]+\\[EOL\\]")) { return ""; } trimmedMessage = trimmedMessage.replace("[EOL]", ""); if (trimmedMessage.isEmpty()) { return ""; } StringBuilder out = new StringBuilder(); out.append(message.charAt(0)); out.append(" "); out.append(trimmedMessage); out.append(System.getProperty("line.separator")); return out.toString(); } }; ConsoleHandler wireHandler = new ConsoleHandler(); wireHandler.setLevel(Level.FINE); wireHandler.setFormatter(wireFormatter); Logger wireLogger = Logger.getLogger("org.apache.http.wire"); wireLogger.setLevel(Level.FINE); wireLogger.setUseParentHandlers(false); wireLogger.addHandler(wireHandler); }
From source file:gov.wa.wsdot.cms.utils.Migration.java
/** * Delete resource files named after GUIDs. */// ww w . j ava 2s.c om public static void deleteResources(String archiveFolder) { File files[] = (new File(archiveFolder)).listFiles(new FilenameFilter() { @Override public boolean accept(File archiveFolder, String name) { return name.matches("res[A-Z0-9]{32}.*"); } }); System.out.println("Deleting resources."); for (File file : files) { if (!file.delete()) { System.out.println("Can't remove: " + file.getAbsolutePath()); } else { System.out.println("Removed: " + file.getAbsolutePath()); } } System.out.println("Done."); }
From source file:android.example.hlsmerge.crypto.Main.java
private static CommandLine parseCommandLine(String[] args) { CommandLineParser parser = new PosixParser(); CommandLine commandLine = null;//from www.java2 s. c om Option help = new Option(OPT_HELP, "help", false, "print this message."); Option silent = new Option(OPT_SILENT, "silent", false, "silent mode."); Option overwrite = new Option(OPT_OVERWRITE, false, "overwrite output files."); Option key = OptionBuilder.withArgName(ARG_KEY).withLongOpt(OPT_KEY_LONG).hasArg() .withDescription("force use of the supplied AES-128 key.").create(OPT_KEY); Option outFile = OptionBuilder.withArgName(ARG_OUT_FILE).withLongOpt(OPT_OUT_FILE_LONG).hasArg() .withDescription("join all transport streams to one file.").create(OPT_OUT_FILE); Options options = new Options(); options.addOption(help); options.addOption(silent); options.addOption(overwrite); options.addOption(key); options.addOption(outFile); try { commandLine = parser.parse(options, args); if (commandLine.hasOption(OPT_HELP) || (commandLine.getArgs().length < 1)) { new HelpFormatter().printHelp(CLI_SYNTAX, options); System.exit(0); } if (commandLine.hasOption(OPT_KEY)) { String optKey = commandLine.getOptionValue(OPT_KEY); if (!optKey.matches("[0-9a-fA-F]{32}")) { System.out.printf( "Bad key format: \"%s\". Expected 32-character hex format.\nExample: -key 12ba7f70db4740dec4aab4c5c2c768d9", optKey); System.exit(1); } } } catch (ParseException e) { System.out.println(e.getMessage()); new HelpFormatter().printHelp(CLI_SYNTAX, options); System.exit(1); } return commandLine; }
From source file:de.tudarmstadt.ukp.experiments.dip.wp1.documents.helpers.boilerplateremoval.impl.Utils.java
/** * Returns `True` if string contains only white-space characters or is * empty. Otherwise `False` is returned. * * @param text/*from www . j a va 2 s . co m*/ * @return */ // TODO remove public static boolean is_blank(String text) { return (text.isEmpty() || text.matches("\\s+")); }
From source file:Main.java
public static int[] getBitmapSize(String path, int targetWidth, int targetHeight) { if (TextUtils.isEmpty(path)) { return null; }/*w w w .j av a2 s. c o m*/ if (path.matches("^\\w+$")) { return null; } return getBitmapSize(new File(path), targetWidth, targetHeight); }
From source file:com.canoo.webtest.plugins.emailtest.EmailMessageStructureFilter.java
private static void appendUuencodedAttachments(final StringBuffer buf, final String content) { // iterate over string looking for ^begin ddd$ final String lineStr = "(^.*$)"; final String startUuencodeStr = "begin \\d\\d\\d .*"; final Pattern linePattern = Pattern.compile(lineStr, Pattern.MULTILINE); final Matcher matcher = linePattern.matcher(content); while (matcher.find()) { final String line = matcher.group(0); if (line.matches(startUuencodeStr)) { final int lastSpace = line.lastIndexOf(" "); final String filename = line.substring(lastSpace + 1); buf.append(" <part type=\"uuencoded\" filename=\""); buf.append(filename).append("\"/>").append(LS); }/*from w w w . ja v a2s .co m*/ } }
From source file:biz.gabrys.maven.plugin.util.io.RegexFileFilter.java
/** * Checks whether a file path matches at least one patter from patterns. * @param path the file path to check./* ww w. jav a2s . co m*/ * @param patterns the regular expressions patterns. * @return {@code true} whether the file path matches at least one patter from patterns, otherwise {@code false}. * @since 1.2 */ protected static boolean matches(final String path, final String[] patterns) { for (final String pattern : patterns) { if (path.matches(pattern)) { return true; } } return false; }
From source file:Main.java
public static Boolean hasBuildPropValue(String buildProp) throws Exception { Boolean has = false;// ww w .ja v a2s.c o m String buildprop = ""; buildprop = getStringFromFile(BUILD_PROP); if (buildprop.matches(buildProp + "=.+$")) has = true; return has; }
From source file:ch.cyberduck.core.io.Checksum.java
public static Checksum parse(final String hash) { if (StringUtils.isBlank(hash)) { return Checksum.NONE; }/*from ww w. j ava2 s.c om*/ if (hash.matches("[a-fA-F0-9]{32}")) { return new Checksum(HashAlgorithm.md5, hash); } if (hash.matches("[a-fA-F0-9]{40}")) { return new Checksum(HashAlgorithm.sha1, hash); } if (hash.matches("[A-Fa-f0-9]{64}")) { return new Checksum(HashAlgorithm.sha256, hash); } if (hash.matches("[A-Fa-f0-9]{128}")) { return new Checksum(HashAlgorithm.sha512, hash); } if (hash.matches("[a-fA-F0-9]{8}")) { return new Checksum(HashAlgorithm.crc32, hash); } log.warn(String.format("Failure to detect algorithm for checksum %s", hash)); return Checksum.NONE; }