You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2022/05/09 01:35:32 UTC
[james-project] 02/09: JAMES-3737 Extract methods in ImapRequestFrameDecoder: small enhancements
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 9fc41cbe6801414fe6dabe56972231be90f2d3af
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Apr 22 10:20:44 2022 +0700
JAMES-3737 Extract methods in ImapRequestFrameDecoder: small enhancements
- Reduce counts of parameters
-Also avoid a double map lookup
---
.../james/imapserver/netty/ImapRequestFrameDecoder.java | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java
index 09bcbb0c53..ab375b356e 100644
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java
@@ -56,6 +56,7 @@ import io.netty.handler.codec.ByteToMessageDecoder;
public class ImapRequestFrameDecoder extends ByteToMessageDecoder implements NettyConstants, LineHandlerAware {
@VisibleForTesting
static final String NEEDED_DATA = "NEEDED_DATA";
+ private static final boolean RETRY = true;
private static final String STORED_DATA = "STORED_DATA";
private static final String WRITTEN_DATA = "WRITTEN_DATA";
private static final String OUTPUT_STREAM = "OUTPUT_STREAM";
@@ -155,9 +156,10 @@ public class ImapRequestFrameDecoder extends ByteToMessageDecoder implements Net
// check if we failed before and if we already know how much data we
// need to sucess next run
int size = -1;
- if (attachment.containsKey(NEEDED_DATA)) {
+ final Object rawSize = attachment.get(NEEDED_DATA);
+ if (rawSize != null) {
retry = true;
- size = (Integer) attachment.get(NEEDED_DATA);
+ size = (Integer) rawSize;
// now see if the buffer hold enough data to process.
if (size != NettyImapRequestLineReader.NotEnoughDataException.UNKNOWN_SIZE && size > in.readableBytes()) {
@@ -167,7 +169,7 @@ public class ImapRequestFrameDecoder extends ByteToMessageDecoder implements Net
// ok seems like it will not fit in the memory limit so we
// need to store it in a temporary file
- reader = uploadToAFile(ctx, in, retry, attachment, size);
+ reader = uploadToAFile(ctx, in, attachment, size);
if (reader == null) return null;
} else {
@@ -185,7 +187,7 @@ public class ImapRequestFrameDecoder extends ByteToMessageDecoder implements Net
return Pair.of(reader, size);
}
- private ImapRequestLineReader uploadToAFile(ChannelHandlerContext ctx, ByteBuf in, boolean retry, Map<String, Object> attachment, int size) throws IOException {
+ private ImapRequestLineReader uploadToAFile(ChannelHandlerContext ctx, ByteBuf in, Map<String, Object> attachment, int size) throws IOException {
ImapRequestLineReader reader;
final File f;
int written;
@@ -228,7 +230,7 @@ public class ImapRequestFrameDecoder extends ByteToMessageDecoder implements Net
//ignore exception during close
}
- reader = new NettyStreamImapRequestLineReader(ctx.channel(), f, retry);
+ reader = new NettyStreamImapRequestLineReader(ctx.channel(), f, RETRY);
} else {
attachment.put(WRITTEN_DATA, written);
return null;
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org