List of usage examples for java.util.regex Pattern MULTILINE
int MULTILINE
To view the source code for java.util.regex Pattern MULTILINE.
Click Source Link
From source file:org.goko.core.rs274ngcv3.parser.GCodeLexer.java
/** * Constructor/*from w w w. j av a2s . c om*/ */ public GCodeLexer() { multilineCommentPattern = Pattern.compile(GCodeTokenType.MULTILINE_COMMENT.getPattern(), Pattern.MULTILINE | Pattern.DOTALL); simpleCommentPattern = Pattern.compile(GCodeTokenType.SIMPLE_COMMENT.getPattern()); lineNumberPattern = Pattern.compile(GCodeTokenType.LINE_NUMBER.getPattern()); wordPattern = Pattern.compile(GCodeTokenType.WORD.getPattern()); spacePattern = Pattern.compile("^[ ]+"); }
From source file:org.apache.hadoop.hive.ql.exec.mr.Throttle.java
/** * Fetch http://tracker.om:/gc.jsp?threshold=period. *///from w ww . j a v a 2 s . co m public static void checkJobTracker(JobConf conf, Log LOG) { try { byte[] buffer = new byte[1024]; int threshold = conf.getInt("mapred.throttle.threshold.percent", DEFAULT_MEMORY_GC_PERCENT); int retry = conf.getInt("mapred.throttle.retry.period", DEFAULT_RETRY_PERIOD); // If the threshold is 100 percent, then there is no throttling if (threshold == 100) { return; } // This is the Job Tracker URL String tracker = JobTrackerURLResolver.getURL(conf) + "/gc.jsp?threshold=" + threshold; while (true) { // read in the first 1K characters from the URL URL url = new URL(tracker); LOG.debug("Throttle: URL " + tracker); InputStream in = null; try { in = url.openStream(); in.read(buffer); in.close(); in = null; } finally { IOUtils.closeStream(in); } String fetchString = new String(buffer); // fetch the xml tag <dogc>xxx</dogc> Pattern dowait = Pattern.compile("<dogc>", Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE); String[] results = dowait.split(fetchString); if (results.length != 2) { throw new IOException( "Throttle: Unable to parse response of URL " + url + ". Get retuned " + fetchString); } dowait = Pattern.compile("</dogc>", Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE); results = dowait.split(results[1]); if (results.length < 1) { throw new IOException( "Throttle: Unable to parse response of URL " + url + ". Get retuned " + fetchString); } // if the jobtracker signalled that the threshold is not exceeded, // then we return immediately. if (results[0].trim().compareToIgnoreCase("false") == 0) { return; } // The JobTracker has exceeded its threshold and is doing a GC. // The client has to wait and retry. LOG.warn("Job is being throttled because of resource crunch on the " + "JobTracker. Will retry in " + retry + " seconds.."); Thread.sleep(retry * 1000L); } } catch (Exception e) { LOG.warn("Job is not being throttled. " + e); } }
From source file:com.redhat.lightblue.eval.RegexEvaluator.java
/** * Constructs evaluator for {field op value} style comparison * * @param expr The expression//from w ww . j ava 2s.c om * @param md Entity metadata * @param context The path relative to which the expression will be * evaluated */ public RegexEvaluator(RegexMatchExpression expr, FieldTreeNode context) { this.relativePath = expr.getField(); fieldMd = context.resolve(relativePath); if (fieldMd == null) { throw new EvaluationError(expr, CrudConstants.ERR_FIELD_NOT_THERE + relativePath); } int flags = 0; if (expr.isCaseInsensitive()) { flags |= Pattern.CASE_INSENSITIVE; } if (expr.isMultiline()) { flags |= Pattern.MULTILINE; } if (expr.isExtended()) { flags |= Pattern.COMMENTS; } if (expr.isDotAll()) { flags |= Pattern.DOTALL; } regex = Pattern.compile(expr.getRegex(), flags); LOGGER.debug("ctor {} {}", relativePath, regex); }
From source file:com.aurel.track.fieldType.runtime.matchers.run.StringMatcherRT.java
private void setPattern(String searchText) throws PatternSyntaxException { pattern = Pattern.compile(searchText, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); }
From source file:com.norconex.importer.ImporterTest.java
@Before public void setUp() throws Exception { ImporterConfig config = new ImporterConfig(); config.setPostParseHandlers(new IDocumentTransformer[] { new IDocumentTransformer() { @Override/* ww w . j ava 2 s. co m*/ public void transformDocument(String reference, InputStream input, OutputStream output, ImporterMetadata metadata, boolean parsed) throws ImporterHandlerException { try { // Clean up what we know is extra noise for a given format Pattern pattern = Pattern.compile("[^a-zA-Z ]", Pattern.MULTILINE); String txt = IOUtils.toString(input); txt = pattern.matcher(txt).replaceAll(""); txt = txt.replaceAll("DowntheRabbitHole", ""); txt = StringUtils.replace(txt, " ", ""); txt = StringUtils.replace(txt, "httppdfreebooksorg", ""); IOUtils.write(txt, output); } catch (IOException e) { throw new ImporterHandlerException(e); } } } }); importer = new Importer(config); }
From source file:com.yahoo.flowetl.core.util.RegexUtil.java
/** * Gets the pattern for the given string by providing the rules to do * extraction./*from www. j a v a 2 s . c o m*/ * * This is similar to how php does regex to match you provide in the format * /REGEX/options where options currently are "i" for case insensitive and * "u" for unicode and "m" for multiline and "s" for dotall and the value * inside the // is the regex to use * * @param str * the string to parsed the pattern out of * * @param cache * whether to cache the compiled pattern * * @return the pattern * * @throws PatternSyntaxException * * the pattern syntax exception if it has wrong syntax */ public static Pattern getPattern(String str, boolean cache) throws PatternSyntaxException { if (str == null) { return null; } // see if we made it before... Pattern p = compiledPats.get(str); if (p != null) { return p; } Matcher mat = patExtractor.matcher(str); if (mat.matches() == false) { throw new PatternSyntaxException("Invalid syntax provided", str, -1); } String regex = mat.group(1); String opts = mat.group(2); int optsVal = 0; if (StringUtils.contains(opts, "i")) { optsVal |= Pattern.CASE_INSENSITIVE; } if (StringUtils.contains(opts, "u")) { optsVal |= Pattern.UNICODE_CASE; } if (StringUtils.contains(opts, "m")) { optsVal |= Pattern.MULTILINE; } if (StringUtils.contains(opts, "s")) { optsVal |= Pattern.DOTALL; } // compile and store it p = Pattern.compile(regex, optsVal); if (cache) { compiledPats.put(str, p); } return p; }
From source file:org.goko.core.gcode.rs274ngcv3.parser.GCodeLexer.java
/** * Constructor//from w ww . j av a 2 s. c om */ public GCodeLexer() { multilineCommentPattern = Pattern.compile(GCodeTokenType.MULTILINE_COMMENT.getPattern(), Pattern.MULTILINE | Pattern.DOTALL); simpleCommentPattern = Pattern.compile(GCodeTokenType.SIMPLE_COMMENT.getPattern()); lineNumberPattern = Pattern.compile(GCodeTokenType.LINE_NUMBER.getPattern()); wordPattern = Pattern.compile(GCodeTokenType.WORD.getPattern()); spacePattern = Pattern.compile("^[ ]+"); percentPattern = Pattern.compile(GCodeTokenType.PERCENT.getPattern()); }
From source file:org.kalypsodeegree_impl.io.sax.test.SaxParserTestUtils.java
private static void assertContentEquals(final String expected, final String actual) { final Pattern whitespacePattern = Pattern.compile("\\s", Pattern.MULTILINE); final String actualCleaned = whitespacePattern.matcher(actual).replaceAll(""); final String expectedCleaned = whitespacePattern.matcher(expected).replaceAll(""); Assert.assertEquals(expectedCleaned, actualCleaned); }
From source file:no.trank.openpipe.wikipedia.producer.meta.RssMetaParser.java
public String findMd5(String md5sums) { if (md5sums != null) { final Matcher matcher = Pattern.compile("^([0-9a-fA-F]{32})\\s+" + fileName + '$', Pattern.MULTILINE) .matcher(md5sums);// www . j a va 2s . co m if (matcher.find()) { return matcher.group(1); } } return null; }
From source file:org.parosproxy.paros.extension.history.ProxyListenerLog.java
public void setFilter(String filter) { if (filter == null || filter.equals("")) { pattern = null;/*w w w . j a v a 2 s . com*/ } else { pattern = Pattern.compile(filter, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); } }