@Test public void encodeContentShared() throws Exception { ProtocolCodecSessionEx session = new ProtocolCodecSessionEx(); IoBufferAllocatorEx<?> allocator = session.getBufferAllocator(); ProtocolEncoder encoder = new HttpResponseEncoder(allocator); HttpBufferAllocator httpAllocator = new HttpBufferAllocator(allocator); IoBufferEx data = httpAllocator.wrap(ByteBuffer.wrap("Hello, world".getBytes()), FLAG_SHARED); HttpContentMessage httpContent = new HttpContentMessage(data, true); encoder.encode(session, httpContent, session.getEncoderOutput()); IoBufferEx buf = (IoBufferEx) session.getEncoderOutputQueue().poll(); assertEquals("Hello, world", buf.getString(Charset.forName("UTF-8").newDecoder())); assertSame(data.array(), buf.array()); }
@Override protected void encode(IoSessionEx session, HttpMessage httpMessage, ProtocolEncoderOutput out) throws Exception { switch (httpMessage.getKind()) { case CONTENT: HttpContentMessage httpContent = (HttpContentMessage)httpMessage; encodeContent(session, httpContent, out); break; case RESPONSE: HttpResponseMessage httpResponse = (HttpResponseMessage)httpMessage; encodeResponse(session, httpResponse, out); break; default: throw new ProtocolEncoderException("Unexpected HTTP message kind: " + httpMessage.getKind()); } }
HttpResponseEncoder extends HttpMessageEncoder<HttpResponseMessage> { @Override protected void encode(IoSessionEx session, HttpMessage httpMessage, ProtocolEncoderOutput out) throws Exception { switch (httpMessage.getKind()) { case CONTENT: HttpContentMessage httpContent = (HttpContentMessage)httpMessage; encodeContent(session, httpContent, out); break; case RESPONSE: HttpResponseMessage httpResponse = (HttpResponseMessage)httpMessage; encodeResponse(session, httpResponse, out); break; default: throw new ProtocolEncoderException("Unexpected HTTP message kind: " + httpMessage.getKind()); } } }
HttpResponseEncoder extends HttpMessageEncoder<HttpResponseMessage> { @Override protected void encode(IoSessionEx session, HttpMessage httpMessage, ProtocolEncoderOutput out) throws Exception { switch (httpMessage.getKind()) { case CONTENT: HttpContentMessage httpContent = (HttpContentMessage)httpMessage; encodeContent(session, httpContent, out); break; case RESPONSE: HttpResponseMessage httpResponse = (HttpResponseMessage)httpMessage; encodeResponse(session, httpResponse, out); break; default: throw new ProtocolEncoderException("Unexpected HTTP message kind: " + httpMessage.getKind()); } } HttpResponseEncoder(IoBufferAllocatorEx<?> allocator);  HttpResponseEncoder(CachingMessageEncoder cachingEncoder, IoBufferAllocatorEx<?> allocator); }
HttpResponseEncoder extends HttpMessageEncoder<HttpResponseMessage> { @Override protected void encode(IoSessionEx session, HttpMessage httpMessage, ProtocolEncoderOutput out) throws Exception { switch (httpMessage.getKind()) { case CONTENT: HttpContentMessage httpContent = (HttpContentMessage)httpMessage; encodeContent(session, httpContent, out); break; case RESPONSE: HttpResponseMessage httpResponse = (HttpResponseMessage)httpMessage; encodeResponse(session, httpResponse, out); break; default: throw new ProtocolEncoderException("Unexpected HTTP message kind: " + httpMessage.getKind()); } } HttpResponseEncoder(IoBufferAllocatorEx<?> allocator);  HttpResponseEncoder(CachingMessageEncoder cachingEncoder, IoBufferAllocatorEx<?> allocator);  }
HttpResponseEncoder extends HttpMessageEncoder<HttpResponseMessage> { @Override protected void encode(IoSessionEx session, HttpMessage httpMessage, ProtocolEncoderOutput out) throws Exception { switch (httpMessage.getKind()) { case CONTENT: HttpContentMessage httpContent = (HttpContentMessage)httpMessage; encodeContent(session, httpContent, out); break; case RESPONSE: HttpResponseMessage httpResponse = (HttpResponseMessage)httpMessage; encodeResponse(session, httpResponse, out); break; default: throw new ProtocolEncoderException("Unexpected HTTP message kind: " + httpMessage.getKind()); } } HttpResponseEncoder(IoBufferAllocatorEx<?> allocator);  HttpResponseEncoder(CachingMessageEncoder cachingEncoder, IoBufferAllocatorEx<?> allocator);   }