You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2011/05/24 12:31:23 UTC

svn commit: r1126970 - in /james/mailbox/trunk/store: pom.xml src/main/java/org/apache/james/mailbox/store/streaming/InputStreamContent.java

Author: norman
Date: Tue May 24 10:31:23 2011
New Revision: 1126970

URL: http://svn.apache.org/viewvc?rev=1126970&view=rev
Log:
Make sure the returned InputStream does match what you expect in respect to the size. See MAILBOX-71

Modified:
    james/mailbox/trunk/store/pom.xml
    james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/streaming/InputStreamContent.java

Modified: james/mailbox/trunk/store/pom.xml
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/pom.xml?rev=1126970&r1=1126969&r2=1126970&view=diff
==============================================================================
--- james/mailbox/trunk/store/pom.xml (original)
+++ james/mailbox/trunk/store/pom.xml Tue May 24 10:31:23 2011
@@ -41,6 +41,10 @@
       <artifactId>slf4j-api</artifactId>
     </dependency>
     <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+    </dependency>
+    <dependency>
       <groupId>${javax.mail.groupId}</groupId>
       <artifactId>${javax.mail.artifactId}</artifactId>
     </dependency>

Modified: james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/streaming/InputStreamContent.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/streaming/InputStreamContent.java?rev=1126970&r1=1126969&r2=1126970&view=diff
==============================================================================
--- james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/streaming/InputStreamContent.java (original)
+++ james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/streaming/InputStreamContent.java Tue May 24 10:31:23 2011
@@ -25,6 +25,7 @@ import java.nio.ByteBuffer;
 import java.nio.channels.FileChannel;
 import java.nio.channels.WritableByteChannel;
 
+import org.apache.commons.io.input.BoundedInputStream;
 import org.apache.james.mailbox.Content;
 import org.apache.james.mailbox.store.mail.model.Message;
 
@@ -33,13 +34,16 @@ import org.apache.james.mailbox.store.ma
  *
  */
 public final class InputStreamContent implements org.apache.james.mailbox.InputStreamContent{
+    @SuppressWarnings("unchecked")
     private Message m;
     private Type type;
 
-    public enum Type {
+    public static enum Type {
         Full,
         Body
     }
+    
+    @SuppressWarnings("unchecked")
     public InputStreamContent(Message m, Type type) throws IOException{
         this.m = m;
         this.type = type;
@@ -60,14 +64,16 @@ public final class InputStreamContent im
     }
 
     /*
-     * 
+     * (non-Javadoc)
+     * @see org.apache.james.mailbox.InputStreamContent#getInputStream()
      */
     public InputStream getInputStream() throws IOException {
+        // wrap the streams in a BoundedInputStream to make sure it really match with the stored size.
         switch (type) {
         case Full:
-            return m.getFullContent();
+            return new BoundedInputStream(m.getFullContent(), size());
         default:
-            return m.getBodyContent();
+            return new BoundedInputStream(m.getBodyContent(), size());
         }
        
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org