@Test(timeout = 60000) public void testEmptyInputBuffer() throws Exception { ByteBuf data = Unpooled.buffer(); List<Object> out = new ArrayList<>(); readerRule.lineReader.decode(data, out, UnpooledByteBufAllocator.DEFAULT); assertThat("Unexpected output size.", out, is(empty())); assertThat("Input buffer not consumed.", data.isReadable(), is(false)); }
public void decode(ByteBuf in, List<Object> out, ByteBufAllocator allocator) { while (in.isReadable()) { final int startIndex = in.readerIndex(); int lastReadIndex = in.forEachByte(LINE_END_FINDER); if (-1 == lastReadIndex) { if (null == incompleteBuffer) { incompleteBuffer = allocator.buffer(DEFAULT_INITIAL_CAPACITY, maxLineLength); } incompleteBuffer.ensureWritable(in.readableBytes()); incompleteBuffer.writeBytes(in); } else { ByteBuf lineBuf = in.readSlice(lastReadIndex - startIndex); String line; if (null != incompleteBuffer) { line = incompleteBuffer.toString(encoding) + lineBuf.toString(encoding); incompleteBuffer.release(); incompleteBuffer = null; } else { line = lineBuf.toString(encoding); } out.add(line); in.skipBytes(1); } } }
LineReader { public void decode(ByteBuf in, List<Object> out, ByteBufAllocator allocator) { while (in.isReadable()) { final int startIndex = in.readerIndex(); int lastReadIndex = in.forEachByte(LINE_END_FINDER); if (-1 == lastReadIndex) { if (null == incompleteBuffer) { incompleteBuffer = allocator.buffer(DEFAULT_INITIAL_CAPACITY, maxLineLength); } incompleteBuffer.ensureWritable(in.readableBytes()); incompleteBuffer.writeBytes(in); } else { ByteBuf lineBuf = in.readSlice(lastReadIndex - startIndex); String line; if (null != incompleteBuffer) { line = incompleteBuffer.toString(encoding) + lineBuf.toString(encoding); incompleteBuffer.release(); incompleteBuffer = null; } else { line = lineBuf.toString(encoding); } out.add(line); in.skipBytes(1); } } } }
LineReader { public void decode(ByteBuf in, List<Object> out, ByteBufAllocator allocator) { while (in.isReadable()) { final int startIndex = in.readerIndex(); int lastReadIndex = in.forEachByte(LINE_END_FINDER); if (-1 == lastReadIndex) { if (null == incompleteBuffer) { incompleteBuffer = allocator.buffer(DEFAULT_INITIAL_CAPACITY, maxLineLength); } incompleteBuffer.ensureWritable(in.readableBytes()); incompleteBuffer.writeBytes(in); } else { ByteBuf lineBuf = in.readSlice(lastReadIndex - startIndex); String line; if (null != incompleteBuffer) { line = incompleteBuffer.toString(encoding) + lineBuf.toString(encoding); incompleteBuffer.release(); incompleteBuffer = null; } else { line = lineBuf.toString(encoding); } out.add(line); in.skipBytes(1); } } } LineReader();  LineReader(int maxLineLength, Charset encoding); }
LineReader { public void decode(ByteBuf in, List<Object> out, ByteBufAllocator allocator) { while (in.isReadable()) { final int startIndex = in.readerIndex(); int lastReadIndex = in.forEachByte(LINE_END_FINDER); if (-1 == lastReadIndex) { if (null == incompleteBuffer) { incompleteBuffer = allocator.buffer(DEFAULT_INITIAL_CAPACITY, maxLineLength); } incompleteBuffer.ensureWritable(in.readableBytes()); incompleteBuffer.writeBytes(in); } else { ByteBuf lineBuf = in.readSlice(lastReadIndex - startIndex); String line; if (null != incompleteBuffer) { line = incompleteBuffer.toString(encoding) + lineBuf.toString(encoding); incompleteBuffer.release(); incompleteBuffer = null; } else { line = lineBuf.toString(encoding); } out.add(line); in.skipBytes(1); } } } LineReader();  LineReader(int maxLineLength, Charset encoding); void decode(ByteBuf in, List<Object> out, ByteBufAllocator allocator); void decodeLast(ByteBuf in, List<Object> out, ByteBufAllocator allocator); void dispose(); static boolean isLineDelimiter(char c); }
LineReader { public void decode(ByteBuf in, List<Object> out, ByteBufAllocator allocator) { while (in.isReadable()) { final int startIndex = in.readerIndex(); int lastReadIndex = in.forEachByte(LINE_END_FINDER); if (-1 == lastReadIndex) { if (null == incompleteBuffer) { incompleteBuffer = allocator.buffer(DEFAULT_INITIAL_CAPACITY, maxLineLength); } incompleteBuffer.ensureWritable(in.readableBytes()); incompleteBuffer.writeBytes(in); } else { ByteBuf lineBuf = in.readSlice(lastReadIndex - startIndex); String line; if (null != incompleteBuffer) { line = incompleteBuffer.toString(encoding) + lineBuf.toString(encoding); incompleteBuffer.release(); incompleteBuffer = null; } else { line = lineBuf.toString(encoding); } out.add(line); in.skipBytes(1); } } } LineReader();  LineReader(int maxLineLength, Charset encoding); void decode(ByteBuf in, List<Object> out, ByteBufAllocator allocator); void decodeLast(ByteBuf in, List<Object> out, ByteBufAllocator allocator); void dispose(); static boolean isLineDelimiter(char c); static final int DEFAULT_INITIAL_CAPACITY; }