cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject svn commit: r605919 - in /incubator/cxf/trunk/rt/core/src: main/java/org/apache/cxf/attachment/AttachmentDataSource.java test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java
Date Thu, 20 Dec 2007 13:27:47 GMT
Author: mmao
Date: Thu Dec 20 05:27:45 2007
New Revision: 605919

URL: http://svn.apache.org/viewvc?rev=605919&view=rev
Log:
CXF-1313
  Cache the AttachmentDataSouce, so it can be reused multiple times, not just read once.


Modified:
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java
    incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java?rev=605919&r1=605918&r2=605919&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java
Thu Dec 20 05:27:45 2007
@@ -19,20 +19,25 @@
 
 package org.apache.cxf.attachment;
 
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 
 import javax.activation.DataSource;
 
+import org.apache.cxf.helpers.IOUtils;
+
 public class AttachmentDataSource implements DataSource {
 
     private final String ct;
     private final InputStream in;
+    private final byte[] cache; 
     
-    public AttachmentDataSource(String ctParam, InputStream inParam) {
+    public AttachmentDataSource(String ctParam, InputStream inParam) throws IOException {
         this.ct = ctParam;
         this.in = inParam;
+        cache = IOUtils.readBytesFromStream(in);
     }
 
     public String getContentType() {
@@ -40,7 +45,7 @@
     }
 
     public InputStream getInputStream() {
-        return in;
+        return new DelegatingInputStream(new ByteArrayInputStream(cache));
     }
 
     public String getName() {

Modified: incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java?rev=605919&r1=605918&r2=605919&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java
(original)
+++ incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java
Thu Dec 20 05:27:45 2007
@@ -75,7 +75,9 @@
         
         InputStream attIs = a.getDataHandler().getInputStream();
         
-        assertTrue(((DelegatingInputStream) attIs).getInputStream() instanceof MimeBodyPartInputStream);
+        // We need to cache the InputStream for reusing the AttachmentDataSource
+        //assertTrue(((DelegatingInputStream) attIs).getInputStream() instanceof MimeBodyPartInputStream);
+        assertTrue(((DelegatingInputStream) attIs).getInputStream() instanceof ByteArrayInputStream);
         assertTrue(((DelegatingInputStream) attBody).getInputStream() instanceof ByteArrayInputStream);
         
         // check the cached output stream
@@ -122,7 +124,9 @@
 
         InputStream attIs = a.getDataHandler().getInputStream();
 
-        assertTrue(((DelegatingInputStream) attIs).getInputStream() instanceof MimeBodyPartInputStream);
+        // We need to cache the InputStream for reusing the AttachmentDataSource
+        //assertTrue(((DelegatingInputStream) attIs).getInputStream() instanceof MimeBodyPartInputStream);
+        assertTrue(((DelegatingInputStream) attIs).getInputStream() instanceof ByteArrayInputStream);
         assertTrue(((DelegatingInputStream) attBody).getInputStream() instanceof ByteArrayInputStream);
 
         // check the cached output stream
@@ -168,8 +172,11 @@
         assertNotNull(a);
         
         InputStream attIs = a.getDataHandler().getInputStream();
-        
-        assertTrue(((DelegatingInputStream) attIs).getInputStream() instanceof MimeBodyPartInputStream);
+
+        // We need to cache the InputStream for reusing the AttachmentDataSource
+        //assertTrue(((DelegatingInputStream) attIs).getInputStream() instanceof MimeBodyPartInputStream);
+        assertTrue(((DelegatingInputStream) attIs).getInputStream() instanceof ByteArrayInputStream);
+
         assertTrue(((DelegatingInputStream) attBody).getInputStream() instanceof ByteArrayInputStream);
         
         // check the cached output stream
@@ -214,7 +221,9 @@
         
         InputStream attIs = a.getDataHandler().getInputStream();
         
-        assertTrue(((DelegatingInputStream) attIs).getInputStream() instanceof MimeBodyPartInputStream);
+        // We need to cache the InputStream for reusing the AttachmentDataSource
+        //assertTrue(((DelegatingInputStream) attIs).getInputStream() instanceof MimeBodyPartInputStream);
+        assertTrue(((DelegatingInputStream) attIs).getInputStream() instanceof ByteArrayInputStream);
         assertTrue(((DelegatingInputStream) attBody).getInputStream() instanceof ByteArrayInputStream);
         
         // check the cached output stream
@@ -262,7 +271,9 @@
         
         InputStream attIs = a.getDataHandler().getInputStream();
         
-        assertTrue(((DelegatingInputStream) attIs).getInputStream() instanceof MimeBodyPartInputStream);
+        // We need to cache the InputStream for reusing the AttachmentDataSource
+        //assertTrue(((DelegatingInputStream) attIs).getInputStream() instanceof MimeBodyPartInputStream);
+        assertTrue(((DelegatingInputStream) attIs).getInputStream() instanceof ByteArrayInputStream);
         assertTrue(((DelegatingInputStream) attBody).getInputStream() instanceof FileInputStream);
         
     }



Mime
View raw message