List of usage examples for io.netty.util CharsetUtil UTF_8
Charset UTF_8
To view the source code for io.netty.util CharsetUtil UTF_8.
Click Source Link
From source file:com.couchbase.client.core.endpoint.search.SearchHandler.java
License:Apache License
@Override protected HttpRequest encodeRequest(ChannelHandlerContext ctx, SearchRequest msg) throws Exception { HttpMethod httpMethod = HttpMethod.GET; if (msg instanceof UpsertSearchIndexRequest) { httpMethod = HttpMethod.PUT;/*w w w . ja v a 2 s . c o m*/ } else if (msg instanceof RemoveSearchIndexRequest) { httpMethod = HttpMethod.DELETE; } else if (msg instanceof SearchQueryRequest) { httpMethod = HttpMethod.POST; } ByteBuf content; if (msg instanceof UpsertSearchIndexRequest) { content = Unpooled.copiedBuffer(((UpsertSearchIndexRequest) msg).payload(), CharsetUtil.UTF_8); } else if (msg instanceof SearchQueryRequest) { content = Unpooled.copiedBuffer(((SearchQueryRequest) msg).payload(), CharsetUtil.UTF_8); } else { content = Unpooled.EMPTY_BUFFER; } FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, httpMethod, msg.path(), content); request.headers().set(HttpHeaders.Names.USER_AGENT, env().userAgent()); if (msg instanceof UpsertSearchIndexRequest || msg instanceof SearchQueryRequest) { request.headers().set(HttpHeaders.Names.ACCEPT, "*/*"); request.headers().set(HttpHeaders.Names.CONTENT_TYPE, "application/json"); } request.headers().set(HttpHeaders.Names.CONTENT_LENGTH, content.readableBytes()); request.headers().set(HttpHeaders.Names.HOST, remoteHttpHost(ctx)); addHttpBasicAuth(ctx, request, msg.bucket(), msg.password()); return request; }
From source file:com.couchbase.client.core.endpoint.util.ByteBufJsonHelperTest.java
License:Apache License
@Test public void testFindNextChar() throws Exception { ByteBuf source = Unpooled.copiedBuffer("ABCDEF", CharsetUtil.UTF_8); assertEquals(3, ByteBufJsonHelper.findNextChar(source, 'D')); assertEquals(-1, ByteBufJsonHelper.findNextChar(source, 'G')); assertEquals(0, source.readerIndex()); }
From source file:com.couchbase.client.core.endpoint.util.ByteBufJsonHelperTest.java
License:Apache License
@Test public void testFindNextCharNotPrefixedBy() throws Exception { ByteBuf source = Unpooled.copiedBuffer("the \\\"end\\\" of a string\"", CharsetUtil.UTF_8); assertEquals(5, ByteBufJsonHelper.findNextCharNotPrefixedBy(source, '\"', 'a')); assertEquals(23, ByteBufJsonHelper.findNextCharNotPrefixedBy(source, '\"', '\\')); assertEquals(-1, ByteBufJsonHelper.findNextCharNotPrefixedBy(source, 'a', ' ')); assertEquals(-1, ByteBufJsonHelper.findNextCharNotPrefixedBy(source, 'z', ' ')); assertEquals(0, source.readerIndex()); }
From source file:com.couchbase.client.core.endpoint.util.ByteBufJsonHelperTest.java
License:Apache License
/** * See JVMCBC-239.//from w w w.j ava 2 s . co 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); 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);// w w w . j av a2 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 shouldNotFindClosingInBrokenSection() { ByteBuf source = Unpooled.copiedBuffer("{ this is simple", CharsetUtil.UTF_8); int closingPos = source.forEachByte(new ClosingPositionBufProcessor('{', '}')); assertEquals(-1, closingPos);//from w ww . j a v a 2s . com assertEquals(0, source.readerIndex()); }