List of usage examples for io.netty.buffer ByteBuf toString
public abstract String toString(Charset charset);
From source file:org.graylog2.inputs.transports.netty.LenientDelimiterBasedFrameDecoderTest.java
License:Open Source License
@Test public void testMultipleLinesStrippedDelimiters() { EmbeddedChannel ch = new EmbeddedChannel( new LenientDelimiterBasedFrameDecoder(8192, true, Delimiters.lineDelimiter())); ch.writeInbound(Unpooled.copiedBuffer("TestLine\r\ng\r\n", Charset.defaultCharset())); ByteBuf buf = ch.readInbound(); assertEquals("TestLine", buf.toString(Charset.defaultCharset())); ByteBuf buf2 = ch.readInbound();/*from w w w .ja v a 2 s. co m*/ assertEquals("g", buf2.toString(Charset.defaultCharset())); assertNull(ch.readInbound()); ch.finish(); buf.release(); buf2.release(); }
From source file:org.graylog2.inputs.transports.netty.LenientDelimiterBasedFrameDecoderTest.java
License:Open Source License
@Test public void testIncompleteLinesStrippedDelimiters() { EmbeddedChannel ch = new EmbeddedChannel( new LenientDelimiterBasedFrameDecoder(8192, true, Delimiters.lineDelimiter())); ch.writeInbound(Unpooled.copiedBuffer("Test", Charset.defaultCharset())); assertNull(ch.readInbound());/*from w ww . ja va 2s. c om*/ ch.writeInbound(Unpooled.copiedBuffer("Line\r\ng\r\n", Charset.defaultCharset())); ByteBuf buf = ch.readInbound(); assertEquals("TestLine", buf.toString(Charset.defaultCharset())); ByteBuf buf2 = ch.readInbound(); assertEquals("g", buf2.toString(Charset.defaultCharset())); assertNull(ch.readInbound()); ch.finish(); buf.release(); buf2.release(); }
From source file:org.graylog2.inputs.transports.netty.LenientDelimiterBasedFrameDecoderTest.java
License:Open Source License
@Test public void testMultipleLines() { EmbeddedChannel ch = new EmbeddedChannel( new LenientDelimiterBasedFrameDecoder(8192, false, Delimiters.lineDelimiter())); ch.writeInbound(Unpooled.copiedBuffer("TestLine\r\ng\r\n", Charset.defaultCharset())); ByteBuf buf = ch.readInbound(); assertEquals("TestLine\r\n", buf.toString(Charset.defaultCharset())); ByteBuf buf2 = ch.readInbound();/* ww w .j a v a2 s.c o m*/ assertEquals("g\r\n", buf2.toString(Charset.defaultCharset())); assertNull(ch.readInbound()); ch.finish(); buf.release(); buf2.release(); }
From source file:org.graylog2.inputs.transports.netty.LenientDelimiterBasedFrameDecoderTest.java
License:Open Source License
@Test public void testIncompleteLines() { EmbeddedChannel ch = new EmbeddedChannel( new LenientDelimiterBasedFrameDecoder(8192, false, Delimiters.lineDelimiter())); ch.writeInbound(Unpooled.copiedBuffer("Test", Charset.defaultCharset())); assertNull(ch.readInbound());// ww w . j a va 2 s . co m ch.writeInbound(Unpooled.copiedBuffer("Line\r\ng\r\n", Charset.defaultCharset())); ByteBuf buf = ch.readInbound(); assertEquals("TestLine\r\n", buf.toString(Charset.defaultCharset())); ByteBuf buf2 = ch.readInbound(); assertEquals("g\r\n", buf2.toString(Charset.defaultCharset())); assertNull(ch.readInbound()); ch.finish(); buf.release(); buf2.release(); }
From source file:org.graylog2.inputs.transports.netty.LenientDelimiterBasedFrameDecoderTest.java
License:Open Source License
@Test public void testDecode() throws Exception { EmbeddedChannel ch = new EmbeddedChannel( new LenientDelimiterBasedFrameDecoder(8192, true, Delimiters.lineDelimiter())); ch.writeInbound(Unpooled.copiedBuffer("first\r\nsecond\nthird", CharsetUtil.US_ASCII)); ByteBuf buf = ch.readInbound(); assertEquals("first", buf.toString(CharsetUtil.US_ASCII)); ByteBuf buf2 = ch.readInbound();//from w w w. j a va 2s . c o m assertEquals("second", buf2.toString(CharsetUtil.US_ASCII)); assertNull(ch.readInbound()); ch.finish(); ReferenceCountUtil.release(ch.readInbound()); buf.release(); buf2.release(); }
From source file:org.graylog2.inputs.transports.netty.LenientDelimiterBasedFrameDecoderTest.java
License:Open Source License
@Test public void testFailSlowTooLongFrameRecovery() throws Exception { EmbeddedChannel ch = new EmbeddedChannel( new LenientDelimiterBasedFrameDecoder(1, true, false, false, Delimiters.nulDelimiter())); for (int i = 0; i < 2; i++) { ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 1, 2 })); try {// w w w . j av a 2 s .com assertTrue(ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 0 }))); fail(DecoderException.class.getSimpleName() + " must be raised."); } catch (TooLongFrameException e) { // Expected } ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 'A', 0 })); ByteBuf buf = ch.readInbound(); assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1)); buf.release(); } }
From source file:org.graylog2.inputs.transports.netty.LenientDelimiterBasedFrameDecoderTest.java
License:Open Source License
@Test public void testFailFastTooLongFrameRecovery() throws Exception { EmbeddedChannel ch = new EmbeddedChannel( new LenientDelimiterBasedFrameDecoder(1, Delimiters.nulDelimiter())); for (int i = 0; i < 2; i++) { try {//from www .java 2 s . co m assertTrue(ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 1, 2 }))); fail(DecoderException.class.getSimpleName() + " must be raised."); } catch (TooLongFrameException e) { // Expected } ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 0, 'A', 0 })); ByteBuf buf = ch.readInbound(); assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1)); buf.release(); } }
From source file:org.graylog2.inputs.transports.netty.LenientDelimiterBasedFrameDecoderTest.java
License:Open Source License
@Test public void testDecodeNulDelimiter() throws Exception { EmbeddedChannel ch = new EmbeddedChannel( new LenientDelimiterBasedFrameDecoder(8192, true, Delimiters.nulDelimiter())); ch.writeInbound(Unpooled.copiedBuffer("first\0second\0third", CharsetUtil.US_ASCII)); ByteBuf buf = ch.readInbound(); assertEquals("first", buf.toString(CharsetUtil.US_ASCII)); ByteBuf buf2 = ch.readInbound();/* w ww .j av a 2s . c o m*/ assertEquals("second", buf2.toString(CharsetUtil.US_ASCII)); assertNull(ch.readInbound()); ch.finish(); ReferenceCountUtil.release(ch.readInbound()); buf.release(); buf2.release(); }
From source file:org.graylog2.inputs.transports.netty.LenientDelimiterBasedFrameDecoderTest.java
License:Open Source License
@Test public void testDecodeAndEmitLastLine() throws Exception { EmbeddedChannel ch = new EmbeddedChannel( new LenientDelimiterBasedFrameDecoder(8192, true, Delimiters.lineDelimiter())); ch.writeInbound(Unpooled.copiedBuffer("first\r\nsecond\nthird", CharsetUtil.US_ASCII)); ByteBuf buf = ch.readInbound(); assertEquals("first", buf.toString(CharsetUtil.US_ASCII)); ByteBuf buf2 = ch.readInbound();/*w w w . j a v a 2s. c o m*/ assertEquals("second", buf2.toString(CharsetUtil.US_ASCII)); // Close channel assertTrue(ch.finish()); ByteBuf buf3 = ch.readInbound(); assertEquals("third", buf3.toString(CharsetUtil.US_ASCII)); assertNull(ch.readInbound()); assertFalse(ch.finish()); ReferenceCountUtil.release(ch.readInbound()); buf.release(); buf2.release(); buf3.release(); }
From source file:org.graylog2.inputs.transports.netty.LenientDelimiterBasedFrameDecoderTest.java
License:Open Source License
@Test public void testDecodeNulDelimiterAndEmitLastLine() throws Exception { EmbeddedChannel ch = new EmbeddedChannel( new LenientDelimiterBasedFrameDecoder(8192, true, true, true, Delimiters.nulDelimiter())); ch.writeInbound(Unpooled.copiedBuffer("first\0second\0third", CharsetUtil.US_ASCII)); ByteBuf buf = ch.readInbound(); assertEquals("first", buf.toString(CharsetUtil.US_ASCII)); ByteBuf buf2 = ch.readInbound();//from w w w .j a va2s . c om assertEquals("second", buf2.toString(CharsetUtil.US_ASCII)); // Close channel assertTrue(ch.finish()); ByteBuf buf3 = ch.readInbound(); assertEquals("third", buf3.toString(CharsetUtil.US_ASCII)); assertNull(ch.readInbound()); assertFalse(ch.finish()); ReferenceCountUtil.release(ch.readInbound()); buf.release(); buf2.release(); }