Decoder Class — netty Architecture
Architecture documentation for the Decoder class in Base64.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 28e851bb_9265_53b6_adb0_c9cb3a05d218["Decoder"] d7a67d90_6cda_f8ab_09c1_a5a0692512cc["Base64.java"] 28e851bb_9265_53b6_adb0_c9cb3a05d218 -->|defined in| d7a67d90_6cda_f8ab_09c1_a5a0692512cc 74bdbf8f_873e_a2b1_95c7_3ecf25a01412["ByteBuf()"] 28e851bb_9265_53b6_adb0_c9cb3a05d218 -->|method| 74bdbf8f_873e_a2b1_95c7_3ecf25a01412 4d39ba07_cab0_b244_3cdb_710ee60e1b2d["process()"] 28e851bb_9265_53b6_adb0_c9cb3a05d218 -->|method| 4d39ba07_cab0_b244_3cdb_710ee60e1b2d ecb75b44_a34c_e912_2204_cd8b6698abcb["decode4to3()"] 28e851bb_9265_53b6_adb0_c9cb3a05d218 -->|method| ecb75b44_a34c_e912_2204_cd8b6698abcb
Relationship Graph
Source Code
codec-base/src/main/java/io/netty/handler/codec/base64/Base64.java lines 373–501
private static final class Decoder implements ByteProcessor {
private final byte[] b4 = new byte[4];
private int b4Posn;
private byte[] decodabet;
private int outBuffPosn;
private ByteBuf dest;
ByteBuf decode(ByteBuf src, int off, int len, ByteBufAllocator allocator, Base64Dialect dialect) {
dest = allocator.buffer(decodedBufferSize(len)).order(src.order()); // Upper limit on size of output
decodabet = decodabet(dialect);
try {
src.forEachByte(off, len, this);
// Padding missing, process additional bytes
if (b4Posn == 1) {
throw new IllegalArgumentException(
"Invalid Base64 input, single remaining character implies incorrect length or padding");
} else if (b4Posn == 2) {
b4[2] = EQUALS_SIGN;
b4[3] = EQUALS_SIGN;
outBuffPosn += decode4to3(b4, dest, outBuffPosn, decodabet);
} else if (b4Posn == 3) {
b4[3] = EQUALS_SIGN;
outBuffPosn += decode4to3(b4, dest, outBuffPosn, decodabet);
}
return dest.slice(0, outBuffPosn);
} catch (Throwable cause) {
dest.release();
PlatformDependent.throwException(cause);
return null;
}
}
@Override
public boolean process(byte value) throws Exception {
if (value > 0) {
byte sbiDecode = decodabet[value];
if (sbiDecode >= WHITE_SPACE_ENC) { // White space, Equals sign or better
if (sbiDecode >= EQUALS_SIGN_ENC) { // Equals sign or better
b4[b4Posn ++] = value;
if (b4Posn > 3) { // Quartet built
outBuffPosn += decode4to3(b4, dest, outBuffPosn, decodabet);
b4Posn = 0;
// If that was the equals sign, break out of 'for' loop
return value != EQUALS_SIGN;
}
}
return true;
}
}
throw new IllegalArgumentException(
"invalid Base64 input character: " + (short) (value & 0xFF) + " (decimal)");
}
private static int decode4to3(byte[] src, ByteBuf dest, int destOffset, byte[] decodabet) {
final byte src0 = src[0];
final byte src1 = src[1];
final byte src2 = src[2];
final int decodedValue;
if (src2 == EQUALS_SIGN) {
// Example: Dk==
try {
decodedValue = (decodabet[src0] & 0xff) << 2 | (decodabet[src1] & 0xff) >>> 4;
} catch (IndexOutOfBoundsException ignored) {
throw new IllegalArgumentException("not encoded in Base64");
}
dest.setByte(destOffset, decodedValue);
return 1;
}
final byte src3 = src[3];
if (src3 == EQUALS_SIGN) {
// Example: DkL=
final byte b1 = decodabet[src1];
// Packing bytes into a short to reduce bound and reference count checking.
try {
if (dest.order() == ByteOrder.BIG_ENDIAN) {
// The decodabet bytes are meant to straddle byte boundaries and so we must carefully mask out
Source
Frequently Asked Questions
What is the Decoder class?
Decoder is a class in the netty codebase, defined in codec-base/src/main/java/io/netty/handler/codec/base64/Base64.java.
Where is Decoder defined?
Decoder is defined in codec-base/src/main/java/io/netty/handler/codec/base64/Base64.java at line 373.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free