GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Overview
  • Use
  • Tree
  • Deprecated
  • Index
  • Search
  • Help
  • io.netty.handler.codec
  • MessageToByteEncoder

This view

  • Original page
  • New address

GeezerVison is showing netty.io — MessageToByteEncoder (Netty API Reference (4.1.141.Final))

Class MessageToByteEncoder<I>

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelOutboundHandlerAdapter
io.netty.handler.codec.MessageToByteEncoder<I>
All Implemented Interfaces:
ChannelHandler, ChannelOutboundHandler
Direct Known Subclasses:
BrotliEncoder, Bzip2Encoder, CompatibleMarshallingEncoder, CompatibleObjectEncoder, FastLzFrameEncoder, HAProxyMessageEncoder, Lz4FrameEncoder, LzfEncoder, LzmaFrameEncoder, MarshallingEncoder, ObjectEncoder, ProtobufVarint32LengthFieldPrepender, SnappyFrameEncoder, Socks4ClientEncoder, Socks4ServerEncoder, Socks5ClientEncoder, Socks5ServerEncoder, SocksMessageEncoder, TcpDnsQueryEncoder, ZlibEncoder, ZstdEncoder

public abstract class MessageToByteEncoder<I> extends ChannelOutboundHandlerAdapter
ChannelOutboundHandlerAdapter which encodes message in a stream-like fashion from one message to an ByteBuf. Example implementation which encodes Integers to a ByteBuf.
    public class IntegerEncoder extends MessageToByteEncoder<Integer> {
        @Override
        public void encode(ChannelHandlerContext ctx, Integer msg, ByteBuf out)
                throws Exception {
            out.writeInt(msg);
        }
    }
  • Nested Class Summary

    Nested classes/interfaces inherited from interface ChannelHandler

    ChannelHandler.Sharable
    Modifier and Type
    Interface
    Description
    static @interface 
    ChannelHandler.Sharable
    Indicates that the same instance of the annotated ChannelHandler can be added to one or more ChannelPipelines multiple times without a race condition.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    MessageToByteEncoder()
    see MessageToByteEncoder(boolean) with true as boolean parameter.
    protected
    MessageToByteEncoder(boolean preferDirect)
    Create a new instance which will try to detect the types to match out of the type parameter of the class.
    protected
    MessageToByteEncoder(Class<? extends I> outboundMessageType)
    see MessageToByteEncoder(Class, boolean) with true as boolean value.
    protected
    MessageToByteEncoder(Class<? extends I> outboundMessageType, boolean preferDirect)
    Create a new instance
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    acceptOutboundMessage(Object msg)
    Returns true if the given message should be handled.
    protected ByteBuf
    allocateBuffer(ChannelHandlerContext ctx, I msg, boolean preferDirect)
    Allocate a ByteBuf which will be used as argument of encode(ChannelHandlerContext, I, ByteBuf).
    protected abstract void
    encode(ChannelHandlerContext ctx, I msg, ByteBuf out)
    Encode a message into a ByteBuf.
    protected boolean
    isPreferDirect()
     
    void
    write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
    Calls ChannelOutboundInvoker.write(Object, ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline.

    Methods inherited from class ChannelOutboundHandlerAdapter

    bind, close, connect, deregister, disconnect, flush, read
    Modifier and Type
    Method
    Description
    void
    bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise)
    Calls ChannelOutboundInvoker.bind(SocketAddress, ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline.
    void
    close(ChannelHandlerContext ctx, ChannelPromise promise)
    Calls ChannelOutboundInvoker.close(ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline.
    void
    connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise)
    Calls ChannelOutboundInvoker.connect(SocketAddress, SocketAddress, ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline.
    void
    deregister(ChannelHandlerContext ctx, ChannelPromise promise)
    Calls ChannelOutboundInvoker.deregister(ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline.
    void
    disconnect(ChannelHandlerContext ctx, ChannelPromise promise)
    Calls ChannelOutboundInvoker.disconnect(ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline.
    void
    flush(ChannelHandlerContext ctx)
    Calls ChannelHandlerContext.flush() to forward to the next ChannelOutboundHandler in the ChannelPipeline.
    void
    read(ChannelHandlerContext ctx)
    Calls ChannelHandlerContext.read() to forward to the next ChannelOutboundHandler in the ChannelPipeline.

    Methods inherited from class ChannelHandlerAdapter

    ensureNotSharable, exceptionCaught, handlerAdded, handlerRemoved, isSharable
    Modifier and Type
    Method
    Description
    protected void
    ensureNotSharable()
    Throws IllegalStateException if ChannelHandlerAdapter.isSharable() returns true
    void
    exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
    Deprecated.
    is part of ChannelInboundHandler
    void
    handlerAdded(ChannelHandlerContext ctx)
    Do nothing by default, sub-classes may override this method.
    void
    handlerRemoved(ChannelHandlerContext ctx)
    Do nothing by default, sub-classes may override this method.
    boolean
    isSharable()
    Return true if the implementation is ChannelHandler.Sharable and so can be added to different ChannelPipelines.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MessageToByteEncoder

      protected MessageToByteEncoder()
      see MessageToByteEncoder(boolean) with true as boolean parameter.
    • MessageToByteEncoder

      protected MessageToByteEncoder(Class<? extends I> outboundMessageType)
      see MessageToByteEncoder(Class, boolean) with true as boolean value.
    • MessageToByteEncoder

      protected MessageToByteEncoder(boolean preferDirect)
      Create a new instance which will try to detect the types to match out of the type parameter of the class.
      Parameters:
      preferDirect - true if a direct ByteBuf should be tried to be used as target for the encoded messages. If false is used it will allocate a heap ByteBuf, which is backed by an byte array.
    • MessageToByteEncoder

      protected MessageToByteEncoder(Class<? extends I> outboundMessageType, boolean preferDirect)
      Create a new instance
      Parameters:
      outboundMessageType - The type of messages to match
      preferDirect - true if a direct ByteBuf should be tried to be used as target for the encoded messages. If false is used it will allocate a heap ByteBuf, which is backed by an byte array.
  • Method Details

    • acceptOutboundMessage

      public boolean acceptOutboundMessage(Object msg) throws Exception
      Returns true if the given message should be handled. If false it will be passed to the next ChannelOutboundHandler in the ChannelPipeline.
      Throws:
      Exception
    • write

      public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception
      Description copied from class: ChannelOutboundHandlerAdapter
      Calls ChannelOutboundInvoker.write(Object, ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.
      Specified by:
      write in interface ChannelOutboundHandler
      Overrides:
      write in class ChannelOutboundHandlerAdapter
      Parameters:
      ctx - the ChannelHandlerContext for which the write operation is made
      msg - the message to write
      promise - the ChannelPromise to notify once the operation completes
      Throws:
      Exception - thrown if an error occurs
    • allocateBuffer

      protected ByteBuf allocateBuffer(ChannelHandlerContext ctx, I msg, boolean preferDirect) throws Exception
      Allocate a ByteBuf which will be used as argument of encode(ChannelHandlerContext, I, ByteBuf). Sub-classes may override this method to return ByteBuf with a perfect matching initialCapacity.
      Throws:
      Exception
    • encode

      protected abstract void encode(ChannelHandlerContext ctx, I msg, ByteBuf out) throws Exception
      Encode a message into a ByteBuf. This method will be called for each written message that can be handled by this encoder.
      Parameters:
      ctx - the ChannelHandlerContext which this MessageToByteEncoder belongs to
      msg - the message to encode
      out - the ByteBuf into which the encoded message will be written
      Throws:
      Exception - is thrown if an error occurs
    • isPreferDirect

      protected boolean isPreferDirect()
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.