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.apache.kylin.monitor.QueryParser.java
public void parseQueryLog(String filePath, String dPath) throws ParseException, IOException { logger.info("Start parsing file " + filePath + " !"); // writer config init FileSystem fs = this.getHdfsFileSystem(); org.apache.hadoop.fs.Path resultStorePath = new org.apache.hadoop.fs.Path(dPath); OutputStreamWriter writer = new OutputStreamWriter(fs.append(resultStorePath)); CSVWriter cwriter = new CSVWriter(writer, '|', CSVWriter.NO_QUOTE_CHARACTER); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS"); Pattern p_query_start = Pattern.compile("^\\[.*\\]:\\[(.*),.*\\]\\[.*\\]\\[.*QueryService.logQuery.*\\].*"); Pattern p_query_end = Pattern.compile("^Message:(.*)$"); Pattern p_query_body = Pattern.compile( "^\\[.*\\]:\\[((\\d{4}-\\d{2}-\\d{2}).*)\\]\\[.*\\]\\[.*\\].*\n^=+\\[QUERY\\]=+\n^SQL:(.*)\n^User:(.*)\n^Success:(.*)\n^Duration:(.*)\n^Project:(.*)\n^(Realization Names|Cube Names): \\[(.*)\\]\n^Cuboid Ids: \\[(.*)\\]\n^Total scan count:(.*)\n^Result row count:(.*)\n^Accept Partial:(.*)\n(^Is Partial Result:(.*)\n)?^Hit Cache:(.*)\n^Message:(.*)", Pattern.MULTILINE); Matcher m_query_start = p_query_start.matcher(""); Matcher m_query_end = p_query_end.matcher(""); Matcher m_query_body = p_query_body.matcher(""); boolean query_start = false; StringBuffer query_body = new StringBuffer(""); Path path = Paths.get(filePath); try {/*from w w w. j a v a 2 s .c om*/ BufferedReader reader = Files.newBufferedReader(path, ENCODING); String line = null; while ((line = reader.readLine()) != null) { m_query_start.reset(line); //reset the input m_query_end.reset(line); // set start flag ,clear StringBuffer if (m_query_start.find()) { query_start = true; query_body = new StringBuffer(""); } if (query_start) { query_body.append(line + "\n"); } if (m_query_end.find()) { query_start = false; m_query_body.reset(query_body); logger.info("parsing query..."); logger.info(query_body); // skip group(8) and group(14) if (m_query_body.find()) { ArrayList<String> groups = new ArrayList<String>(); int grp_count = m_query_body.groupCount(); for (int i = 1; i <= grp_count; i++) { if (i != 8 && i != 14) { String grp_item = m_query_body.group(i); grp_item = grp_item == null ? "" : grp_item.trim(); groups.add(grp_item); } } long start_time = format.parse(groups.get(0)).getTime() - (int) (Double.parseDouble(groups.get(5)) * 1000); groups.set(0, format.format(new Date(start_time))); groups.add(DEPLOY_ENV); String[] recordArray = groups.toArray(new String[groups.size()]); // write to hdfs cwriter.writeNext(recordArray); } } } } catch (IOException ex) { logger.info("Failed to write to hdfs:", ex); } finally { if (writer != null) { writer.close(); } if (cwriter != null) { cwriter.close(); } if (fs != null) { fs.close(); } } logger.info("Finish parsing file " + filePath + " !"); }
From source file:org.zaproxy.zap.extension.ascanrulesAlpha.CloudMetadataScanner.java
private static HttpMethod createRequestMethod(HttpRequestHeader header, HttpBody body, HttpMethodParams params) throws URIException { HttpMethod httpMethod = new ZapGetMethod(); httpMethod.setURI(header.getURI());//from ww w. ja va2 s. co m httpMethod.setParams(params); params.setVersion(HttpVersion.HTTP_1_1); String msg = header.getHeadersAsString(); String[] split = Pattern.compile("\\r\\n", Pattern.MULTILINE).split(msg); String token = null; String name = null; String value = null; int pos = 0; for (int i = 0; i < split.length; i++) { token = split[i]; if (token.equals("")) { continue; } if ((pos = token.indexOf(":")) < 0) { return null; } name = token.substring(0, pos).trim(); value = token.substring(pos + 1).trim(); httpMethod.addRequestHeader(name, value); } if (body != null && body.length() > 0 && (httpMethod instanceof EntityEnclosingMethod)) { EntityEnclosingMethod post = (EntityEnclosingMethod) httpMethod; post.setRequestEntity(new ByteArrayRequestEntity(body.getBytes())); } httpMethod.setFollowRedirects(false); return httpMethod; }
From source file:com.swordlord.gozer.databinding.DataBindingMember.java
private void parseBindingMember() { // probably throw error in this case? -> no. DataBinding can be NULL! if (_strDataBindingMember == null) { return;/* ww w. jav a 2 s . co m*/ } Pattern pattern = Pattern.compile( "^(@)?([a-z_0-9]*)(\\{[(\\?)?a-z_0-9,:='%\\s@\\[\\]\\(\\)]*\\})?(\\[[0-9]*\\])?$", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); String[] bmElements = _strDataBindingMember.split("\\."); if (bmElements.length == 0) { LOG.error("Split of binding member return 0 elements: " + _strDataBindingMember); return; } // reset this, is no problem since works with lazy initialisation _strBindingPathName = null; int iElement = 0; for (String strBindingMemberElement : bmElements) { Matcher matcher = pattern.matcher(strBindingMemberElement); if (!matcher.find()) { LOG.error("DataBinding parser can't parse binding member: " + strBindingMemberElement); return; } if (matcher.groupCount() != 4) { LOG.error("Wrong group count during parsing of binding member element: " + strBindingMemberElement + " in binding member: " + _strDataBindingMember); return; } DataBindingElement element = new DataBindingElement(); element.setPathElement(matcher.group(2)); String strFilter = matcher.group(3); if ((strFilter != null) && (strFilter.length() > 2)) { try { element.setFilter(strFilter.substring(1, strFilter.length() - 1)); } catch (IndexOutOfBoundsException e) { LOG.error("strFilter is defect: " + strFilter); LOG.debug(e.getMessage()); return; } } String strRowNumber = matcher.group(4); if ((strRowNumber != null) && (strRowNumber.length() > 2)) { try { element.setRowNumber(Integer.parseInt(strRowNumber.substring(1, strRowNumber.length() - 1))); } catch (NumberFormatException e) { LOG.error("RowNumber is not of type integer: " + strRowNumber); LOG.debug(e.getMessage()); return; } catch (IndexOutOfBoundsException e) { LOG.error("RowNumber is defect: " + strRowNumber); LOG.debug(e.getMessage()); return; } } else { if (iElement < bmElements.length - 1) { // wrong syntax, add 0 on our own element.setRowNumber(0); //element.isField(true); } else { element.setField(true); } } _dataBindingElements.add(element); iElement++; } }
From source file:de.micromata.genome.gwiki.tools.PatchVersion.java
public void patch(Pair<String, String> p) { String f = readFile(p.getFirst()); Pattern pattern = Pattern.compile(p.getSecond(), Pattern.MULTILINE | Pattern.DOTALL); Matcher m = pattern.matcher(f); if (m.matches() == false) { System.out.println("Does not match: " + p.getFirst() + "; Pattern: " + p.getSecond()); return;// w ww . java 2 s . c o m } String g1 = m.group(1); String g2 = m.group(2); String g3 = m.group(3); if (StringUtils.isNotEmpty(expected) == true) { if (expected.equals(g2) == false) { System.out.println("Do not patch " + p.getFirst() + ". Expect: " + expected + "; got: " + g2); return; } } String ret = g1 + version + g3; System.out.println("Patched " + p.getFirst() + " from " + g2 + " to " + version); if (testOnly == true) { return; } writeFile(p.getFirst(), ret); }
From source file:org.opennms.web.rest.v1.AcknowledgmentRestServiceIT.java
@Test @JUnitTemporaryDatabase//from w ww.j a v a 2 s . c o m public void testAcknowlegeAlarm() throws Exception { final Pattern p = Pattern.compile("^.*<ackTime>(.*?)</ackTime>.*$", Pattern.DOTALL & Pattern.MULTILINE); sendData(POST, MediaType.APPLICATION_FORM_URLENCODED, "/acks", "alarmId=1&action=ack", 200); // Try to fetch a non-existent ack, get 404 Not Found String xml = sendRequest(GET, "/acks/999999", 404); xml = sendRequest(GET, "/acks/count", 200); // {@link DatabasePopulator} adds one ack so we have 2 total assertEquals("2", xml); Integer newAckId = null; for (OnmsAcknowledgment ack : getXmlObject(JaxbUtils.getContextFor(OnmsAcknowledgmentCollection.class), "/acks", 200, OnmsAcknowledgmentCollection.class).getObjects()) { if (AckType.UNSPECIFIED.equals(ack.getAckType())) { // Ack from DatabasePopulator assertEquals(AckAction.UNSPECIFIED, ack.getAckAction()); assertEquals("admin", ack.getAckUser()); } else if (AckType.ALARM.equals(ack.getAckType())) { // Ack that we just created assertEquals(new Integer(1), ack.getRefId()); assertEquals(AckAction.ACKNOWLEDGE, ack.getAckAction()); newAckId = ack.getId(); } else { fail("Unrecognized alarm type: " + ack.getAckType().toString()); } } if (newAckId == null) { fail("Couldn't determine ID of new ack"); } xml = sendRequest(GET, "/acks/" + newAckId, 200); xml = sendRequest(GET, "/alarms/1", new HashMap<String, String>(), 200); Matcher m = p.matcher(xml); assertTrue(m.matches()); assertTrue(m.group(1).length() > 0); sendData(POST, MediaType.APPLICATION_FORM_URLENCODED, "/acks", "alarmId=1&action=unack", 200); xml = sendRequest(GET, "/alarms/1", new HashMap<String, String>(), 200); m = p.matcher(xml); assertFalse(m.matches()); // POST with no argument, this will ack by default sendData(POST, MediaType.APPLICATION_FORM_URLENCODED, "/acks", "alarmId=1", 200); xml = sendRequest(GET, "/alarms/1", new HashMap<String, String>(), 200); m = p.matcher(xml); assertTrue(m.matches()); }
From source file:org.solenopsis.checkstyle.checks.regexp.RegexpCheck.java
/** * Set the format to the specified regular expression. * @param format a {@code String} value//from w w w . j av a2 s. c om * @throws org.apache.commons.beanutils.ConversionException unable to parse format */ public final void setFormat(String format) { this.format = format; regexp = CommonUtils.createPattern(format, Pattern.MULTILINE); }
From source file:Normalization.TextNormalization.java
public String removeNonEnglishWordsFromString(String content) { String utf8tweet = ""; try {/*from w ww .j av a 2s .c om*/ byte[] utf8Bytes = content.getBytes("UTF-8"); utf8tweet = new String(utf8Bytes, "UTF-8"); } catch (UnsupportedEncodingException e) { } final String regex = "[\\W]"; final Pattern unicodeOutliers = Pattern.compile(regex, Pattern.MULTILINE | Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE); Matcher unicodeOutlierMatcher = unicodeOutliers.matcher(utf8tweet); utf8tweet = unicodeOutlierMatcher.replaceAll(" "); return utf8tweet; }
From source file:net.sourceforge.jwbf.actions.mw.queries.GetBacklinkTitles.java
/** * gets the information about a follow-up page from a provided api response. * If there is one, the information for the next page parameter is * added to the nextPageInfo field.// w w w . j a va 2 s. co m * * @param s text for parsing */ protected void parseHasMore(final String s) { // get the blcontinue-value Pattern p = Pattern.compile( "<query-continue>.*?" + "<backlinks *blcontinue=\"([^\"]*)\" */>" + ".*?</query-continue>", Pattern.DOTALL | Pattern.MULTILINE); Matcher m = p.matcher(s); if (m.find()) { nextPageInfo = m.group(1); } }
From source file:net.sourceforge.jwbf.actions.mw.queries.GetAllPageTitles.java
/** * gets the information about a follow-up page from a provided api response. * If there is one, a new request is added to msgs by calling generateRequest. * /*from w w w . j a v a 2 s . c om*/ * @param s text for parsing */ protected void parseHasMore(final String s) { // get the blcontinue-value Pattern p = Pattern.compile( "<query-continue>.*?" + "<allpages *apfrom=\"([^\"]*)\" */>" + ".*?</query-continue>", Pattern.DOTALL | Pattern.MULTILINE); Matcher m = p.matcher(s); if (m.find()) { nextPageInfo = m.group(1); } }
From source file:com.agiletec.aps.system.services.pagemodel.PageModelManager.java
@Override public List getGuiFragmentUtilizers(String guiFragmentCode) throws ApsSystemException { List<PageModel> utilizers = new ArrayList<PageModel>(); try {// w w w . j a v a 2 s. co m Iterator<PageModel> it = this.getPageModels().iterator(); while (it.hasNext()) { PageModel pModel = it.next(); String template = pModel.getTemplate(); if (StringUtils.isNotBlank(template)) { Pattern pattern = Pattern.compile("<@wp\\.fragment.*code=\"" + guiFragmentCode + "\".*/>", Pattern.MULTILINE); Matcher matcher = pattern.matcher(template); if (matcher.find()) { utilizers.add(pModel); } } } } catch (Throwable t) { _logger.error("Error extracting utilizers", t); throw new ApsSystemException("Error extracting utilizers", t); } return utilizers; }