james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r1029149 - in /james/server/trunk/core-library/src/main/java/org/apache/james/core: InternetHeadersInputStream.java MimeMessageInputStream.java
Date Sat, 30 Oct 2010 18:45:07 GMT
Author: norman
Date: Sat Oct 30 18:45:07 2010
New Revision: 1029149

URL: http://svn.apache.org/viewvc?rev=1029149&view=rev
Log:
Reuse InternetHeadersInputStream

Modified:
    james/server/trunk/core-library/src/main/java/org/apache/james/core/InternetHeadersInputStream.java
    james/server/trunk/core-library/src/main/java/org/apache/james/core/MimeMessageInputStream.java

Modified: james/server/trunk/core-library/src/main/java/org/apache/james/core/InternetHeadersInputStream.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-library/src/main/java/org/apache/james/core/InternetHeadersInputStream.java?rev=1029149&r1=1029148&r2=1029149&view=diff
==============================================================================
--- james/server/trunk/core-library/src/main/java/org/apache/james/core/InternetHeadersInputStream.java
(original)
+++ james/server/trunk/core-library/src/main/java/org/apache/james/core/InternetHeadersInputStream.java
Sat Oct 30 18:45:07 2010
@@ -43,8 +43,13 @@ public class InternetHeadersInputStream 
     
     @SuppressWarnings("unchecked")
     public InternetHeadersInputStream(InternetHeaders headers) {
-        this.headerLines = headers.getAllHeaderLines();
+        this(headers.getAllHeaderLines());
     }
+    
+    public InternetHeadersInputStream(Enumeration<String> headerLines) {
+        this.headerLines = headerLines;
+    }
+    
     @Override
     public int read() throws IOException {
         if (currLine == null || pos == currLine.length) {

Modified: james/server/trunk/core-library/src/main/java/org/apache/james/core/MimeMessageInputStream.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-library/src/main/java/org/apache/james/core/MimeMessageInputStream.java?rev=1029149&r1=1029148&r2=1029149&view=diff
==============================================================================
--- james/server/trunk/core-library/src/main/java/org/apache/james/core/MimeMessageInputStream.java
(original)
+++ james/server/trunk/core-library/src/main/java/org/apache/james/core/MimeMessageInputStream.java
Sat Oct 30 18:45:07 2010
@@ -19,11 +19,8 @@
 
 package org.apache.james.core;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.Enumeration;
 
 import javax.mail.MessagingException;
 import javax.mail.internet.MimeMessage;
@@ -44,14 +41,8 @@ public class MimeMessageInputStream exte
     @SuppressWarnings("unchecked")
     public MimeMessageInputStream(MimeMessage message) throws IOException {
         try {
-            ByteArrayOutputStream headersOut = new ByteArrayOutputStream();
-            Enumeration headers = message.getAllHeaderLines();
-            while (headers.hasMoreElements()) {
-                headersOut.write(headers.nextElement().toString().getBytes("US-ASCII"));
-                headersOut.write("\r\n".getBytes());
-            }
-            headersInputStream = new ByteArrayInputStream(headersOut.toByteArray());
-            
+            headersInputStream = new InternetHeadersInputStream(message.getAllHeaderLines());
+
             // use the raw InputStream because we want to have no conversion here and just
obtain the original message body
             this.bodyInputStream = message.getRawInputStream();
         } catch (MessagingException e) {
@@ -61,28 +52,18 @@ public class MimeMessageInputStream exte
 
     @Override
     public int read() throws IOException {
-        if (nextCR) {
-            nextCR = false;
-            nextLF = true;
-            return '\r';
-        } else if (nextLF) {
-            nextLF = false;
-            return '\n';
+        int i = -1;
+        if (cStream == 0) {
+            i = headersInputStream.read();
         } else {
-            int i = -1;
-            if (cStream == 0) {
-                i = headersInputStream.read();
-            } else {
-                i = bodyInputStream.read();
-            }
-
-            if (i == -1 && cStream == 0) {
-                cStream++;
-                nextCR = true;
-                return read();
-            }
-            return i;
+            i = bodyInputStream.read();
+        }
+
+        if (i == -1 && cStream == 0) {
+            cStream++;
+            return read();
         }
+        return i;
 
     }
 



---------------------------------------------------------------------
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