cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r608231 - in /incubator/cxf/branches/2.0.x-fixes: ./ rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java
Date Wed, 02 Jan 2008 21:07:48 GMT
Author: dkulp
Date: Wed Jan  2 13:07:46 2008
New Revision: 608231

URL: http://svn.apache.org/viewvc?rev=608231&view=rev
Log:
Merged revisions 605919 via svnmerge from 
https://svn.apache.org/repos/asf/incubator/cxf/trunk

........
  r605919 | mmao | 2007-12-20 08:27:45 -0500 (Thu, 20 Dec 2007) | 4 lines
  
  CXF-1313
    Cache the AttachmentDataSouce, so it can be reused multiple times, not just read once.
........

Modified:
    incubator/cxf/branches/2.0.x-fixes/   (props changed)
    incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java
    incubator/cxf/branches/2.0.x-fixes/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java

Propchange: incubator/cxf/branches/2.0.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java?rev=608231&r1=608230&r2=608231&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java
(original)
+++ incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java
Wed Jan  2 13:07:46 2008
@@ -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/branches/2.0.x-fixes/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java?rev=608231&r1=608230&r2=608231&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java
(original)
+++ incubator/cxf/branches/2.0.x-fixes/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java
Wed Jan  2 13:07:46 2008
@@ -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