ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1160073 - in /webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments: ContentStoreFactory.java PartImpl.java
Date Sun, 21 Aug 2011 22:08:34 GMT
Author: veithen
Date: Sun Aug 21 22:08:33 2011
New Revision: 1160073

URL: http://svn.apache.org/viewvc?rev=1160073&view=rev
Log:
AXIOM-377: Don't pass the MIME parser to ContentStoreFactory, but only the input stream.

Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/ContentStoreFactory.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartImpl.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/ContentStoreFactory.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/ContentStoreFactory.java?rev=1160073&r1=1160072&r2=1160073&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/ContentStoreFactory.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/ContentStoreFactory.java
Sun Aug 21 22:08:33 2011
@@ -26,8 +26,6 @@ import org.apache.axiom.attachments.util
 import org.apache.axiom.om.OMException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.james.mime4j.stream.EntityState;
-import org.apache.james.mime4j.stream.MimeTokenStream;
 
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
@@ -54,13 +52,6 @@ class ContentStoreFactory {
     // Dynamic Threshold = availMemory / THRESHOLD_FACTOR
     private static final int THRESHOLD_FACTOR = 5;
     
-    private static void checkParserState(EntityState state, EntityState expected) throws
IllegalStateException {
-        if (expected != state) {
-            throw new IllegalStateException("Internal error: expected parser to be in state
"
-                    + expected + ", but got " + state);
-        }
-    }
-    
     /**
      * Creates a part from the input stream.
      * The remaining parameters are used to determine if the
@@ -75,7 +66,7 @@ class ContentStoreFactory {
      * @return Part
      * @throws OMException if any exception is encountered while processing.
      */
-    static ContentStore createContentStore(LifecycleManager manager, MimeTokenStream parser,
+    static ContentStore createContentStore(LifecycleManager manager, InputStream in,
                     boolean isSOAPPart,
                     int thresholdSize,
                     String attachmentDir,
@@ -90,8 +81,6 @@ class ContentStoreFactory {
         }
         
         try {
-            checkParserState(parser.getState(), EntityState.T_BODY);
-            
             ContentStore part;
             try {
                 
@@ -130,13 +119,12 @@ class ContentStoreFactory {
                     // of resizing and GC.  The BAAOutputStream 
                     // keeps the data in non-contiguous byte buffers.
                     BAAOutputStream baaos = new BAAOutputStream();
-                    BufferUtils.inputStream2OutputStream(parser.getDecodedInputStream(),
baaos);
+                    BufferUtils.inputStream2OutputStream(in, baaos);
                     part = new ContentOnMemory(baaos.buffers(), baaos.length());
                 } else {
                     // We need to read the input stream to determine whether
                     // the size is bigger or smaller than the threshold.
                     BAAOutputStream baaos = new BAAOutputStream();
-                    InputStream in = parser.getDecodedInputStream();
                     int count = BufferUtils.inputStream2OutputStream(in, baaos, thresholdSize);
 
                     if (count < thresholdSize) {
@@ -153,7 +141,6 @@ class ContentStoreFactory {
                     }
 
                 } 
-                checkParserState(parser.next(), EntityState.T_END_BODYPART);
             } finally {
                 if (!isSOAPPart) {
                     synchronized(semifore) {

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartImpl.java?rev=1160073&r1=1160072&r2=1160073&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartImpl.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartImpl.java
Sun Aug 21 22:08:33 2011
@@ -165,6 +165,13 @@ final class PartImpl implements Part {
         return content;
     }
     
+    private static void checkParserState(EntityState state, EntityState expected) throws
IllegalStateException {
+        if (expected != state) {
+            throw new IllegalStateException("Internal error: expected parser to be in state
"
+                    + expected + ", but got " + state);
+        }
+    }
+    
     /**
      * Make sure that the MIME part has been fully read from the parser. If the part has
not been
      * read yet, then it will be buffered. This method prepares the parser for reading the
next part
@@ -172,13 +179,17 @@ final class PartImpl implements Part {
      */
     void fetch() {
         if (content == null && parser != null) {
+            checkParserState(parser.getState(), EntityState.T_BODY);
+            
             // The PartFactory will determine which Part implementation is most appropriate.
-            content = ContentStoreFactory.createContentStore(message.getLifecycleManager(),
parser, 
+            content = ContentStoreFactory.createContentStore(message.getLifecycleManager(),
+                                          parser.getDecodedInputStream(), 
                                           isSOAPPart, 
                                           message.getThreshold(),
                                           message.getAttachmentRepoDir(),
                                           message.getContentLengthIfKnown());  // content-length
for the whole message
             try {
+                checkParserState(parser.next(), EntityState.T_END_BODYPART);
                 EntityState state = parser.next();
                 if (state == EntityState.T_EPILOGUE) {
                     while (parser.next() != EntityState.T_END_MULTIPART) {



Mime
View raw message