james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r1238662 - /james/server/trunk/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java
Date Tue, 31 Jan 2012 15:23:59 GMT
Author: norman
Date: Tue Jan 31 15:23:58 2012
New Revision: 1238662

URL: http://svn.apache.org/viewvc?rev=1238662&view=rev
Log:
Only open the FileOutputStream one time

Modified:
    james/server/trunk/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java

Modified: james/server/trunk/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java
URL: http://svn.apache.org/viewvc/james/server/trunk/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java?rev=1238662&r1=1238661&r2=1238662&view=diff
==============================================================================
--- james/server/trunk/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java
(original)
+++ james/server/trunk/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java
Tue Jan 31 15:23:58 2012
@@ -52,6 +52,8 @@ public class ImapRequestFrameDecoder ext
     private final static String NEEDED_DATA = "NEEDED_DATA";
     private final static String STORED_DATA = "STORED_DATA";
     private final static String WRITTEN_DATA = "WRITTEN_DATA";
+    private final static String OUTPUT_STREAM = "OUTPUT_STREAM";
+
 
     public ImapRequestFrameDecoder(ImapDecoder decoder, int inMemorySizeLimit, int literalSizeLimit)
{
         this.decoder = decoder;
@@ -95,30 +97,36 @@ public class ImapRequestFrameDecoder ext
                     final File f;
                     int written;
 
+                    OutputStream out = null;
                     // check if we have created a temporary file already or if
                     // we need to create a new one
                     if (attachment.containsKey(STORED_DATA)) {
                         f = (File) attachment.get(STORED_DATA);
                         written = (Integer) attachment.get(WRITTEN_DATA);
+                        out = (OutputStream) attachment.get(OUTPUT_STREAM);
                     } else {
                         f = File.createTempFile("imap-literal", ".tmp");
                         attachment.put(STORED_DATA, f);
                         written = 0;
                         attachment.put(WRITTEN_DATA, written);
+                        out = new FileOutputStream(f, true);
+                        attachment.put(OUTPUT_STREAM, out);
 
                     }
 
-                    OutputStream out = null;
 
                     try {
                         int amount = Math.min(buffer.readableBytes(), size - written);
-                        out = new FileOutputStream(f, true);
                         buffer.readBytes(out, amount);
-                    } finally {
+                        written += amount;
+                    } catch (Exception e) {
                         IOUtils.closeQuietly(out);
+                        throw e;
                     }
                     // Check if all needed data was streamed to the file.
                     if (written == size) {
+                        IOUtils.closeQuietly(out);
+
                         reader = new NettyStreamImapRequestLineReader(channel, new FileInputStream(f)
{
                             /**
                              * Delete the File on close too



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message