Home / Class/ XmlFrameDecoder Class — netty Architecture

XmlFrameDecoder Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  7d6b87e5_eb7b_72e0_1afd_174c09a039b0["XmlFrameDecoder"]
  7b9914b6_4628_4fb7_e86d_e7e85c93168d["XmlFrameDecoder.java"]
  7d6b87e5_eb7b_72e0_1afd_174c09a039b0 -->|defined in| 7b9914b6_4628_4fb7_e86d_e7e85c93168d
  384fe0ce_cc1a_3df3_3080_49fc2ea0d4aa["XmlFrameDecoder()"]
  7d6b87e5_eb7b_72e0_1afd_174c09a039b0 -->|method| 384fe0ce_cc1a_3df3_3080_49fc2ea0d4aa
  16b71bcb_9bc6_dcdf_9d02_291227b77db6["decode()"]
  7d6b87e5_eb7b_72e0_1afd_174c09a039b0 -->|method| 16b71bcb_9bc6_dcdf_9d02_291227b77db6
  23b37d5f_23cf_0f21_3b33_fd790dcc0476["fail()"]
  7d6b87e5_eb7b_72e0_1afd_174c09a039b0 -->|method| 23b37d5f_23cf_0f21_3b33_fd790dcc0476
  5f2ef599_fbcc_987b_bcb8_09a6ce041d72["ByteBuf()"]
  7d6b87e5_eb7b_72e0_1afd_174c09a039b0 -->|method| 5f2ef599_fbcc_987b_bcb8_09a6ce041d72
  5e926dca_a4e1_c95b_d634_6ca4f87b600b["isValidStartCharForXmlElement()"]
  7d6b87e5_eb7b_72e0_1afd_174c09a039b0 -->|method| 5e926dca_a4e1_c95b_d634_6ca4f87b600b
  3a7fee41_cc4a_eb14_8d1a_edf3de107e18["isCommentBlockStart()"]
  7d6b87e5_eb7b_72e0_1afd_174c09a039b0 -->|method| 3a7fee41_cc4a_eb14_8d1a_edf3de107e18
  56cf43c0_f19c_4ce5_a232_f932718a5dd2["isCDATABlockStart()"]
  7d6b87e5_eb7b_72e0_1afd_174c09a039b0 -->|method| 56cf43c0_f19c_4ce5_a232_f932718a5dd2

Relationship Graph

Source Code

codec-xml/src/main/java/io/netty/handler/codec/xml/XmlFrameDecoder.java lines 78–245

public class XmlFrameDecoder extends ByteToMessageDecoder {

    private final int maxFrameLength;

    public XmlFrameDecoder(int maxFrameLength) {
        this.maxFrameLength = checkPositive(maxFrameLength, "maxFrameLength");
    }

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        boolean openingBracketFound = false;
        boolean atLeastOneXmlElementFound = false;
        boolean inCDATASection = false;
        long openBracketsCount = 0;
        int length = 0;
        int leadingWhiteSpaceCount = 0;
        final int bufferLength = in.writerIndex();

        if (bufferLength > maxFrameLength) {
            // bufferLength exceeded maxFrameLength; dropping frame
            in.skipBytes(in.readableBytes());
            fail(bufferLength);
            return;
        }

        for (int i = in.readerIndex(); i < bufferLength; i++) {
            final byte readByte = in.getByte(i);
            if (!openingBracketFound && Character.isWhitespace(readByte)) {
                // xml has not started and whitespace char found
                leadingWhiteSpaceCount++;
            } else if (!openingBracketFound && readByte != '<') {
                // garbage found before xml start
                fail(ctx);
                in.skipBytes(in.readableBytes());
                return;
            } else if (!inCDATASection && readByte == '<') {
                openingBracketFound = true;

                if (i < bufferLength - 1) {
                    final byte peekAheadByte = in.getByte(i + 1);
                    if (peekAheadByte == '/') {
                        // found </, we must check if it is enclosed
                        int peekFurtherAheadIndex = i + 2;
                        while (peekFurtherAheadIndex <= bufferLength - 1) {
                            //if we have </ and enclosing > we can decrement openBracketsCount
                            if (in.getByte(peekFurtherAheadIndex) == '>') {
                                openBracketsCount--;
                                break;
                            }
                            peekFurtherAheadIndex++;
                        }
                    } else if (isValidStartCharForXmlElement(peekAheadByte)) {
                        atLeastOneXmlElementFound = true;
                        // char after < is a valid xml element start char,
                        // incrementing openBracketsCount
                        openBracketsCount++;
                    } else if (peekAheadByte == '!') {
                        if (isCommentBlockStart(in, i)) {
                            // <!-- comment --> start found
                            openBracketsCount++;
                        } else if (isCDATABlockStart(in, i)) {
                            // <![CDATA[ start found
                            openBracketsCount++;
                            inCDATASection = true;
                        }
                    } else if (peekAheadByte == '?') {
                        // <?xml ?> start found
                        openBracketsCount++;
                    }
                }
            } else if (!inCDATASection && readByte == '/') {
                if (i < bufferLength - 1 && in.getByte(i + 1) == '>') {
                    // found />, decrementing openBracketsCount
                    openBracketsCount--;
                }
            } else if (readByte == '>') {
                length = i + 1;

                if (i - 1 > -1) {
                    final byte peekBehindByte = in.getByte(i - 1);

Frequently Asked Questions

What is the XmlFrameDecoder class?
XmlFrameDecoder is a class in the netty codebase, defined in codec-xml/src/main/java/io/netty/handler/codec/xml/XmlFrameDecoder.java.
Where is XmlFrameDecoder defined?
XmlFrameDecoder is defined in codec-xml/src/main/java/io/netty/handler/codec/xml/XmlFrameDecoder.java at line 78.

Analyze Your Own Codebase

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

Try Supermodel Free