Class ObjectEncoder
- java.lang.Object
-
- org.jboss.netty.handler.codec.oneone.OneToOneEncoder
-
- org.jboss.netty.handler.codec.serialization.ObjectEncoder
-
- All Implemented Interfaces:
ChannelDownstreamHandler
,ChannelHandler
@Sharable public class ObjectEncoder extends OneToOneEncoder
An encoder which serializes a Java object into aChannelBuffer
.Please note that the serialized form this encoder produces is not compatible with the standard
ObjectInputStream
. Please useObjectDecoder
orObjectDecoderInputStream
to ensure the interoperability with this encoder.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.jboss.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
-
Field Summary
Fields Modifier and Type Field Description private int
estimatedLength
private static byte[]
LENGTH_PLACEHOLDER
-
Constructor Summary
Constructors Constructor Description ObjectEncoder()
Creates a new encoder with the estimated length of 512 bytes.ObjectEncoder(int estimatedLength)
Creates a new encoder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.-
Methods inherited from class org.jboss.netty.handler.codec.oneone.OneToOneEncoder
doEncode, handleDownstream
-
-
-
-
Constructor Detail
-
ObjectEncoder
public ObjectEncoder()
Creates a new encoder with the estimated length of 512 bytes.
-
ObjectEncoder
public ObjectEncoder(int estimatedLength)
Creates a new encoder.- Parameters:
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.
-
-
Method Detail
-
encode
protected java.lang.Object encode(ChannelHandlerContext ctx, Channel channel, java.lang.Object msg) throws java.lang.Exception
Description copied from class:OneToOneEncoder
Transforms the specified message into another message and return the transformed message. Note that you can not returnnull
, unlike you can inOneToOneDecoder.decode(ChannelHandlerContext, Channel, Object)
; you must return something, at leastChannelBuffers.EMPTY_BUFFER
.- Specified by:
encode
in classOneToOneEncoder
- Throws:
java.lang.Exception
-
-