Example usage for io.netty.buffer CompositeByteBuf setBytes

List of usage examples for io.netty.buffer CompositeByteBuf setBytes

Introduction

In this page you can find the example usage for io.netty.buffer CompositeByteBuf setBytes.

Prototype

@Override
    public CompositeByteBuf setBytes(int index, byte[] src) 

Source Link

Usage

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