[#902] Remove usage of generics for output of Encoder/Decoder to make them more flexible again

This commit is contained in:
Norman Maurer 2013-01-08 08:18:46 +01:00
parent 5d2e0688ab
commit b742dcc209
40 changed files with 97 additions and 100 deletions

View File

@ -47,7 +47,7 @@ import java.util.Map.Entry;
* @apiviz.landmark
* @apiviz.has io.netty.handler.codec.http.HttpChunk oneway - - filters out
*/
public class HttpChunkAggregator extends MessageToMessageDecoder<HttpObject, HttpMessage> {
public class HttpChunkAggregator extends MessageToMessageDecoder<HttpObject> {
public static final int DEFAULT_MAX_COMPOSITEBUFFER_COMPONENTS = 1024;
private static final ByteBuf CONTINUE = Unpooled.copiedBuffer(
"HTTP/1.1 100 Continue\r\n\r\n", CharsetUtil.US_ASCII);
@ -110,7 +110,7 @@ public class HttpChunkAggregator extends MessageToMessageDecoder<HttpObject, Htt
}
@Override
protected HttpMessage decode(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
protected Object decode(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
HttpMessage currentMessage = this.currentMessage;
if (msg instanceof HttpMessage) {

View File

@ -40,7 +40,7 @@ import io.netty.handler.codec.MessageToMessageDecoder;
* so that this handler can intercept HTTP requests after {@link HttpMessageDecoder}
* converts {@link ByteBuf}s into HTTP requests.
*/
public abstract class HttpContentDecoder extends MessageToMessageDecoder<Object, Object> {
public abstract class HttpContentDecoder extends MessageToMessageDecoder<Object> {
private EmbeddedByteChannel decoder;

View File

@ -46,7 +46,7 @@ import java.util.Queue;
* so that this handler can intercept HTTP responses before {@link HttpMessageEncoder}
* converts them into {@link ByteBuf}s.
*/
public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpMessage, HttpMessage, Object, Object> {
public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpMessage, Object> {
private final Queue<String> acceptEncodingQueue = new ArrayDeque<String>();
private EmbeddedByteChannel encoder;
@ -61,7 +61,7 @@ public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpMessa
}
@Override
protected HttpMessage decode(ChannelHandlerContext ctx, HttpMessage msg)
protected Object decode(ChannelHandlerContext ctx, HttpMessage msg)
throws Exception {
String acceptedEncoding = msg.getHeader(HttpHeaders.Names.ACCEPT_ENCODING);
if (acceptedEncoding == null) {

View File

@ -98,7 +98,7 @@ import java.util.List;
* implement all abstract methods properly.
* @apiviz.landmark
*/
public abstract class HttpMessageDecoder extends ReplayingDecoder<Object, HttpMessageDecoder.State> {
public abstract class HttpMessageDecoder extends ReplayingDecoder<HttpMessageDecoder.State> {
private final int maxInitialLineLength;
private final int maxHeaderSize;

View File

@ -29,7 +29,7 @@ import io.netty.handler.codec.TooLongFrameException;
* @apiviz.landmark
* @apiviz.uses io.netty.handler.codec.http.websocket.WebSocketFrame
*/
public class WebSocket00FrameDecoder extends ReplayingDecoder<WebSocketFrame, Void> {
public class WebSocket00FrameDecoder extends ReplayingDecoder<Void> {
static final int DEFAULT_MAX_FRAME_SIZE = 16384;
@ -52,7 +52,7 @@ public class WebSocket00FrameDecoder extends ReplayingDecoder<WebSocketFrame, Vo
}
@Override
public WebSocketFrame decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
public Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
// Discard all data received if closing handshake was received before.
if (receivedClosingHandshake) {
in.skipBytes(actualReadableBytes());

View File

@ -67,7 +67,7 @@ import io.netty.logging.InternalLoggerFactory;
* Decodes a web socket frame from wire protocol version 8 format. This code was forked from <a
* href="https://github.com/joewalnes/webbit">webbit</a> and modified.
*/
public class WebSocket08FrameDecoder extends ReplayingDecoder<WebSocketFrame, WebSocket08FrameDecoder.State> {
public class WebSocket08FrameDecoder extends ReplayingDecoder<WebSocket08FrameDecoder.State> {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(WebSocket08FrameDecoder.class);
@ -118,7 +118,7 @@ public class WebSocket08FrameDecoder extends ReplayingDecoder<WebSocketFrame, We
}
@Override
public WebSocketFrame decode(
public Object decode(
ChannelHandlerContext ctx, ByteBuf in) throws Exception {
// Discard all data received if closing handshake was received before.

View File

@ -25,7 +25,7 @@ import io.netty.handler.codec.TooLongFrameException;
/**
* Decodes {@link ByteBuf}s into SPDY Data and Control Frames.
*/
public class SpdyFrameDecoder extends ByteToMessageDecoder<Object> {
public class SpdyFrameDecoder extends ByteToMessageDecoder {
private final int spdyVersion;
private final int maxChunkSize;

View File

@ -31,7 +31,7 @@ import static io.netty.handler.codec.spdy.SpdyCodecUtil.*;
/**
* Encodes a SPDY Data or Control Frame into a {@link ByteBuf}.
*/
public class SpdyFrameEncoder extends MessageToByteEncoder<Object> {
public class SpdyFrameEncoder extends MessageToByteEncoder {
private final int version;
private volatile boolean finished;

View File

@ -37,7 +37,7 @@ import java.util.Map;
* Decodes {@link SpdySynStreamFrame}s, {@link SpdySynReplyFrame}s,
* and {@link SpdyDataFrame}s into {@link HttpRequest}s and {@link HttpResponse}s.
*/
public class SpdyHttpDecoder extends MessageToMessageDecoder<Object, HttpMessage> {
public class SpdyHttpDecoder extends MessageToMessageDecoder<Object> {
private final int spdyVersion;
private final int maxContentLength;
@ -67,7 +67,7 @@ public class SpdyHttpDecoder extends MessageToMessageDecoder<Object, HttpMessage
}
@Override
public HttpMessage decode(ChannelHandlerContext ctx, Object msg) throws Exception {
public Object decode(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof SpdySynStreamFrame) {
// HTTP requests/responses are mapped one-to-one to SPDY streams.

View File

@ -119,7 +119,7 @@ import java.util.Map;
* All pushed resources should be sent before sending the response
* that corresponds to the initial request.
*/
public class SpdyHttpEncoder extends MessageToMessageEncoder<Object, Object> {
public class SpdyHttpEncoder extends MessageToMessageEncoder<Object> {
private final int spdyVersion;
private volatile int currentStreamId;

View File

@ -29,7 +29,7 @@ import io.netty.handler.codec.http.HttpResponse;
* for HTTP.
*/
public class SpdyHttpResponseStreamIdHandler extends
MessageToMessageCodec<Object, Object, HttpMessage, HttpMessage> {
MessageToMessageCodec<Object, HttpMessage> {
private static final Integer NO_ID = -1;
private final Queue<Integer> ids = new LinkedList<Integer>();
@ -38,7 +38,7 @@ public class SpdyHttpResponseStreamIdHandler extends
}
@Override
protected HttpMessage encode(ChannelHandlerContext ctx, HttpMessage msg) throws Exception {
protected Object encode(ChannelHandlerContext ctx, HttpMessage msg) throws Exception {
Integer id = ids.poll();
if (id != null && id.intValue() != NO_ID && !msg.containsHeader(SpdyHttpHeaders.Names.STREAM_ID)) {
SpdyHttpHeaders.setStreamId(msg, id);

View File

@ -24,7 +24,7 @@ import io.netty.util.CharsetUtil;
* Decodes {@link ByteBuf}s into {@link SocksAuthRequest}.
* Before returning SocksRequest decoder removes itself from pipeline.
*/
public class SocksAuthRequestDecoder extends ReplayingDecoder<SocksRequest, SocksAuthRequestDecoder.State> {
public class SocksAuthRequestDecoder extends ReplayingDecoder<SocksAuthRequestDecoder.State> {
private static final String name = "SOCKS_AUTH_REQUEST_DECODER";
public static String getName() {
@ -42,7 +42,7 @@ public class SocksAuthRequestDecoder extends ReplayingDecoder<SocksRequest, Sock
}
@Override
public SocksRequest decode(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception {
public Object decode(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception {
switch (state()) {
case CHECK_PROTOCOL_VERSION: {
version = SocksMessage.SubnegotiationVersion.fromByte(byteBuf.readByte());

View File

@ -23,7 +23,7 @@ import io.netty.handler.codec.ReplayingDecoder;
* Decodes {@link ByteBuf}s into {@link SocksAuthResponse}.
* Before returning SocksResponse decoder removes itself from pipeline.
*/
public class SocksAuthResponseDecoder extends ReplayingDecoder<SocksResponse, SocksAuthResponseDecoder.State> {
public class SocksAuthResponseDecoder extends ReplayingDecoder<SocksAuthResponseDecoder.State> {
private static final String name = "SOCKS_AUTH_RESPONSE_DECODER";
public static String getName() {
@ -39,7 +39,7 @@ public class SocksAuthResponseDecoder extends ReplayingDecoder<SocksResponse, So
}
@Override
public SocksResponse decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf) throws Exception {
public Object decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf) throws Exception {
switch (state()) {
case CHECK_PROTOCOL_VERSION: {
version = SocksMessage.SubnegotiationVersion.fromByte(byteBuf.readByte());

View File

@ -24,7 +24,7 @@ import io.netty.util.CharsetUtil;
* Decodes {@link ByteBuf}s into {@link SocksCmdRequest}.
* Before returning SocksRequest decoder removes itself from pipeline.
*/
public class SocksCmdRequestDecoder extends ReplayingDecoder<SocksRequest, SocksCmdRequestDecoder.State> {
public class SocksCmdRequestDecoder extends ReplayingDecoder<SocksCmdRequestDecoder.State> {
private static final String name = "SOCKS_CMD_REQUEST_DECODER";
public static String getName() {
@ -45,8 +45,7 @@ public class SocksCmdRequestDecoder extends ReplayingDecoder<SocksRequest, Socks
}
@Override
public SocksRequest decode(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception {
public Object decode(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception {
switch (state()) {
case CHECK_PROTOCOL_VERSION: {
version = SocksMessage.ProtocolVersion.fromByte(byteBuf.readByte());

View File

@ -24,7 +24,7 @@ import io.netty.util.CharsetUtil;
* Decodes {@link ByteBuf}s into {@link SocksCmdResponse}.
* Before returning SocksResponse decoder removes itself from pipeline.
*/
public class SocksCmdResponseDecoder extends ReplayingDecoder<SocksResponse, SocksCmdResponseDecoder.State> {
public class SocksCmdResponseDecoder extends ReplayingDecoder<SocksCmdResponseDecoder.State> {
private static final String name = "SOCKS_CMD_RESPONSE_DECODER";
public static String getName() {
@ -45,7 +45,7 @@ public class SocksCmdResponseDecoder extends ReplayingDecoder<SocksResponse, Soc
}
@Override
public SocksResponse decode(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception {
public Object decode(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception {
switch (state()) {
case CHECK_PROTOCOL_VERSION: {

View File

@ -26,7 +26,7 @@ import java.util.List;
* Decodes {@link ByteBuf}s into {@link SocksInitRequest}.
* Before returning SocksRequest decoder removes itself from pipeline.
*/
public class SocksInitRequestDecoder extends ReplayingDecoder<SocksRequest, SocksInitRequestDecoder.State> {
public class SocksInitRequestDecoder extends ReplayingDecoder<SocksInitRequestDecoder.State> {
private static final String name = "SOCKS_INIT_REQUEST_DECODER";
public static String getName() {
@ -43,7 +43,7 @@ public class SocksInitRequestDecoder extends ReplayingDecoder<SocksRequest, Sock
}
@Override
public SocksRequest decode(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception {
public Object decode(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception {
switch (state()) {
case CHECK_PROTOCOL_VERSION: {
version = SocksMessage.ProtocolVersion.fromByte(byteBuf.readByte());

View File

@ -23,7 +23,7 @@ import io.netty.handler.codec.ReplayingDecoder;
* Decodes {@link ByteBuf}s into {@link SocksInitResponse}.
* Before returning SocksResponse decoder removes itself from pipeline.
*/
public class SocksInitResponseDecoder extends ReplayingDecoder<SocksResponse, SocksInitResponseDecoder.State> {
public class SocksInitResponseDecoder extends ReplayingDecoder<SocksInitResponseDecoder.State> {
private static final String name = "SOCKS_INIT_RESPONSE_DECODER";
public static String getName() {

View File

@ -24,36 +24,35 @@ import io.netty.channel.ChannelInboundByteHandler;
import io.netty.channel.ChannelOutboundMessageHandler;
import io.netty.channel.ChannelPromise;
public abstract class ByteToMessageCodec<INBOUND_OUT, OUTBOUND_IN>
extends ChannelHandlerAdapter
implements ChannelInboundByteHandler, ChannelOutboundMessageHandler<OUTBOUND_IN> {
public abstract class ByteToMessageCodec<I> extends ChannelHandlerAdapter
implements ChannelInboundByteHandler, ChannelOutboundMessageHandler<I> {
private final Class<?>[] encodableMessageTypes;
private final MessageToByteEncoder<OUTBOUND_IN> encoder;
private final ByteToMessageDecoder<INBOUND_OUT> decoder;
private final MessageToByteEncoder<I> encoder;
private final ByteToMessageDecoder decoder;
protected ByteToMessageCodec(Class<?>... encodableMessageTypes) {
this.encodableMessageTypes = encodableMessageTypes;
encoder = new MessageToByteEncoder<OUTBOUND_IN>() {
encoder = new MessageToByteEncoder<I>() {
@Override
public boolean isEncodable(Object msg) throws Exception {
return ByteToMessageCodec.this.isEncodable(msg);
}
@Override
protected void encode(ChannelHandlerContext ctx, OUTBOUND_IN msg, ByteBuf out) throws Exception {
protected void encode(ChannelHandlerContext ctx, I msg, ByteBuf out) throws Exception {
ByteToMessageCodec.this.encode(ctx, msg, out);
}
};
decoder = new ByteToMessageDecoder<INBOUND_OUT>() {
decoder = new ByteToMessageDecoder() {
@Override
public INBOUND_OUT decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
public Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
return ByteToMessageCodec.this.decode(ctx, in);
}
@Override
protected INBOUND_OUT decodeLast(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
protected Object decodeLast(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
return ByteToMessageCodec.this.decodeLast(ctx, in);
}
};
@ -80,7 +79,7 @@ public abstract class ByteToMessageCodec<INBOUND_OUT, OUTBOUND_IN>
}
@Override
public MessageBuf<OUTBOUND_IN> newOutboundBuffer(ChannelHandlerContext ctx) throws Exception {
public MessageBuf<I> newOutboundBuffer(ChannelHandlerContext ctx) throws Exception {
return encoder.newOutboundBuffer(ctx);
}
@ -103,9 +102,9 @@ public abstract class ByteToMessageCodec<INBOUND_OUT, OUTBOUND_IN>
return ChannelHandlerUtil.acceptMessage(encodableMessageTypes, msg);
}
protected abstract void encode(ChannelHandlerContext ctx, OUTBOUND_IN msg, ByteBuf out) throws Exception;
protected abstract INBOUND_OUT decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception;
protected INBOUND_OUT decodeLast(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
protected abstract void encode(ChannelHandlerContext ctx, I msg, ByteBuf out) throws Exception;
protected abstract Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception;
protected Object decodeLast(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
return decode(ctx, in);
}
}

View File

@ -30,16 +30,16 @@ import io.netty.channel.ChannelPipeline;
* the input {@link ByteBuf} and create a new {@link ByteBuf}.
*
* <pre>
* public class SquareDecoder extends {@link ByteToMessageDecoder}&lt;{@link ByteBuf}&gt; {
* public class SquareDecoder extends {@link ByteToMessageDecoder} {
* {@code @Override}
* public {@link ByteBuf} decode({@link ChannelHandlerContext} ctx, {@link ByteBuf} in)
* public {@link Object} decode({@link ChannelHandlerContext} ctx, {@link ByteBuf} in)
* throws {@link Exception} {
* return in.readBytes(in.readableBytes());
* }
* }
* </pre>
*/
public abstract class ByteToMessageDecoder<O>
public abstract class ByteToMessageDecoder
extends ChannelInboundHandlerAdapter implements ChannelInboundByteHandler {
private ChannelHandlerContext ctx;
@ -94,7 +94,7 @@ public abstract class ByteToMessageDecoder<O>
while (in.readable()) {
try {
int oldInputLength = in.readableBytes();
O o = decode(ctx, in);
Object o = decode(ctx, in);
if (o == null) {
if (oldInputLength == in.readableBytes()) {
break;
@ -167,7 +167,7 @@ public abstract class ByteToMessageDecoder<O>
* there was not enough data left in the {@link ByteBuf} to decode.
* @throws Exception is thrown if an error accour
*/
protected abstract O decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception;
protected abstract Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception;
/**
* Is called one last time when the {@link ChannelHandlerContext} goes in-active. Which means the
@ -176,7 +176,7 @@ public abstract class ByteToMessageDecoder<O>
* By default this will just call {@link #decode(ChannelHandlerContext, ByteBuf)} but sub-classes may
* override this for some special cleanup operation.
*/
protected O decodeLast(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
protected Object decodeLast(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
return decode(ctx, in);
}
}

View File

@ -54,7 +54,7 @@ import io.netty.channel.ChannelHandlerContext;
* </pre>
* @apiviz.uses io.netty.handler.codec.Delimiters - - useful
*/
public class DelimiterBasedFrameDecoder extends ByteToMessageDecoder<Object> {
public class DelimiterBasedFrameDecoder extends ByteToMessageDecoder {
private final ByteBuf[] delimiters;
private final int maxFrameLength;

View File

@ -34,7 +34,7 @@ import io.netty.channel.ChannelHandlerContext;
* +-----+-----+-----+
* </pre>
*/
public class FixedLengthFrameDecoder extends ByteToMessageDecoder<Object> {
public class FixedLengthFrameDecoder extends ByteToMessageDecoder {
private final int frameLength;
private final boolean allocateFullBuffer;

View File

@ -179,7 +179,7 @@ import io.netty.handler.codec.serialization.ObjectDecoder;
* </pre>
* @see LengthFieldPrepender
*/
public class LengthFieldBasedFrameDecoder extends ByteToMessageDecoder<Object> {
public class LengthFieldBasedFrameDecoder extends ByteToMessageDecoder {
private final int maxFrameLength;
private final int lengthFieldOffset;

View File

@ -24,7 +24,7 @@ import io.netty.channel.ChannelHandlerContext;
* Both {@code "\n"} and {@code "\r\n"} are handled.
* For a more general delimiter-based decoder, see {@link DelimiterBasedFrameDecoder}.
*/
public class LineBasedFrameDecoder extends ByteToMessageDecoder<ByteBuf> {
public class LineBasedFrameDecoder extends ByteToMessageDecoder {
/** Maximum length of a frame we're willing to decode. */
private final int maxLength;
@ -67,8 +67,7 @@ public class LineBasedFrameDecoder extends ByteToMessageDecoder<ByteBuf> {
}
@Override
protected ByteBuf decode(ChannelHandlerContext ctx, ByteBuf buffer) throws Exception {
protected Object decode(ChannelHandlerContext ctx, ByteBuf buffer) throws Exception {
final int eol = findEndOfLine(buffer);
if (eol != -1) {
final ByteBuf frame;

View File

@ -48,20 +48,20 @@ import io.netty.channel.ChannelPromise;
* }
* </pre>
*/
public abstract class MessageToMessageCodec<INBOUND_IN, INBOUND_OUT, OUTBOUND_IN, OUTBOUND_OUT>
public abstract class MessageToMessageCodec<INBOUND_IN, OUTBOUND_IN>
extends ChannelHandlerAdapter
implements ChannelInboundMessageHandler<INBOUND_IN>,
ChannelOutboundMessageHandler<OUTBOUND_IN> {
private final MessageToMessageEncoder<OUTBOUND_IN, OUTBOUND_OUT> encoder =
new MessageToMessageEncoder<OUTBOUND_IN, OUTBOUND_OUT>() {
private final MessageToMessageEncoder<OUTBOUND_IN> encoder =
new MessageToMessageEncoder<OUTBOUND_IN>() {
@Override
public boolean isEncodable(Object msg) throws Exception {
return MessageToMessageCodec.this.isEncodable(msg);
}
@Override
public OUTBOUND_OUT encode(ChannelHandlerContext ctx, OUTBOUND_IN msg) throws Exception {
public Object encode(ChannelHandlerContext ctx, OUTBOUND_IN msg) throws Exception {
return MessageToMessageCodec.this.encode(ctx, msg);
}
@ -71,15 +71,15 @@ public abstract class MessageToMessageCodec<INBOUND_IN, INBOUND_OUT, OUTBOUND_IN
}
};
private final MessageToMessageDecoder<INBOUND_IN, INBOUND_OUT> decoder =
new MessageToMessageDecoder<INBOUND_IN, INBOUND_OUT>() {
private final MessageToMessageDecoder<INBOUND_IN> decoder =
new MessageToMessageDecoder<INBOUND_IN>() {
@Override
public boolean isDecodable(Object msg) throws Exception {
return MessageToMessageCodec.this.isDecodable(msg);
}
@Override
public INBOUND_OUT decode(ChannelHandlerContext ctx, INBOUND_IN msg) throws Exception {
public Object decode(ChannelHandlerContext ctx, INBOUND_IN msg) throws Exception {
return MessageToMessageCodec.this.decode(ctx, msg);
}
@ -151,8 +151,8 @@ public abstract class MessageToMessageCodec<INBOUND_IN, INBOUND_OUT, OUTBOUND_IN
return ChannelHandlerUtil.acceptMessage(acceptedOutboundMsgTypes, msg);
}
protected abstract OUTBOUND_OUT encode(ChannelHandlerContext ctx, OUTBOUND_IN msg) throws Exception;
protected abstract INBOUND_OUT decode(ChannelHandlerContext ctx, INBOUND_IN msg) throws Exception;
protected abstract Object encode(ChannelHandlerContext ctx, OUTBOUND_IN msg) throws Exception;
protected abstract Object decode(ChannelHandlerContext ctx, INBOUND_IN msg) throws Exception;
protected void freeInboundMessage(INBOUND_IN msg) throws Exception {
ChannelHandlerUtil.freeMessage(msg);

View File

@ -31,13 +31,13 @@ import io.netty.channel.ChannelPipeline;
*
* <pre>
* public class StringToIntegerDecoder extends
* {@link MessageToMessageDecoder}&lt;{@link String},{@link Integer}&gt; {
* {@link MessageToMessageDecoder}&lt;{@link String}&gt; {
* public StringToIntegerDecoder() {
* super(String.class);
* }
*
* {@code @Override}
* public {@link Integer} decode({@link ChannelHandlerContext} ctx, {@link String} message)
* public {@link Object} decode({@link ChannelHandlerContext} ctx, {@link String} message)
* throws {@link Exception} {
* return message.length());
* }
@ -45,7 +45,7 @@ import io.netty.channel.ChannelPipeline;
* </pre>
*
*/
public abstract class MessageToMessageDecoder<I, O>
public abstract class MessageToMessageDecoder<I>
extends ChannelInboundHandlerAdapter implements ChannelInboundMessageHandler<I> {
private final Class<?>[] acceptedMsgTypes;
@ -84,7 +84,7 @@ public abstract class MessageToMessageDecoder<I, O>
I imsg = (I) msg;
boolean free = true;
try {
O omsg = decode(ctx, imsg);
Object omsg = decode(ctx, imsg);
if (omsg == null) {
// Decoder consumed a message but returned null.
// Probably it needs more messages because it's an aggregator.
@ -131,7 +131,7 @@ public abstract class MessageToMessageDecoder<I, O>
* needs to do some kind of aggragation
* @throws Exception is thrown if an error accour
*/
protected abstract O decode(ChannelHandlerContext ctx, I msg) throws Exception;
protected abstract Object decode(ChannelHandlerContext ctx, I msg) throws Exception;
/**
* Is called after a message was processed via {@link #decode(ChannelHandlerContext, Object)} to free

View File

@ -31,13 +31,13 @@ import io.netty.channel.PartialFlushException;
*
* <pre>
* public class IntegerToStringEncoder extends
* {@link MessageToMessageEncoder}&lt;{@link Integer},{@link String}&gt; {
* {@link MessageToMessageEncoder}&lt;{@link Integer}&gt; {
* public StringToIntegerDecoder() {
* super(String.class);
* }
*
* {@code @Override}
* public {@link String} encode({@link ChannelHandlerContext} ctx, {@link Integer} message)
* public {@link Object} encode({@link ChannelHandlerContext} ctx, {@link Integer} message)
* throws {@link Exception} {
* return message.toString();
* }
@ -45,7 +45,7 @@ import io.netty.channel.PartialFlushException;
* </pre>
*
*/
public abstract class MessageToMessageEncoder<I, O> extends ChannelOutboundMessageHandlerAdapter<I> {
public abstract class MessageToMessageEncoder<I> extends ChannelOutboundMessageHandlerAdapter<I> {
private final Class<?>[] acceptedMsgTypes;
@ -78,7 +78,7 @@ public abstract class MessageToMessageEncoder<I, O> extends ChannelOutboundMessa
I imsg = (I) msg;
boolean free = true;
try {
O omsg = encode(ctx, imsg);
Object omsg = encode(ctx, imsg);
if (omsg == null) {
// encode() might be waiting for more inbound messages to generate
// an aggregated message - keep polling.
@ -130,7 +130,7 @@ public abstract class MessageToMessageEncoder<I, O> extends ChannelOutboundMessa
* needs to do some kind of aggragation
* @throws Exception is thrown if an error accour
*/
protected abstract O encode(ChannelHandlerContext ctx, I msg) throws Exception;
protected abstract Object encode(ChannelHandlerContext ctx, I msg) throws Exception;
/**
* Is called after a message was processed via {@link #encode(ChannelHandlerContext, Object)} to free

View File

@ -167,7 +167,7 @@ import io.netty.util.internal.Signal;
* }
*
* public class IntegerHeaderFrameDecoder
* extends {@link ReplayingDecoder}&lt;{@link ByteBuf}, <strong>MyDecoderState</strong>&gt; {
* extends {@link ReplayingDecoder}&lt;<strong>MyDecoderState</strong>&gt; {
*
* private int length;
*
@ -177,7 +177,7 @@ import io.netty.util.internal.Signal;
* }
*
* {@code @Override}
* protected {@link ByteBuf} decode({@link ChannelHandlerContext} ctx,
* protected {@link Object} decode({@link ChannelHandlerContext} ctx,
* {@link ByteBuf} in) throws Exception {
* switch (state()) {
* case READ_LENGTH:
@ -199,13 +199,13 @@ import io.netty.util.internal.Signal;
* An alternative way to manage the decoder state is to manage it by yourself.
* <pre>
* public class IntegerHeaderFrameDecoder
* extends {@link ReplayingDecoder}&lt;{@link ByteBuf},<strong>{@link Void}</strong>&gt; {
* extends {@link ReplayingDecoder}&lt;<strong>{@link Void}</strong>&gt; {
*
* <strong>private boolean readLength;</strong>
* private int length;
*
* {@code @Override}
* protected {@link ByteBuf} decode({@link ChannelHandlerContext} ctx,
* protected {@link Object} decode({@link ChannelHandlerContext} ctx,
* {@link ByteBuf} in) throws Exception {
* if (!readLength) {
* length = buf.readInt();
@ -233,7 +233,7 @@ import io.netty.util.internal.Signal;
* {@link ChannelPipeline#replace(ChannelHandler, String, ChannelHandler)}, but
* some additional steps are required:
* <pre>
* public class FirstDecoder extends {@link ReplayingDecoder}&lt;{@link Object}, {@link Void}&gt; {
* public class FirstDecoder extends {@link ReplayingDecoder}&lt;{@link Void}&gt; {
*
* {@code @Override}
* protected Object decode({@link ChannelHandlerContext} ctx,
@ -264,7 +264,7 @@ import io.netty.util.internal.Signal;
* @apiviz.landmark
* @apiviz.has io.netty.handler.codec.UnreplayableOperationException oneway - - throws
*/
public abstract class ReplayingDecoder<O, S> extends ByteToMessageDecoder<O> {
public abstract class ReplayingDecoder<S> extends ByteToMessageDecoder {
static final Signal REPLAY = new Signal(ReplayingDecoder.class.getName() + ".REPLAY");

View File

@ -44,7 +44,7 @@ import io.netty.handler.codec.MessageToMessageDecoder;
* @apiviz.uses io.netty.handler.codec.base64.Base64
*/
@Sharable
public class Base64Decoder extends MessageToMessageDecoder<ByteBuf, ByteBuf> {
public class Base64Decoder extends MessageToMessageDecoder<ByteBuf> {
private final Base64Dialect dialect;
@ -62,7 +62,7 @@ public class Base64Decoder extends MessageToMessageDecoder<ByteBuf, ByteBuf> {
}
@Override
protected ByteBuf decode(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
protected Object decode(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
return Base64.decode(msg, msg.readerIndex(), msg.readableBytes(), dialect);
}
}

View File

@ -40,7 +40,7 @@ import io.netty.handler.codec.MessageToMessageEncoder;
* @apiviz.uses io.netty.handler.codec.base64.Base64
*/
@Sharable
public class Base64Encoder extends MessageToMessageEncoder<ByteBuf, ByteBuf> {
public class Base64Encoder extends MessageToMessageEncoder<ByteBuf> {
private final boolean breakLines;
private final Base64Dialect dialect;
@ -65,7 +65,7 @@ public class Base64Encoder extends MessageToMessageEncoder<ByteBuf, ByteBuf> {
}
@Override
protected ByteBuf encode(ChannelHandlerContext ctx,
protected Object encode(ChannelHandlerContext ctx,
ByteBuf msg) throws Exception {
return Base64.encode(msg, msg.readerIndex(), msg.readableBytes(), breakLines, dialect);
}

View File

@ -46,14 +46,14 @@ import io.netty.handler.codec.MessageToMessageDecoder;
* }
* </pre>
*/
public class ByteArrayDecoder extends MessageToMessageDecoder<ByteBuf, byte[]> {
public class ByteArrayDecoder extends MessageToMessageDecoder<ByteBuf> {
public ByteArrayDecoder() {
super(ByteBuf.class);
}
@Override
protected byte[] decode(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
protected Object decode(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
byte[] array;
if (msg.hasArray()) {
if (msg.arrayOffset() == 0 && msg.readableBytes() == msg.capacity()) {

View File

@ -48,7 +48,7 @@ import io.netty.handler.codec.MessageToMessageEncoder;
* }
* </pre>
*/
public class ByteArrayEncoder extends MessageToMessageEncoder<byte[], ByteBuf> {
public class ByteArrayEncoder extends MessageToMessageEncoder<byte[]> {
public ByteArrayEncoder() {
super(byte[].class);

View File

@ -30,7 +30,7 @@ import java.io.ObjectStreamConstants;
*
* If you can you should use {@link MarshallingDecoder}.
*/
public class CompatibleMarshallingDecoder extends ReplayingDecoder<Object, Void> {
public class CompatibleMarshallingDecoder extends ReplayingDecoder<Void> {
protected final UnmarshallerProvider provider;
protected final int maxObjectSize;
private boolean discardingTooLongFrame;

View File

@ -61,7 +61,7 @@ import com.google.protobuf.MessageLite;
* @apiviz.landmark
*/
@Sharable
public class ProtobufDecoder extends MessageToMessageDecoder<ByteBuf, MessageLite> {
public class ProtobufDecoder extends MessageToMessageDecoder<ByteBuf> {
private final MessageLite prototype;
private final ExtensionRegistry extensionRegistry;
@ -84,7 +84,7 @@ public class ProtobufDecoder extends MessageToMessageDecoder<ByteBuf, MessageLit
}
@Override
protected MessageLite decode(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
protected Object decode(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
if (msg.hasArray()) {
final int offset = msg.readerIndex();
if (extensionRegistry == null) {

View File

@ -56,14 +56,14 @@ import com.google.protobuf.MessageLite;
* @apiviz.landmark
*/
@Sharable
public class ProtobufEncoder extends MessageToMessageEncoder<Object, ByteBuf> {
public class ProtobufEncoder extends MessageToMessageEncoder<Object> {
public ProtobufEncoder() {
super(MessageLite.class, MessageLite.Builder.class);
}
@Override
protected ByteBuf encode(ChannelHandlerContext ctx, Object msg) throws Exception {
protected Object encode(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof MessageLite) {
return wrappedBuffer(((MessageLite) msg).toByteArray());
}

View File

@ -37,7 +37,7 @@ import com.google.protobuf.CodedInputStream;
*
* @see CodedInputStream
*/
public class ProtobufVarint32FrameDecoder extends ByteToMessageDecoder<Object> {
public class ProtobufVarint32FrameDecoder extends ByteToMessageDecoder {
// TODO maxFrameLength + safe skip + fail-fast option
// (just like LengthFieldBasedFrameDecoder)

View File

@ -52,7 +52,7 @@ import java.nio.charset.Charset;
* @apiviz.landmark
*/
@Sharable
public class StringDecoder extends MessageToMessageDecoder<ByteBuf, String> {
public class StringDecoder extends MessageToMessageDecoder<ByteBuf> {
// TODO Use CharsetDecoder instead.
private final Charset charset;
@ -77,7 +77,7 @@ public class StringDecoder extends MessageToMessageDecoder<ByteBuf, String> {
}
@Override
protected String decode(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
protected Object decode(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
return msg.toString(charset);
}
}

View File

@ -48,7 +48,7 @@ import java.nio.charset.Charset;
* @apiviz.landmark
*/
@Sharable
public class StringEncoder extends MessageToMessageEncoder<CharSequence, ByteBuf> {
public class StringEncoder extends MessageToMessageEncoder<CharSequence> {
// TODO Use CharsetEncoder instead.
private final Charset charset;
@ -73,7 +73,7 @@ public class StringEncoder extends MessageToMessageEncoder<CharSequence, ByteBuf
}
@Override
protected ByteBuf encode(ChannelHandlerContext ctx, CharSequence msg) throws Exception {
protected Object encode(ChannelHandlerContext ctx, CharSequence msg) throws Exception {
return Unpooled.copiedBuffer(msg, charset);
}
}

View File

@ -47,7 +47,7 @@ public class ReplayingDecoderTest {
assertNull(ch.readInbound());
}
private static final class LineDecoder extends ReplayingDecoder<ByteBuf, Void> {
private static final class LineDecoder extends ReplayingDecoder<Void> {
LineDecoder() {
}

View File

@ -28,7 +28,7 @@ import java.math.BigInteger;
* {@link BigInteger} instance. For example, { 'F', 0, 0, 0, 1, 42 } will be
* decoded into new BigInteger("42").
*/
public class BigIntegerDecoder extends ByteToMessageDecoder<BigInteger> {
public class BigIntegerDecoder extends ByteToMessageDecoder {
@Override
public BigInteger decode(ChannelHandlerContext ctx, ByteBuf in) {

View File

@ -20,7 +20,7 @@ import io.netty.channel.socket.sctp.SctpMessage;
import io.netty.handler.codec.CodecException;
import io.netty.handler.codec.MessageToMessageDecoder;
public abstract class SctpMessageToMessageDecoder<O> extends MessageToMessageDecoder<SctpMessage, O> {
public abstract class SctpMessageToMessageDecoder extends MessageToMessageDecoder<SctpMessage> {
@Override
public boolean isDecodable(Object msg) throws Exception {