Example usage for io.netty.buffer Unpooled copiedBuffer

List of usage examples for io.netty.buffer Unpooled copiedBuffer

Introduction

In this page you can find the example usage for io.netty.buffer Unpooled copiedBuffer.

Prototype

private static ByteBuf copiedBuffer(CharBuffer buffer, Charset charset) 

Source Link

Usage

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

License:Apache License

/**
 * See JVMCBC-239.//from   ww  w. ja  va 2 s .c o m
 */
@Test
public void testFindNextCharNotPrefixedByAfterReaderIndexMoved() throws Exception {
    //before JVMCBC-239 the fact that the head of the buffer, with skipped data, is larger than its tail would
    //cause an negative search length and the method would return a -1.
    ByteBuf source = Unpooled.copiedBuffer("sectionWithLotsAndLotsOfDataToSkip\": \"123456\\\"78901234567890\"",
            CharsetUtil.UTF_8);
    source.skipBytes(38);

    assertEquals(22, ByteBufJsonHelper.findNextCharNotPrefixedBy(source, '"', '\\'));
}

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

License:Apache License

@Test
public void shouldFindSectionClosingPositionIfAtStartSection() throws Exception {
    ByteBuf source = Unpooled.copiedBuffer("{123}", CharsetUtil.UTF_8);

    assertEquals(4, ByteBufJsonHelper.findSectionClosingPosition(source, '{', '}'));
    assertEquals(0, source.readerIndex());
}

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

License:Apache License

@Test
public void shouldNotFindSectionClosingPositionIfAfterStartSection() throws Exception {
    ByteBuf source = Unpooled.copiedBuffer("123}", CharsetUtil.UTF_8);

    assertEquals(-1, ByteBufJsonHelper.findSectionClosingPosition(source, '{', '}'));
    assertEquals(0, source.readerIndex());
}

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

License:Apache License

@Test
public void shouldFindSectionClosingPositionWithOffset() throws Exception {
    ByteBuf source = Unpooled.copiedBuffer("{{{}{123}", CharsetUtil.UTF_8);

    assertEquals(8, ByteBufJsonHelper.findSectionClosingPosition(source, 4, '{', '}'));
    assertEquals(0, source.readerIndex());
}

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

License:Apache License

@Test
public void shouldFindSectionClosingInRealLifeExample() {
    ByteBuf source = Unpooled.copiedBuffer(
            "rics\":{\"elapsedTime\":\"128.21463ms\",\"executionTime\":\"127.21463ms\",\"resultCount\":1,\"resultSize\":0,\"mutationCount\":0,\"errorCount\":0,\"warningCount\":0}}",
            CharsetUtil.UTF_8);/*www.  j  a  v  a  2  s . c o m*/

    assertNotEquals(-1, ByteBufJsonHelper.findSectionClosingPosition(source, '{', '}'));
}

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

License:Apache License

@Test
public void shouldFindClosingInSimpleSection() {
    ByteBuf source = Unpooled.copiedBuffer("{ this is simple }", CharsetUtil.UTF_8);
    int closingPos = source.forEachByte(new ClosingPositionBufProcessor('{', '}'));
    assertEquals(17, closingPos);/*from w w w.ja v  a2 s .  c  om*/
    assertEquals(0, source.readerIndex());
}

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

License:Apache License

@Test
public void shouldNotFindClosingInBrokenSection() {
    ByteBuf source = Unpooled.copiedBuffer("{ this is simple", CharsetUtil.UTF_8);
    int closingPos = source.forEachByte(new ClosingPositionBufProcessor('{', '}'));
    assertEquals(-1, closingPos);//from  w w w  . ja  v a 2 s  . co  m
    assertEquals(0, source.readerIndex());
}

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);//from w  w  w .j  a va2  s  . c  om
    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);/*  ww w  . jav  a2s .  c o  m*/
    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);/*from   w  w  w .  j a  v  a 2  s . c om*/

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

    assertEquals(74, closingPos);
    assertEquals(0, source.readerIndex());
}