cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Kulp <dk...@apache.org>
Subject Re: 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 15:17:50 GMT


Can this be changed to use the CachedOutputStream stream stuff?   We 
shouldn't be storing attachments in memory as a byte[].   That can 
easily suck up the entire memory causing all kinds of issues.

Dan

On Thursday 20 December 2007, mmao@apache.org wrote:
> 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/At
>tachmentDataSource.java
> incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/At
>tachmentDeserializerTest.java
>
> Modified:
> incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/At
>tachmentDataSource.java URL:
> http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java
>/org/apache/cxf/attachment/AttachmentDataSource.java?rev=605919&r1=6059
>18&r2=605919&view=diff
> ======================================================================
>======== ---
> incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/At
>tachmentDataSource.java (original) +++
> incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/At
>tachmentDataSource.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/At
>tachmentDeserializerTest.java URL:
> http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/test/java
>/org/apache/cxf/attachment/AttachmentDeserializerTest.java?rev=605919&r
>1=605918&r2=605919&view=diff
> ======================================================================
>======== ---
> incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/At
>tachmentDeserializerTest.java (original) +++
> incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/At
>tachmentDeserializerTest.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);
>
>      }



-- 
J. Daniel Kulp
Principal Engineer, IONA
dkulp@apache.org
http://www.dankulp.com/blog

Mime
View raw message