List of usage examples for org.apache.hadoop.util StringUtils ESCAPE_CHAR
char ESCAPE_CHAR
To view the source code for org.apache.hadoop.util StringUtils ESCAPE_CHAR.
Click Source Link
From source file:com.chinamobile.bcbsp.bspcontroller.Counters.java
License:Apache License
/**Extracts a block (data enclosed within delimeters) ignoring escape * sequences. Throws ParseException if an incomplete block is found else * returns null./*from w w w. ja v a 2s . c o m*/ * @param str * split address to find * @param open * if the split is open * @param close * if the split is close * @param index * block write index. * @return blocks has got */ private static String getBlock(String str, char open, char close, IntWritable index) throws ParseException { StringBuilder split = new StringBuilder(); int next = StringUtils.findNext(str, open, StringUtils.ESCAPE_CHAR, index.get(), split); split.setLength(0); // clear the buffer if (next >= 0) { ++next; // move over '(' next = StringUtils.findNext(str, close, StringUtils.ESCAPE_CHAR, next, split); if (next >= 0) { ++next; // move over ')' index.set(next); return split.toString(); // found a block } else { throw new ParseException("Unexpected end of block", next); } } return null; // found nothing }
From source file:com.chinamobile.bcbsp.bspcontroller.Counters.java
License:Apache License
/** * Escapes all the delimiters for counters i.e {,[,(,),],} * @param string/*from w w w .j av a 2 s .co m*/ * counter record to escape. * @return * counter record has been escaped */ private static String escape(String string) { return StringUtils.escapeString(string, StringUtils.ESCAPE_CHAR, charsToEscape); }
From source file:com.chinamobile.bcbsp.bspcontroller.Counters.java
License:Apache License
/** * Unescapes all the delimiters for counters i.e {,[,(,),],} * @param string//from ww w . jav a2 s . c o m * counter record to unescape * @return unescaped counter record. */ private static String unescape(String string) { return StringUtils.unEscapeString(string, StringUtils.ESCAPE_CHAR, charsToEscape); }
From source file:org.apache.ambari.log4j.hadoop.mapreduce.jobhistory.MapReduceJobHistoryUpdater.java
License:Apache License
public static WorkflowContext buildWorkflowContext(JobSubmittedEvent historyEvent) { String workflowId = historyEvent.getWorkflowId().replace("\\", ""); if (workflowId.isEmpty()) return generateWorkflowContext(historyEvent); String workflowName = historyEvent.getWorkflowName().replace("\\", ""); String workflowNodeName = historyEvent.getWorkflowNodeName().replace("\\", ""); String workflowAdjacencies = StringUtils.unEscapeString(historyEvent.getWorkflowAdjacencies(), StringUtils.ESCAPE_CHAR, new char[] { '"', '=', '.' }); WorkflowContext context = new WorkflowContext(); context.setWorkflowId(workflowId);//ww w. j av a2 s. c o m context.setWorkflowName(workflowName); context.setWorkflowEntityName(workflowNodeName); WorkflowDag dag = new WorkflowDag(); Matcher matcher = adjPattern.matcher(workflowAdjacencies); while (matcher.find()) { WorkflowDagEntry dagEntry = new WorkflowDagEntry(); dagEntry.setSource(matcher.group(1).replace("\\", "")); String[] values = StringUtils.getStrings(matcher.group(2).replace("\\", "")); if (values != null) { for (String target : values) { dagEntry.addTarget(target); } } dag.addEntry(dagEntry); } if (dag.getEntries().isEmpty()) { WorkflowDagEntry wfDagEntry = new WorkflowDagEntry(); wfDagEntry.setSource(workflowNodeName); dag.addEntry(wfDagEntry); } context.setWorkflowDag(dag); return context; }
From source file:org.apache.ambari.TestJobHistoryParsing.java
License:Apache License
private static String log(String recordType, String[] keys, String[] values) { int length = recordType.length() + keys.length * 4 + 2; for (int i = 0; i < keys.length; i++) { values[i] = StringUtils.escapeString(values[i], StringUtils.ESCAPE_CHAR, charsToEscape); length += values[i].length() + keys[i].toString().length(); }/* w w w. j a va2 s.c o m*/ // We have the length of the buffer, now construct it. StringBuilder builder = new StringBuilder(length); builder.append(recordType); builder.append(DELIMITER); for (int i = 0; i < keys.length; i++) { builder.append(keys[i]); builder.append("=\""); builder.append(values[i]); builder.append("\""); builder.append(DELIMITER); } builder.append(LINE_DELIMITER_CHAR); return builder.toString(); }
From source file:org.apache.hama.bsp.Counters.java
License:Apache License
private static String getBlock(String str, char open, char close, IntWritable index) throws ParseException { StringBuilder split = new StringBuilder(); int next = StringUtils.findNext(str, open, StringUtils.ESCAPE_CHAR, index.get(), split); split.setLength(0); // clear the buffer if (next >= 0) { ++next; // move over '(' next = StringUtils.findNext(str, close, StringUtils.ESCAPE_CHAR, next, split); if (next >= 0) { ++next; // move over ')' index.set(next);/*from w ww.jav a 2 s.co m*/ return split.toString(); // found a block } else { throw new ParseException("Unexpected end of block", next); } } return null; // found nothing }
From source file:org.apache.hama.bsp.Counters.java
License:Apache License
private static String escape(String string) { return StringUtils.escapeString(string, StringUtils.ESCAPE_CHAR, charsToEscape); }
From source file:org.apache.hama.bsp.Counters.java
License:Apache License
private static String unescape(String string) { return StringUtils.unEscapeString(string, StringUtils.ESCAPE_CHAR, charsToEscape); }
From source file:org.apache.hcatalog.templeton.test.tool.TempletonUtilsTest.java
License:Apache License
@Test public void testEncodeArray() { assertEquals(null, TempletonUtils.encodeArray((String[]) null)); String[] tmp = new String[0]; assertTrue(TempletonUtils.encodeArray(new String[0]).length() == 0); tmp = new String[3]; tmp[0] = "fred"; tmp[1] = null;// w w w . j a va 2 s . c o m tmp[2] = "peter,lisa,, barney"; assertEquals("fred,,peter" + StringUtils.ESCAPE_CHAR + ",lisa" + StringUtils.ESCAPE_CHAR + "," + StringUtils.ESCAPE_CHAR + ", barney", TempletonUtils.encodeArray(tmp)); }
From source file:org.apache.hcatalog.templeton.tool.TestTempletonUtils.java
License:Apache License
@Test public void testEncodeArray() { Assert.assertEquals(null, TempletonUtils.encodeArray((String[]) null)); String[] tmp = new String[0]; Assert.assertTrue(TempletonUtils.encodeArray(new String[0]).length() == 0); tmp = new String[3]; tmp[0] = "fred"; tmp[1] = null;/*from ww w . j av a 2 s. c om*/ tmp[2] = "peter,lisa,, barney"; Assert.assertEquals("fred,,peter" + StringUtils.ESCAPE_CHAR + ",lisa" + StringUtils.ESCAPE_CHAR + "," + StringUtils.ESCAPE_CHAR + ", barney", TempletonUtils.encodeArray(tmp)); }