Class CompatibleObjectEncoder
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelOutboundHandlerAdapter
-
- io.netty.handler.codec.MessageToByteEncoder<java.io.Serializable>
-
- io.netty.handler.codec.serialization.CompatibleObjectEncoder
-
- All Implemented Interfaces:
ChannelHandler
,ChannelOutboundHandler
public class CompatibleObjectEncoder extends MessageToByteEncoder<java.io.Serializable>
An encoder which serializes a Java object into aByteBuf
(interoperability version).This encoder is interoperable with the standard Java object streams such as
ObjectInputStream
andObjectOutputStream
.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
-
Field Summary
Fields Modifier and Type Field Description private int
resetInterval
private int
writtenObjects
-
Constructor Summary
Constructors Constructor Description CompatibleObjectEncoder()
Creates a new instance with the reset interval of16
.CompatibleObjectEncoder(int resetInterval)
Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
encode(ChannelHandlerContext ctx, java.io.Serializable msg, ByteBuf out)
Encode a message into aByteBuf
.protected java.io.ObjectOutputStream
newObjectOutputStream(java.io.OutputStream out)
Creates a newObjectOutputStream
which wraps the specifiedOutputStream
.-
Methods inherited from class io.netty.handler.codec.MessageToByteEncoder
acceptOutboundMessage, allocateBuffer, isPreferDirect, write
-
Methods inherited from class io.netty.channel.ChannelOutboundHandlerAdapter
bind, close, connect, deregister, disconnect, flush, read
-
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, exceptionCaught, handlerAdded, handlerRemoved, isSharable
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty.channel.ChannelHandler
exceptionCaught, handlerAdded, handlerRemoved
-
-
-
-
Constructor Detail
-
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 Detail
-
newObjectOutputStream
protected java.io.ObjectOutputStream newObjectOutputStream(java.io.OutputStream out) throws java.lang.Exception
Creates a newObjectOutputStream
which wraps the specifiedOutputStream
. Override this method to use a subclass of theObjectOutputStream
.- Throws:
java.lang.Exception
-
encode
protected void encode(ChannelHandlerContext ctx, java.io.Serializable msg, ByteBuf out) throws java.lang.Exception
Description copied from class:MessageToByteEncoder
Encode a message into aByteBuf
. This method will be called for each written message that can be handled by this encoder.- Specified by:
encode
in classMessageToByteEncoder<java.io.Serializable>
- Parameters:
ctx
- theChannelHandlerContext
which thisMessageToByteEncoder
belongs tomsg
- the message to encodeout
- theByteBuf
into which the encoded message will be written- Throws:
java.lang.Exception
- is thrown if an error occurs
-
-