BlockRecordReader extends RecordReader { protected byte[][] splitLine(byte[] sbl) { if (sbl == null) { return null; } List<byte[]> l = new ArrayList<byte[]>(); int start = 0; int end = 0; while (end != -1) { end = indexOf(sbl, start, sbl.length, fieldDelimiter); int colLen = (end == -1 ? sbl.length - start : end - start); byte[] col = new byte[colLen]; System.arraycopy(sbl, start, col, 0, colLen); l.add(col); start = end + fieldDelimiter.length; } return l.toArray(new byte[l.size()][]); } BlockRecordReader(BlockInfo blockInfo, String fd, String rd, boolean ignoreHeader); byte[][] readTextRecord(); String getCurrentLine(); void close(); static int indexOf(byte[] src, int offset, int length, byte[] search);  }
@Test public void testSpliter() throws Exception { BlockInfo blockInfo = new BlockInfo(1L, new File("src/test/resources/file/reader/one_char_split_A.txt"), 0L, 15L); BlockRecordReader reader = new BlockRecordReader(blockInfo, "[", "\n", false); byte[][] l = reader.splitLine("123[abc[456".getBytes()); assertEquals("size not equal", 3, l.length); assertEquals("123 not equal", "123", new String(l[0], "utf8")); assertEquals("abc not equal", "abc", new String(l[1], "utf8")); assertEquals("456 not equal", "456", new String(l[2], "utf8")); l = reader.splitLine("123[[abc[456[".getBytes()); assertEquals("size not equal", 5, l.length); assertEquals("123 not equal", "123", new String(l[0], "utf8")); assertEquals("null not equal", "", new String(l[1], "utf8")); assertEquals("abc not equal", "abc", new String(l[2], "utf8")); assertEquals("456 not equal", "456", new String(l[3], "utf8")); assertEquals("null not equal", "", new String(l[4], "utf8")); l = reader.splitLine("123[[abc[456[[[[".getBytes()); assertEquals("size not equal", 8, l.length); assertEquals("123 not equal", "123", new String(l[0], "utf8")); assertEquals("null not equal", "", new String(l[1], "utf8")); assertEquals("abc not equal", "abc", new String(l[2], "utf8")); assertEquals("456 not equal", "456", new String(l[3], "utf8")); assertEquals("null not equal", "", new String(l[4], "utf8")); assertEquals("null not equal", "", new String(l[5], "utf8")); assertEquals("null not equal", "", new String(l[6], "utf8")); assertEquals("null not equal", "", new String(l[7], "utf8")); reader = new BlockRecordReader(blockInfo, ",", "\n", false); l = reader.splitLine("123,abc,456".getBytes()); assertEquals("size not equal", 3, l.length); assertEquals("123 not equal", "123", new String(l[0], "utf8")); assertEquals("abc not equal", "abc", new String(l[1], "utf8")); assertEquals("456 not equal", "456", new String(l[2], "utf8")); l = reader.splitLine("123,,abc,456,".getBytes()); assertEquals("size not equal", 5, l.length); assertEquals("123 not equal", "123", new String(l[0], "utf8")); assertEquals("null not equal", "", new String(l[1], "utf8")); assertEquals("abc not equal", "abc", new String(l[2], "utf8")); assertEquals("456 not equal", "456", new String(l[3], "utf8")); assertEquals("null not equal", "", new String(l[4], "utf8")); reader = new BlockRecordReader(blockInfo, ",", "\n", false); l = reader.splitLine("123,abc,456".getBytes()); assertEquals("size not equal", 3, l.length); assertEquals("123 not equal", "123", new String(l[0], "utf8")); assertEquals("abc not equal", "abc", new String(l[1], "utf8")); assertEquals("456 not equal", "456", new String(l[2], "utf8")); l = reader.splitLine("123,,abc,456,".getBytes()); assertEquals("size not equal", 5, l.length); assertEquals("123 not equal", "123", new String(l[0], "utf8")); assertEquals("null not equal", "", new String(l[1], "utf8")); assertEquals("abc not equal", "abc", new String(l[2], "utf8")); assertEquals("456 not equal", "456", new String(l[3], "utf8")); assertEquals("null not equal", "", new String(l[4], "utf8")); reader = new BlockRecordReader(blockInfo, "99", "\n", false); l = reader.splitLine("12399abc99456".getBytes()); assertEquals("size not equal", 3, l.length); assertEquals("123 not equal", "123", new String(l[0], "utf8")); assertEquals("abc not equal", "abc", new String(l[1], "utf8")); assertEquals("456 not equal", "456", new String(l[2], "utf8")); l = reader.splitLine("1239999abc9945699".getBytes()); assertEquals("size not equal", 5, l.length); assertEquals("123 not equal", "123", new String(l[0], "utf8")); assertEquals("null not equal", "", new String(l[1], "utf8")); assertEquals("abc not equal", "abc", new String(l[2], "utf8")); assertEquals("456 not equal", "456", new String(l[3], "utf8")); assertEquals("null not equal", "", new String(l[4], "utf8")); }