Home / Class/ Utf8Validator Class — netty Architecture

Utf8Validator Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  a129a485_fea7_32eb_eedd_5a9aa67bad55["Utf8Validator"]
  79879148_1f84_23be_b8fb_f26fb13dd777["Utf8Validator.java"]
  a129a485_fea7_32eb_eedd_5a9aa67bad55 -->|defined in| 79879148_1f84_23be_b8fb_f26fb13dd777
  745c59ab_c53e_72aa_d446_1a90664f5eef["check()"]
  a129a485_fea7_32eb_eedd_5a9aa67bad55 -->|method| 745c59ab_c53e_72aa_d446_1a90664f5eef
  4f0efe15_7b6c_e8e7_147f_675582d756e8["finish()"]
  a129a485_fea7_32eb_eedd_5a9aa67bad55 -->|method| 4f0efe15_7b6c_e8e7_147f_675582d756e8
  1a919edd_6f09_5d0e_782f_c642472f5fca["process()"]
  a129a485_fea7_32eb_eedd_5a9aa67bad55 -->|method| 1a919edd_6f09_5d0e_782f_c642472f5fca
  6643108c_2e92_b403_d2da_041669ef4d4f["isChecking()"]
  a129a485_fea7_32eb_eedd_5a9aa67bad55 -->|method| 6643108c_2e92_b403_d2da_041669ef4d4f

Relationship Graph

Source Code

codec-http/src/main/java/io/netty/handler/codec/http/websocketx/Utf8Validator.java lines 44–110

final class Utf8Validator implements ByteProcessor {
    private static final int UTF8_ACCEPT = 0;
    private static final int UTF8_REJECT = 12;

    private static final byte[] TYPES = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,
            1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7, 7, 7, 7,
            7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8,
            8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
            2, 2, 10, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 3, 11, 6, 6, 6, 5, 8, 8, 8, 8, 8,
            8, 8, 8, 8, 8, 8 };

    private static final byte[] STATES = { 0, 12, 24, 36, 60, 96, 84, 12, 12, 12, 48, 72, 12, 12,
            12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 0, 12, 12, 12, 12, 12, 0, 12, 0, 12, 12,
            12, 24, 12, 12, 12, 12, 12, 24, 12, 24, 12, 12, 12, 12, 12, 12, 12, 12, 12, 24, 12, 12,
            12, 12, 12, 24, 12, 12, 12, 12, 12, 12, 12, 24, 12, 12, 12, 12, 12, 12, 12, 12, 12, 36,
            12, 36, 12, 12, 12, 36, 12, 12, 12, 12, 12, 36, 12, 36, 12, 12, 12, 36, 12, 12, 12, 12,
            12, 12, 12, 12, 12, 12 };

    @SuppressWarnings("RedundantFieldInitialization")
    private int state = UTF8_ACCEPT;
    private int codep;
    private boolean checking;

    public void check(ByteBuf buffer) {
        checking = true;
        buffer.forEachByte(this);
    }

    void check(ByteBuf buffer, int index, int length) {
        checking = true;
        buffer.forEachByte(index, length, this);
    }

    public void finish() {
        checking = false;
        codep = 0;
        if (state != UTF8_ACCEPT) {
            state = UTF8_ACCEPT;
            throw new CorruptedWebSocketFrameException(
                WebSocketCloseStatus.INVALID_PAYLOAD_DATA, "bytes are not UTF-8");
        }
    }

    @Override
    public boolean process(byte b) throws Exception {
        byte type = TYPES[b & 0xFF];

        codep = state != UTF8_ACCEPT ? b & 0x3f | codep << 6 : 0xff >> type & b;

        state = STATES[state + type];

        if (state == UTF8_REJECT) {
            checking = false;
            throw new CorruptedWebSocketFrameException(
                WebSocketCloseStatus.INVALID_PAYLOAD_DATA, "bytes are not UTF-8");
        }
        return true;
    }

    public boolean isChecking() {
        return checking;
    }
}

Frequently Asked Questions

What is the Utf8Validator class?
Utf8Validator is a class in the netty codebase, defined in codec-http/src/main/java/io/netty/handler/codec/http/websocketx/Utf8Validator.java.
Where is Utf8Validator defined?
Utf8Validator is defined in codec-http/src/main/java/io/netty/handler/codec/http/websocketx/Utf8Validator.java at line 44.

Analyze Your Own Codebase

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

Try Supermodel Free