Example usage for io.netty.buffer ByteBuf toString

List of usage examples for io.netty.buffer ByteBuf toString

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf toString.

Prototype

public abstract String toString(Charset charset);

Source Link

Document

Decodes this buffer's readable bytes into a string with the specified character set name.

Usage

From source file:org.graylog2.inputs.transports.netty.LenientLineBasedFrameDecoderTest.java

License:Open Source License

@Test
public void testDecodeWithStrip() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new LenientLineBasedFrameDecoder(8192, true, false, false));

    ch.writeInbound(copiedBuffer("first\r\nsecond\nthird", CharsetUtil.US_ASCII));

    ByteBuf buf = ch.readInbound();
    assertEquals("first", buf.toString(CharsetUtil.US_ASCII));

    ByteBuf buf2 = ch.readInbound();/*from ww  w.  j a va  2s  . c  om*/
    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.LenientLineBasedFrameDecoderTest.java

License:Open Source License

@Test
public void testDecodeWithoutStrip() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new LenientLineBasedFrameDecoder(8192, false, false, false));

    ch.writeInbound(copiedBuffer("first\r\nsecond\nthird", CharsetUtil.US_ASCII));

    ByteBuf buf = ch.readInbound();
    assertEquals("first\r\n", buf.toString(CharsetUtil.US_ASCII));

    ByteBuf buf2 = ch.readInbound();// w  w  w.j  a  va2  s.  co m
    assertEquals("second\n", 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.LenientLineBasedFrameDecoderTest.java

License:Open Source License

@Test
public void testDecodeSplitsCorrectly() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new LenientLineBasedFrameDecoder(8192, false, false, false));

    assertTrue(ch.writeInbound(copiedBuffer("line\r\n.\r\n", CharsetUtil.US_ASCII)));

    ByteBuf buf = ch.readInbound();
    assertEquals("line\r\n", buf.toString(CharsetUtil.US_ASCII));

    ByteBuf buf2 = ch.readInbound();/* w  ww  .  j  a  va2 s .c  o m*/
    assertEquals(".\r\n", buf2.toString(CharsetUtil.US_ASCII));
    assertFalse(ch.finishAndReleaseAll());

    buf.release();
    buf2.release();
}

From source file:org.graylog2.inputs.transports.netty.LenientLineBasedFrameDecoderTest.java

License:Open Source License

@Test
public void testFragmentedDecode() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new LenientLineBasedFrameDecoder(8192, false, false, false));

    assertFalse(ch.writeInbound(copiedBuffer("huu", CharsetUtil.US_ASCII)));
    assertNull(ch.readInbound());/*  w w  w.  j  ava2 s . c  o m*/

    assertFalse(ch.writeInbound(copiedBuffer("haa\r", CharsetUtil.US_ASCII)));
    assertNull(ch.readInbound());

    assertTrue(ch.writeInbound(copiedBuffer("\nhuuhaa\r\n", CharsetUtil.US_ASCII)));
    ByteBuf buf = ch.readInbound();
    assertEquals("huuhaa\r\n", buf.toString(CharsetUtil.US_ASCII));

    ByteBuf buf2 = ch.readInbound();
    assertEquals("huuhaa\r\n", buf2.toString(CharsetUtil.US_ASCII));
    assertFalse(ch.finishAndReleaseAll());

    buf.release();
    buf2.release();
}

From source file:org.graylog2.inputs.transports.netty.LenientLineBasedFrameDecoderTest.java

License:Open Source License

@Test
public void testEmptyLine() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new LenientLineBasedFrameDecoder(8192, true, false, false));

    assertTrue(ch.writeInbound(copiedBuffer("\nabcna\r\n", CharsetUtil.US_ASCII)));

    ByteBuf buf = ch.readInbound();
    assertEquals("", buf.toString(CharsetUtil.US_ASCII));

    ByteBuf buf2 = ch.readInbound();//from ww  w  .ja  v a 2s .  c  o m
    assertEquals("abcna", buf2.toString(CharsetUtil.US_ASCII));

    assertFalse(ch.finishAndReleaseAll());

    buf.release();
    buf2.release();
}

From source file:org.graylog2.inputs.transports.netty.LenientLineBasedFrameDecoderTest.java

License:Open Source License

@Test
public void testDecodeWithStripAndEmitLastLine() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new LenientLineBasedFrameDecoder(8192, true, false, true));

    ch.writeInbound(copiedBuffer("first\r\nsecond\nthird", CharsetUtil.US_ASCII));

    ByteBuf buf1 = ch.readInbound();
    assertEquals("first", buf1.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());

    buf1.release();
    buf2.release();
    buf3.release();
}

From source file:org.graylog2.inputs.transports.netty.LenientLineBasedFrameDecoderTest.java

License:Open Source License

@Test
public void testDecodeWithoutStripAndEmitLastLine() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new LenientLineBasedFrameDecoder(8192, false, false, true));

    ch.writeInbound(copiedBuffer("first\r\nsecond\nthird", CharsetUtil.US_ASCII));

    ByteBuf buf1 = ch.readInbound();
    assertEquals("first\r\n", buf1.toString(CharsetUtil.US_ASCII));

    ByteBuf buf2 = ch.readInbound();/*from  w  w w  .j a  v  a  2  s. co  m*/
    assertEquals("second\n", 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());

    buf1.release();
    buf2.release();
    buf3.release();
}

From source file:org.graylog2.inputs.transports.netty.LenientLineBasedFrameDecoderTest.java

License:Open Source License

@Test
public void testDecodeSplitsCorrectlyAndEmitLastLine() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new LenientLineBasedFrameDecoder(8192, false, false, true));

    assertTrue(ch.writeInbound(copiedBuffer("line\r\n.\r\n", CharsetUtil.US_ASCII)));

    ByteBuf buf = ch.readInbound();
    assertEquals("line\r\n", buf.toString(CharsetUtil.US_ASCII));

    ByteBuf buf2 = ch.readInbound();/*from  w  ww .ja  va 2s.  c om*/
    assertEquals(".\r\n", buf2.toString(CharsetUtil.US_ASCII));
    assertFalse(ch.finishAndReleaseAll());

    buf.release();
    buf2.release();
}

From source file:org.graylog2.inputs.transports.netty.LenientLineBasedFrameDecoderTest.java

License:Open Source License

@Test
public void testFragmentedDecodeAndEmitLastLine() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new LenientLineBasedFrameDecoder(8192, false, false, true));

    assertFalse(ch.writeInbound(copiedBuffer("huu", CharsetUtil.US_ASCII)));
    assertNull(ch.readInbound());// www.  ja v  a  2 s.  co m

    assertFalse(ch.writeInbound(copiedBuffer("haa\r", CharsetUtil.US_ASCII)));
    assertNull(ch.readInbound());

    assertTrue(ch.writeInbound(copiedBuffer("\nhuuhaa\r\n", CharsetUtil.US_ASCII)));
    ByteBuf buf = ch.readInbound();
    assertEquals("huuhaa\r\n", buf.toString(CharsetUtil.US_ASCII));

    ByteBuf buf2 = ch.readInbound();
    assertEquals("huuhaa\r\n", buf2.toString(CharsetUtil.US_ASCII));
    assertFalse(ch.finishAndReleaseAll());

    buf.release();
    buf2.release();
}

From source file:org.graylog2.inputs.transports.netty.LenientLineBasedFrameDecoderTest.java

License:Open Source License

@Test
public void testEmptyLineAndEmitLastLine() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new LenientLineBasedFrameDecoder(8192, true, false, true));

    assertTrue(ch.writeInbound(copiedBuffer("\nabcna\r\n", CharsetUtil.US_ASCII)));

    ByteBuf buf = ch.readInbound();
    assertEquals("", buf.toString(CharsetUtil.US_ASCII));

    ByteBuf buf2 = ch.readInbound();//from   w ww  .  j a v  a2  s  .com
    assertEquals("abcna", buf2.toString(CharsetUtil.US_ASCII));

    assertFalse(ch.finishAndReleaseAll());

    buf.release();
    buf2.release();
}