Example usage for io.netty.util CharsetUtil US_ASCII

List of usage examples for io.netty.util CharsetUtil US_ASCII

Introduction

In this page you can find the example usage for io.netty.util CharsetUtil US_ASCII.

Prototype

Charset US_ASCII

To view the source code for io.netty.util CharsetUtil US_ASCII.

Click Source Link

Document

7-bit ASCII, as known as ISO646-US or the Basic Latin block of the Unicode character set

Usage

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();/*w w  w. j  a  v  a 2s  .  c  o  m*/
    assertEquals("first", buf.toString(CharsetUtil.US_ASCII));

    ByteBuf buf2 = ch.readInbound();
    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();
}

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();/* www  .  j av  a  2 s  .  c  om*/
    assertEquals("first", buf.toString(CharsetUtil.US_ASCII));

    ByteBuf buf2 = ch.readInbound();
    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();//from ww w  .  java  2 s  . com
    assertEquals("first\r\n", buf.toString(CharsetUtil.US_ASCII));

    ByteBuf buf2 = ch.readInbound();
    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 testTooLongLine1() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new LenientLineBasedFrameDecoder(16, false, false, false));

    try {//from   w w w .  ja va  2 s  .c  o  m
        ch.writeInbound(copiedBuffer("12345678901234567890\r\nfirst\nsecond", CharsetUtil.US_ASCII));
        fail();
    } catch (Exception e) {
        assertThat(e, is(instanceOf(TooLongFrameException.class)));
    }

    ByteBuf buf = ch.readInbound();
    ByteBuf buf2 = copiedBuffer("first\n", CharsetUtil.US_ASCII);
    assertThat(buf, is(buf2));
    assertThat(ch.finish(), is(false));

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

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

License:Open Source License

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

    assertFalse(ch.writeInbound(copiedBuffer("12345678901234567", CharsetUtil.US_ASCII)));
    try {//from   www  . j a  v  a2 s  .c  om
        ch.writeInbound(copiedBuffer("890\r\nfirst\r\n", CharsetUtil.US_ASCII));
        fail();
    } catch (Exception e) {
        assertThat(e, is(instanceOf(TooLongFrameException.class)));
    }

    ByteBuf buf = ch.readInbound();
    ByteBuf buf2 = copiedBuffer("first\r\n", CharsetUtil.US_ASCII);
    assertThat(buf, is(buf2));
    assertThat(ch.finish(), is(false));

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

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

License:Open Source License

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

    try {/*from   w w w .j a  v a  2  s .  co  m*/
        ch.writeInbound(copiedBuffer("12345678901234567", CharsetUtil.US_ASCII));
        fail();
    } catch (Exception e) {
        assertThat(e, is(instanceOf(TooLongFrameException.class)));
    }

    assertThat(ch.writeInbound(copiedBuffer("890", CharsetUtil.US_ASCII)), is(false));
    assertThat(ch.writeInbound(copiedBuffer("123\r\nfirst\r\n", CharsetUtil.US_ASCII)), is(true));

    ByteBuf buf = ch.readInbound();
    ByteBuf buf2 = copiedBuffer("first\r\n", CharsetUtil.US_ASCII);
    assertThat(buf, is(buf2));
    assertThat(ch.finish(), is(false));

    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();/*  w  w  w  .  jav  a2 s. c  om*/
    assertEquals("line\r\n", buf.toString(CharsetUtil.US_ASCII));

    ByteBuf buf2 = ch.readInbound();
    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());//from  w w w  .j ava  2  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();// ww w.j a v a2 s.com
    assertEquals("", buf.toString(CharsetUtil.US_ASCII));

    ByteBuf buf2 = ch.readInbound();
    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();//from www  . j ava2  s .  c  om
    assertEquals("first", buf1.toString(CharsetUtil.US_ASCII));

    ByteBuf buf2 = ch.readInbound();
    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();
}