Class CompatibleObjectEncoder
java.lang.Object
org.jboss.netty.handler.codec.oneone.OneToOneEncoder
org.jboss.netty.handler.codec.serialization.CompatibleObjectEncoder
- All Implemented Interfaces:
ChannelDownstreamHandler
,ChannelHandler
An encoder which serializes a Java object into a
ChannelBuffer
(interoperability version).
This encoder is interoperable with the standard Java object streams such as
ObjectInputStream
and ObjectOutputStream
.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jboss.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicReference
<ChannelBuffer> private ObjectOutputStream
private final int
private int
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance with the reset interval of16
.CompatibleObjectEncoder
(int resetInterval) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionprivate ChannelBuffer
protected Object
encode
(ChannelHandlerContext context, Channel channel, Object msg) Transforms the specified message into another message and return the transformed message.protected ObjectOutputStream
Creates a newObjectOutputStream
which wraps the specifiedOutputStream
.Methods inherited from class org.jboss.netty.handler.codec.oneone.OneToOneEncoder
doEncode, handleDownstream
-
Field Details
-
buffer
-
resetInterval
private final int resetInterval -
oout
-
writtenObjects
private int writtenObjects
-
-
Constructor Details
-
CompatibleObjectEncoder
public CompatibleObjectEncoder()Creates a new instance with the reset interval of16
. -
CompatibleObjectEncoder
public CompatibleObjectEncoder(int resetInterval) Creates a new instance.- Parameters:
resetInterval
- the number of objects betweenObjectOutputStream.reset()
.0
will disable resetting the stream, but the remote peer will be at the risk of gettingOutOfMemoryError
in the long term.
-
-
Method Details
-
newObjectOutputStream
Creates a newObjectOutputStream
which wraps the specifiedOutputStream
. Override this method to use a subclass of theObjectOutputStream
.- Throws:
Exception
-
encode
protected Object encode(ChannelHandlerContext context, Channel channel, Object msg) throws 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:
Exception
-
buffer
- Throws:
Exception
-