@ChannelHandler.Sharable public class ObjectEncoder extends OneToOneEncoder
ChannelBuffer.
Please note that the serialized form this encoder produces is not
compatible with the standard ObjectInputStream. Please use
ObjectDecoder or ObjectDecoderInputStream to ensure the
interoperability with this encoder.
ChannelHandler.Sharable| Modifier and Type | Field and Description |
|---|---|
private int |
estimatedLength |
private static byte[] |
LENGTH_PLACEHOLDER |
| Constructor and Description |
|---|
ObjectEncoder()
Creates a new encoder with the estimated length of 512 bytes.
|
ObjectEncoder(int estimatedLength)
Creates a new encoder.
|
| Modifier and Type | Method and Description |
|---|---|
protected java.lang.Object |
encode(ChannelHandlerContext ctx,
Channel channel,
java.lang.Object msg)
Transforms the specified message into another message and return the
transformed message.
|
doEncode, handleDownstreamprivate static final byte[] LENGTH_PLACEHOLDER
private final int estimatedLength
public ObjectEncoder()
public ObjectEncoder(int estimatedLength)
estimatedLength - the estimated byte length of the serialized form of an object.
If the length of the serialized form exceeds this value, the
internal buffer will be expanded automatically at the cost of
memory bandwidth. If this value is too big, it will also waste
memory bandwidth. To avoid unnecessary memory copy or allocation
cost, please specify the properly estimated value.protected java.lang.Object encode(ChannelHandlerContext ctx, Channel channel, java.lang.Object msg) throws java.lang.Exception
OneToOneEncodernull, unlike
you can in OneToOneDecoder.decode(ChannelHandlerContext, Channel, Object);
you must return something, at least ChannelBuffers.EMPTY_BUFFER.encode in class OneToOneEncoderjava.lang.Exception