Home / Class/ AsciiHeadersEncoder Class — netty Architecture

AsciiHeadersEncoder Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  2d4cfb24_f9fc_cd74_6a9e_3f7bbcc2d798["AsciiHeadersEncoder"]
  aec626bf_7e11_0641_2f70_71c87da7f8d5["AsciiHeadersEncoder.java"]
  2d4cfb24_f9fc_cd74_6a9e_3f7bbcc2d798 -->|defined in| aec626bf_7e11_0641_2f70_71c87da7f8d5
  19354230_7334_44db_a9a0_9f45d2f5b818["AsciiHeadersEncoder()"]
  2d4cfb24_f9fc_cd74_6a9e_3f7bbcc2d798 -->|method| 19354230_7334_44db_a9a0_9f45d2f5b818
  cbf087d0_8177_7060_1807_d17087c928dc["encode()"]
  2d4cfb24_f9fc_cd74_6a9e_3f7bbcc2d798 -->|method| cbf087d0_8177_7060_1807_d17087c928dc
  24207862_67c2_d169_8677_4c6636680266["writeAscii()"]
  2d4cfb24_f9fc_cd74_6a9e_3f7bbcc2d798 -->|method| 24207862_67c2_d169_8677_4c6636680266

Relationship Graph

Source Code

codec-base/src/main/java/io/netty/handler/codec/AsciiHeadersEncoder.java lines 28–121

public final class AsciiHeadersEncoder {

    /**
     * The separator characters to insert between a header name and a header value.
     */
    public enum SeparatorType {
        /**
         * {@code ':'}
         */
        COLON,
        /**
         * {@code ': '}
         */
        COLON_SPACE,
    }

    /**
     * The newline characters to insert between header entries.
     */
    public enum NewlineType {
        /**
         * {@code '\n'}
         */
        LF,
        /**
         * {@code '\r\n'}
         */
        CRLF
    }

    private final ByteBuf buf;
    private final SeparatorType separatorType;
    private final NewlineType newlineType;

    public AsciiHeadersEncoder(ByteBuf buf) {
        this(buf, SeparatorType.COLON_SPACE, NewlineType.CRLF);
    }

    public AsciiHeadersEncoder(ByteBuf buf, SeparatorType separatorType, NewlineType newlineType) {
        this.buf = ObjectUtil.checkNotNull(buf, "buf");
        this.separatorType = ObjectUtil.checkNotNull(separatorType, "separatorType");
        this.newlineType = ObjectUtil.checkNotNull(newlineType, "newlineType");
    }

    public void encode(Entry<CharSequence, CharSequence> entry) {
        final CharSequence name = entry.getKey();
        final CharSequence value = entry.getValue();
        final ByteBuf buf = this.buf;
        final int nameLen = name.length();
        final int valueLen = value.length();
        final int entryLen = nameLen + valueLen + 4;
        int offset = buf.writerIndex();
        buf.ensureWritable(entryLen);
        writeAscii(buf, offset, name);
        offset += nameLen;

        switch (separatorType) {
            case COLON:
                buf.setByte(offset ++, ':');
                break;
            case COLON_SPACE:
                buf.setByte(offset ++, ':');
                buf.setByte(offset ++, ' ');
                break;
            default:
                throw new Error("Unexpected separator type: " + separatorType);
        }

        writeAscii(buf, offset, value);
        offset += valueLen;

        switch (newlineType) {
            case LF:
                buf.setByte(offset ++, '\n');
                break;
            case CRLF:
                buf.setByte(offset ++, '\r');
                buf.setByte(offset ++, '\n');
                break;
            default:
                throw new Error("Unexpected newline type: " + newlineType);

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free