Example usage for io.netty.util CharsetUtil UTF_8

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

Introduction

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

Prototype

Charset UTF_8

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

Click Source Link

Document

8-bit UTF (UCS Transformation Format)

Usage

From source file:com.couchbase.client.core.endpoint.util.ClosingPositionBufProcessorTest.java

License:Apache License

@Test
public void shouldFindClosingInSectionWithSubsection() {
    ByteBuf source = Unpooled.copiedBuffer("{ this is { simple } }", CharsetUtil.UTF_8);
    int closingPos = source.forEachByte(new ClosingPositionBufProcessor('{', '}'));
    assertEquals(21, closingPos);/*ww  w  .jav  a  2 s  .c  o m*/
    assertEquals(0, source.readerIndex());
}

From source file:com.couchbase.client.core.endpoint.util.ClosingPositionBufProcessorTest.java

License:Apache License

@Test
public void shouldNotFindClosingInBrokenSectionWithCompleteSubSection() {
    ByteBuf source = Unpooled.copiedBuffer("{ this is { complex } oups", CharsetUtil.UTF_8);
    int closingPos = source.forEachByte(new ClosingPositionBufProcessor('{', '}'));
    assertEquals(-1, closingPos);//w ww. j a  v a 2 s .com
    assertEquals(0, source.readerIndex());
}

From source file:com.couchbase.client.core.endpoint.util.ClosingPositionBufProcessorTest.java

License:Apache License

@Test
public void shouldIgnoreJsonStringWithRandomSectionChars() {
    ByteBuf source = Unpooled.copiedBuffer(
            "{ this is \"a string \\\"with escaped quote and sectionChars like } or {{{!\" }",
            CharsetUtil.UTF_8);

    int closingPos = source.forEachByte(new ClosingPositionBufProcessor('{', '}', true));

    assertEquals(74, closingPos);/*  w  ww. j a  va2 s .  c  o m*/
    assertEquals(0, source.readerIndex());
}

From source file:com.couchbase.client.core.endpoint.util.ClosingPositionBufProcessorTest.java

License:Apache License

@Test
public void shouldIgnoreJsonStringWithClosingSectionCharEvenIfStreamInterrupted() {
    ByteBuf source = Unpooled.copiedBuffer("{ this is \"a string \\\"with }", CharsetUtil.UTF_8);

    int closingPos = source.forEachByte(new ClosingPositionBufProcessor('{', '}', true));

    assertEquals(-1, closingPos);//w  ww. ja  va  2 s .  c om
    assertEquals(0, source.readerIndex());
}

From source file:com.couchbase.client.core.endpoint.util.ClosingPositionBufProcessorTest.java

License:Apache License

@Test
public void shouldSkipStringWithEscapedBackslashJustBeforeClosingQuote() {
    ByteBuf source = Unpooled.copiedBuffer("{\"some\": \"weird }object\\\\\"}", CharsetUtil.UTF_8);
    int closingPos = source.forEachByte(new ClosingPositionBufProcessor('{', '}', true));

    assertEquals(26, closingPos);/*from w w w .j  a v  a  2  s.c  o m*/
    assertEquals(0, source.readerIndex());
}

From source file:com.couchbase.client.core.endpoint.util.ClosingPositionBufProcessorTest.java

License:Apache License

@Test
public void shouldSkipEmptyString() {
    ByteBuf source = Unpooled.copiedBuffer("{\"some\": \"\"}", CharsetUtil.UTF_8);
    int closingPos = source.forEachByte(new ClosingPositionBufProcessor('{', '}', true));

    assertEquals(11, closingPos);/*from w w  w  .  j  av  a  2s .  co m*/
    assertEquals(0, source.readerIndex());
}

From source file:com.couchbase.client.core.endpoint.util.ClosingPositionBufProcessorTest.java

License:Apache License

@Test
public void shouldSkipStringWithEscapedBackslashOnly() {
    ByteBuf source = Unpooled.copiedBuffer("{\"some\": \"\\\\\"}", CharsetUtil.UTF_8);
    int closingPos = source.forEachByte(new ClosingPositionBufProcessor('{', '}', true));

    assertEquals(13, closingPos);//www.ja v  a2 s. c om
    assertEquals(0, source.readerIndex());
}

From source file:com.couchbase.client.core.endpoint.util.StringClosingPositionBufProcessorTest.java

License:Apache License

@Test
public void testClosingPosFoundInSimpleString() {
    ByteBuf source = Unpooled.copiedBuffer("\" \"", CharsetUtil.UTF_8);

    int closingPos = source.forEachByte(new StringClosingPositionBufProcessor());

    assertEquals(2, closingPos);// www. j  a v  a 2s  .co  m
    assertEquals(0, source.readerIndex());
}

From source file:com.couchbase.client.core.endpoint.util.StringClosingPositionBufProcessorTest.java

License:Apache License

@Test
public void testClosingPosFoundInStringWithEscapedContent() {
    ByteBuf source = Unpooled.copiedBuffer(" \"Some string with {\\\"escaped\\\"} strings\" \"otherString\"",
            CharsetUtil.UTF_8);

    int closingPos = source.forEachByte(new StringClosingPositionBufProcessor());

    assertEquals(40, closingPos);//from w w  w .  ja va  2s .  c  om
    assertEquals(0, source.readerIndex());
}

From source file:com.couchbase.client.core.endpoint.util.StringClosingPositionBufProcessorTest.java

License:Apache License

@Test
public void testClosingPosNotFoundInPartialStringLeftPart() {
    ByteBuf source = Unpooled.copiedBuffer(" \"\\\"Partial\\\" str", CharsetUtil.UTF_8);

    int closingPos = source.forEachByte(new StringClosingPositionBufProcessor());

    assertEquals(-1, closingPos);//from w w w . j  a va 2s .c  o  m
    assertEquals(0, source.readerIndex());
}