List of usage examples for io.netty.buffer CompositeByteBuf capacity
@Override public CompositeByteBuf capacity(int newCapacity)
From source file:io.grpc.alts.internal.BufUnwrapperTest.java
License:Apache License
@Test public void writableNioBuffers_worksWithComposite() { CompositeByteBuf buf = alloc.compositeBuffer(); buf.addComponent(alloc.buffer(1));//from www.j a v a 2 s.c o m buf.capacity(1); try (BufUnwrapper unwrapper = new BufUnwrapper()) { ByteBuffer[] internalBufs = unwrapper.writableNioBuffers(buf); Truth.assertThat(internalBufs).hasLength(1); internalBufs[0].put((byte) 'a'); buf.writerIndex(1); assertEquals('a', buf.readByte()); } finally { buf.release(); } }
From source file:org.ebayopensource.scc.cache.NettyResponseDeserializer.java
License:Apache License
@Override public FullHttpResponse deserialize(CacheResponse cacheResp) { CompositeByteBuf byteBuf = UnpooledByteBufAllocator.DEFAULT.compositeBuffer(); if (cacheResp.getContent() != null) { byteBuf.capacity(cacheResp.getContent().length); byteBuf.setBytes(0, cacheResp.getContent()); byteBuf.writerIndex(cacheResp.getContent().length); }/*from ww w. j ava 2s. c om*/ DefaultFullHttpResponse response = new DefaultFullHttpResponse( HttpVersion.valueOf(cacheResp.getProtocalVersion()), new HttpResponseStatus(cacheResp.getCode(), cacheResp.getReasonPhrase()), byteBuf, true); HttpHeaders headers = response.headers(); List<CacheEntry<String, String>> cacheHeaders = cacheResp.getHeaders(); for (Entry<String, String> entry : cacheHeaders) { headers.add(entry.getKey(), entry.getValue()); } HttpHeaders trailingHeaders = response.trailingHeaders(); List<CacheEntry<String, String>> cacheTrailingHeaders = cacheResp.getTrailingHeaders(); for (Entry<String, String> entry : cacheTrailingHeaders) { trailingHeaders.add(entry.getKey(), entry.getValue()); } return response; }