Example usage for io.netty.buffer ByteBuf readerIndex

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

Introduction

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

Prototype

public abstract int readerIndex();

Source Link

Document

Returns the readerIndex of this buffer.

Usage

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 2s.  c  o  m*/

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

    assertEquals(74, closingPos);
    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);/*from www  .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 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  a  v  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);/*  w ww .jav  a  2 s  . c o  m*/
    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);//w  w  w. j  av a 2  s.  c  om
    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);//  w  w  w.j  a v  a2  s .  c o  m

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

    assertEquals(40, closingPos);
    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  ww w. j  a  v a 2 s. co m*/
    assertEquals(0, source.readerIndex());
}

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

License:Apache License

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

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

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

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

License:Apache License

@Test
public void testClosingPosFoundInStringWithEscapedBackslashLast() {
    ByteBuf source = Unpooled.copiedBuffer("\"abc\\\\\"", CharsetUtil.UTF_8);
    int closingPos = source.forEachByte(new StringClosingPositionBufProcessor());

    assertEquals(6, closingPos);//from w ww  .  java  2 s  . c  om
    assertEquals(0, source.readerIndex());
}