SmtpResponseDecoder Class — netty Architecture
Architecture documentation for the SmtpResponseDecoder class in SmtpResponseDecoder.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 676d2047_352d_72b6_2e56_db05dff1e4bc["SmtpResponseDecoder"] fa35c420_7d0e_7f4a_8576_17c588eba008["SmtpResponseDecoder.java"] 676d2047_352d_72b6_2e56_db05dff1e4bc -->|defined in| fa35c420_7d0e_7f4a_8576_17c588eba008 54240ede_1f25_4ad1_d455_44014e5e6754["SmtpResponseDecoder()"] 676d2047_352d_72b6_2e56_db05dff1e4bc -->|method| 54240ede_1f25_4ad1_d455_44014e5e6754 0ba21a04_844e_c443_be46_00b8f6c40861["SmtpResponse()"] 676d2047_352d_72b6_2e56_db05dff1e4bc -->|method| 0ba21a04_844e_c443_be46_00b8f6c40861 9312f50b_d62a_c739_4832_64f5aa22b68e["DecoderException()"] 676d2047_352d_72b6_2e56_db05dff1e4bc -->|method| 9312f50b_d62a_c739_4832_64f5aa22b68e c0926e74_a270_c704_dfeb_8c3ef6168e99["parseCode()"] 676d2047_352d_72b6_2e56_db05dff1e4bc -->|method| c0926e74_a270_c704_dfeb_8c3ef6168e99 785c8bde_08f5_8452_8efb_e3a103a61451["parseNumber()"] 676d2047_352d_72b6_2e56_db05dff1e4bc -->|method| 785c8bde_08f5_8452_8efb_e3a103a61451
Relationship Graph
Source Code
codec-smtp/src/main/java/io/netty/handler/codec/smtp/SmtpResponseDecoder.java lines 32–117
@UnstableApi
public final class SmtpResponseDecoder extends LineBasedFrameDecoder {
private List<CharSequence> details;
/**
* Creates a new instance that enforces the given {@code maxLineLength}.
*/
public SmtpResponseDecoder(int maxLineLength) {
super(maxLineLength);
}
@Override
protected SmtpResponse decode(ChannelHandlerContext ctx, ByteBuf buffer) throws Exception {
ByteBuf frame = (ByteBuf) super.decode(ctx, buffer);
if (frame == null) {
// No full line received yet.
return null;
}
try {
final int readable = frame.readableBytes();
final int readerIndex = frame.readerIndex();
if (readable < 3) {
throw newDecoderException(buffer, readerIndex, readable);
}
final int code = parseCode(frame);
final int separator = frame.readByte();
final CharSequence detail = frame.isReadable() ? frame.toString(CharsetUtil.US_ASCII) : null;
List<CharSequence> details = this.details;
switch (separator) {
case ' ':
// Marks the end of a response.
this.details = null;
if (details != null) {
if (detail != null) {
details.add(detail);
}
} else {
if (detail == null) {
details = Collections.emptyList();
} else {
details = Collections.singletonList(detail);
}
}
return new DefaultSmtpResponse(code, details);
case '-':
// Multi-line response.
if (detail != null) {
if (details == null) {
// Using initial capacity as it is very unlikely that we will receive a multi-line response
// with more then 3 lines.
this.details = details = new ArrayList<CharSequence>(4);
}
details.add(detail);
}
break;
default:
throw newDecoderException(buffer, readerIndex, readable);
}
} finally {
frame.release();
}
return null;
}
private static DecoderException newDecoderException(ByteBuf buffer, int readerIndex, int readable) {
return new DecoderException(
"Received invalid line: '" + buffer.toString(readerIndex, readable, CharsetUtil.US_ASCII) + '\'');
}
/**
* Parses the io.netty.handler.codec.smtp code without any allocation, which is three digits.
*/
private static int parseCode(ByteBuf buffer) {
final int first = parseNumber(buffer.readByte()) * 100;
final int second = parseNumber(buffer.readByte()) * 10;
final int third = parseNumber(buffer.readByte());
return first + second + third;
}
Source
Frequently Asked Questions
What is the SmtpResponseDecoder class?
SmtpResponseDecoder is a class in the netty codebase, defined in codec-smtp/src/main/java/io/netty/handler/codec/smtp/SmtpResponseDecoder.java.
Where is SmtpResponseDecoder defined?
SmtpResponseDecoder is defined in codec-smtp/src/main/java/io/netty/handler/codec/smtp/SmtpResponseDecoder.java at line 32.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free