Home / Class/ LineEncoder Class — netty Architecture

LineEncoder Class — netty Architecture

Architecture documentation for the LineEncoder class in LineEncoder.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  d6e3a5a7_eb4f_a549_dda2_c575dde055e9["LineEncoder"]
  e4deebe5_1ef4_1b06_7360_eccc45a32838["LineEncoder.java"]
  d6e3a5a7_eb4f_a549_dda2_c575dde055e9 -->|defined in| e4deebe5_1ef4_1b06_7360_eccc45a32838
  da68b081_2a17_6928_3f69_e51fdf33e285["LineEncoder()"]
  d6e3a5a7_eb4f_a549_dda2_c575dde055e9 -->|method| da68b081_2a17_6928_3f69_e51fdf33e285
  1a70a7b2_b375_85d8_a79e_5c91f48d1051["encode()"]
  d6e3a5a7_eb4f_a549_dda2_c575dde055e9 -->|method| 1a70a7b2_b375_85d8_a79e_5c91f48d1051

Relationship Graph

Source Code

codec-base/src/main/java/io/netty/handler/codec/string/LineEncoder.java lines 53–95

@Sharable
public class LineEncoder extends MessageToMessageEncoder<CharSequence> {

    private final Charset charset;
    private final byte[] lineSeparator;

    /**
     * Creates a new instance with the current system line separator and UTF-8 charset encoding.
     */
    public LineEncoder() {
        this(LineSeparator.DEFAULT, CharsetUtil.UTF_8);
    }

    /**
     * Creates a new instance with the specified line separator and UTF-8 charset encoding.
     */
    public LineEncoder(LineSeparator lineSeparator) {
        this(lineSeparator, CharsetUtil.UTF_8);
    }

    /**
     * Creates a new instance with the specified character set.
     */
    public LineEncoder(Charset charset) {
        this(LineSeparator.DEFAULT, charset);
    }

    /**
     * Creates a new instance with the specified line separator and character set.
     */
    public LineEncoder(LineSeparator lineSeparator, Charset charset) {
        super(CharSequence.class);
        this.charset = ObjectUtil.checkNotNull(charset, "charset");
        this.lineSeparator = ObjectUtil.checkNotNull(lineSeparator, "lineSeparator").value().getBytes(charset);
    }

    @Override
    protected void encode(ChannelHandlerContext ctx, CharSequence msg, List<Object> out) throws Exception {
        ByteBuf buffer = ByteBufUtil.encodeString(ctx.alloc(), CharBuffer.wrap(msg), charset, lineSeparator.length);
        buffer.writeBytes(lineSeparator);
        out.add(buffer);
    }
}

Frequently Asked Questions

What is the LineEncoder class?
LineEncoder is a class in the netty codebase, defined in codec-base/src/main/java/io/netty/handler/codec/string/LineEncoder.java.
Where is LineEncoder defined?
LineEncoder is defined in codec-base/src/main/java/io/netty/handler/codec/string/LineEncoder.java at line 53.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free