TimelineReaderUtils { static List<String> split(final String str, final char delimiterChar, final char escapeChar) throws IllegalArgumentException { if (str == null) { return null; } int len = str.length(); if (len == 0) { return Collections.emptyList(); } List<String> list = new ArrayList<String>(); int offset = 0; int startOffset = 0; StringBuilder builder = new StringBuilder(len); while (offset < len) { if (str.charAt(offset) == escapeChar) { if (offset + 1 >= len) { throw new IllegalArgumentException( "Escape char not properly escaped."); } char nextChar = str.charAt(offset + 1); if (nextChar != escapeChar && nextChar != delimiterChar) { throw new IllegalArgumentException( "Escape char or delimiter char not properly escaped."); } if (startOffset < offset) { builder.append(str.substring(startOffset, offset)); } builder.append(nextChar); offset += 2; startOffset = offset; continue; } else if (str.charAt(offset) == delimiterChar) { builder.append(str.substring(startOffset, offset)); list.add(builder.toString().trim()); startOffset = ++offset; builder = new StringBuilder(len - offset); continue; } offset++; } if (!str.isEmpty()) { builder.append(str.substring(startOffset)); } list.add(builder.toString().trim()); return list; } private  TimelineReaderUtils(); static List<String> split(final String str); static String joinAndEscapeStrings(final String[] strs); @VisibleForTesting
  static final char DEFAULT_DELIMITER_CHAR; @VisibleForTesting
  static final char DEFAULT_ESCAPE_CHAR; static final String FROMID_KEY; @VisibleForTesting
  static final String UID_KEY; }
@Test public void testSplitUsingEscapeAndDelimChar() throws Exception { List<String> list = TimelineReaderUtils.split("*!cluster!*!b**o***!xer!oozie**", '!', '*'); String[] arr = new String[list.size()]; arr = list.toArray(arr); assertArrayEquals(new String[] {"!cluster", "!b*o*!xer", "oozie*"}, arr); list = TimelineReaderUtils.split("*!cluster!*!b**o***!xer!!", '!', '*'); arr = new String[list.size()]; arr = list.toArray(arr); assertArrayEquals(new String[] {"!cluster", "!b*o*!xer", "", ""}, arr); }