You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2016/04/28 21:23:38 UTC

svn commit: r1741497 - in /webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments: Attachments.java MIMEMessage.java MIMEMessageAdapter.java

Author: veithen
Date: Thu Apr 28 19:23:38 2016
New Revision: 1741497

URL: http://svn.apache.org/viewvc?rev=1741497&view=rev
Log:
Move the contentLength stuff to MIMEMessageAdapter.

Modified:
    webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java
    webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java
    webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessageAdapter.java

Modified: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java?rev=1741497&r1=1741496&r2=1741497&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java (original)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java Thu Apr 28 19:23:38 2016
@@ -119,8 +119,8 @@ public class Attachments {
             };
         }
         
-        delegate = new MIMEMessageAdapter(new MIMEMessage(inStream, contentTypeString, attachmentBlobFactory,
-                contentLength));
+        delegate = new MIMEMessageAdapter(inStream, contentTypeString, attachmentBlobFactory,
+                contentLength);
     }
 
     /**

Modified: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java?rev=1741497&r1=1741496&r2=1741497&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java (original)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java Thu Apr 28 19:23:38 2016
@@ -63,10 +63,6 @@ class MIMEMessage {
     /** <code>ContentType</code> of the MIME message */
     private final ContentType contentType;
     
-    private final int contentLength; // Content Length
-
-    private final CountingInputStream filterIS;
-
     private final MimeTokenStream parser;
     
     /**
@@ -97,12 +93,8 @@ class MIMEMessage {
     private final WritableBlobFactory attachmentBlobFactory;
     
     MIMEMessage(InputStream inStream, String contentTypeString,
-            WritableBlobFactory attachmentBlobFactory, int contentLength) throws OMException {
-        this.contentLength = contentLength;
+            WritableBlobFactory attachmentBlobFactory) throws OMException {
         this.attachmentBlobFactory = attachmentBlobFactory;
-        if (log.isDebugEnabled()) {
-            log.debug("Attachments contentLength=" + contentLength + ", contentTypeString=" + contentTypeString);
-        }
         try {
             contentType = new ContentType(contentTypeString);
         } catch (ParseException e) {
@@ -111,21 +103,11 @@ class MIMEMessage {
                     , e);
         }
 
-        // If the length is not known, install a TeeInputStream
-        // so that we can retrieve it later.
-        InputStream is = inStream;
-        if (contentLength <= 0) {
-            filterIS = new CountingInputStream(inStream);
-            is = filterIS;
-        } else {
-            filterIS = null;
-        }
-        
         MimeConfig config = new MimeConfig();
         config.setStrictParsing(true);
         parser = new MimeTokenStream(config);
         parser.setRecursionMode(RecursionMode.M_NO_RECURSE);
-        parser.parseHeadless(is, contentTypeString);
+        parser.parseHeadless(inStream, contentTypeString);
         
         // Move the parser to the beginning of the first part
         while (parser.getState() != EntityState.T_START_BODYPART) {
@@ -239,7 +221,7 @@ class MIMEMessage {
     /**
      * Force reading of all attachments.
      */
-    private void fetchAllParts() {
+    void fetchAllParts() {
         while (getNextPartDataHandler() != null) {
             // Just loop until getNextPartDataHandler returns null
         }
@@ -257,17 +239,6 @@ class MIMEMessage {
         return Collections.unmodifiableMap(attachmentsMap);
     }
     
-    long getContentLength() throws IOException {
-        if (contentLength > 0) {
-            return contentLength;
-        } else {
-            // Ensure all parts are read
-            fetchAllParts();
-            // Now get the count from the filter
-            return filterIS.getCount();
-        }
-    }
-    
     /**
      * @return the Next valid MIME part + store the Part in the Parts List
      * @throws OMException throw if content id is null or if two MIME parts contain the same

Modified: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessageAdapter.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessageAdapter.java?rev=1741497&r1=1741496&r2=1741497&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessageAdapter.java (original)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessageAdapter.java Thu Apr 28 19:23:38 2016
@@ -29,15 +29,36 @@ import java.util.Set;
 
 import javax.activation.DataHandler;
 
+import org.apache.axiom.blob.WritableBlobFactory;
 import org.apache.axiom.mime.ContentType;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 final class MIMEMessageAdapter extends AttachmentsDelegate {
+    private static final Log log = LogFactory.getLog(MIMEMessageAdapter.class);
+
     private final MIMEMessage message;
     private final Map<String,DataHandler> addedDataHandlers = new LinkedHashMap<String,DataHandler>();
     private final Set<String> removedDataHandlers = new HashSet<String>();
+    private final int contentLength;
+    private final CountingInputStream filterIS;
+
+    MIMEMessageAdapter(InputStream inStream, String contentTypeString,
+            WritableBlobFactory attachmentBlobFactory, int contentLength) {
+        this.contentLength = contentLength;
+        if (log.isDebugEnabled()) {
+            log.debug("Attachments contentLength=" + contentLength + ", contentTypeString=" + contentTypeString);
+        }
+
+        // If the length is not known, install a filter so that we can retrieve it later.
+        if (contentLength <= 0) {
+            filterIS = new CountingInputStream(inStream);
+            inStream = filterIS;
+        } else {
+            filterIS = null;
+        }
 
-    MIMEMessageAdapter(MIMEMessage message) {
-        this.message = message;
+        this.message = new MIMEMessage(inStream, contentTypeString, attachmentBlobFactory);
     }
 
     @Override
@@ -107,6 +128,13 @@ final class MIMEMessageAdapter extends A
 
     @Override
     long getContentLength() throws IOException {
-        return message.getContentLength();
+        if (contentLength > 0) {
+            return contentLength;
+        } else {
+            // Ensure all parts are read
+            message.fetchAllParts();
+            // Now get the count from the filter
+            return filterIS.getCount();
+        }
     }
 }