Class CompatibleObjectEncoder
- java.lang.Object
-
- io.netty5.channel.ChannelHandlerAdapter
-
- io.netty5.handler.codec.MessageToByteEncoder<Serializable>
-
- io.netty.contrib.handler.codec.serialization.CompatibleObjectEncoder
-
- All Implemented Interfaces:
io.netty5.channel.ChannelHandler
public class CompatibleObjectEncoder extends io.netty5.handler.codec.MessageToByteEncoder<Serializable>
An encoder which serializes a Java object into aBuffer(interoperability version).This encoder is interoperable with the standard Java object streams such as
ObjectInputStreamandObjectOutputStream.
-
-
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 io.netty5.buffer.BufferallocateBuffer(io.netty5.channel.ChannelHandlerContext ctx, Serializable serializable)protected voidencode(io.netty5.channel.ChannelHandlerContext ctx, Serializable msg, io.netty5.buffer.Buffer out)protected ObjectOutputStreamnewObjectOutputStream(OutputStream out)Creates a newObjectOutputStreamwhich wraps the specifiedOutputStream.-
Methods inherited from class io.netty5.handler.codec.MessageToByteEncoder
acceptOutboundMessage, write
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty5.channel.ChannelHandler
bind, channelActive, channelExceptionCaught, channelInactive, channelInboundEvent, channelRead, channelReadComplete, channelRegistered, channelShutdown, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, flush, handlerAdded, handlerRemoved, isSharable, pendingOutboundBytes, read, register, sendOutboundEvent, shutdown
-
-
-
-
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().0will disable resetting the stream, but the remote peer will be at the risk of gettingOutOfMemoryErrorin the long term.
-
-
Method Detail
-
allocateBuffer
protected io.netty5.buffer.Buffer allocateBuffer(io.netty5.channel.ChannelHandlerContext ctx, Serializable serializable)- Specified by:
allocateBufferin classio.netty5.handler.codec.MessageToByteEncoder<Serializable>
-
newObjectOutputStream
protected ObjectOutputStream newObjectOutputStream(OutputStream out) throws Exception
Creates a newObjectOutputStreamwhich wraps the specifiedOutputStream. Override this method to use a subclass of theObjectOutputStream.- Throws:
Exception
-
encode
protected void encode(io.netty5.channel.ChannelHandlerContext ctx, Serializable msg, io.netty5.buffer.Buffer out) throws Exception- Specified by:
encodein classio.netty5.handler.codec.MessageToByteEncoder<Serializable>- Throws:
Exception
-
-