List of usage examples for io.netty.buffer ByteBuf forEachByte
public abstract int forEachByte(ByteProcessor processor);
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 . java 2 s . 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 w w w . j a va 2s .c o m 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);// w w w . jav 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 shouldSkipEmptyString() { ByteBuf source = Unpooled.copiedBuffer("{\"some\": \"\"}", CharsetUtil.UTF_8); int closingPos = source.forEachByte(new ClosingPositionBufProcessor('{', '}', true)); assertEquals(11, closingPos);/*from ww w . j av a2s. 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 w w .j a v a 2s .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);// w ww. jav a 2s.c o 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);//from w ww . j a va2s.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 ava2 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 testClosingPosNotFoundInPartialStringRightPart() { ByteBuf source = Unpooled.copiedBuffer("ring\"", CharsetUtil.UTF_8); int closingPos = source.forEachByte(new StringClosingPositionBufProcessor()); assertEquals(-1, closingPos);/*from w w w. j a v a2 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 ww w. ja va 2 s . c o m assertEquals(0, source.readerIndex()); }