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 2010/04/07 21:17:17 UTC

svn commit: r931646 - in /james/imap/trunk: jcr/src/main/java/org/apache/james/imap/jcr/ jcr/src/main/java/org/apache/james/imap/jcr/mail/ jcr/src/main/java/org/apache/james/imap/jcr/mail/model/ jpa/src/main/java/org/apache/james/imap/jpa/ jpa/src/main...

Author: norman
Date: Wed Apr  7 19:17:17 2010
New Revision: 931646

URL: http://svn.apache.org/viewvc?rev=931646&view=rev
Log:
Complete the change of exposing Content of Document / Message via InputStream. Still room for improvements (IMAP-128)

Modified:
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailbox.java
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/Persistent.java
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMessageMapper.java
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRMailboxMembership.java
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRMessage.java
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/JPAMailboxMembership.java
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/JPAMessage.java
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/openjpa/JPAStreamingMessage.java
    james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/SimpleMailboxMembership.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/CountingInputStream.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/InputStreamContent.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/InputStreamFullContent.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/LazySkippingInputStream.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/RewindableInputStream.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailbox.java

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailbox.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailbox.java?rev=931646&r1=931645&r2=931646&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailbox.java (original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailbox.java Wed Apr  7 19:17:17 2010
@@ -80,7 +80,7 @@ public class JCRMailbox extends StoreMai
 
     
     @Override
-    protected MailboxMembership<String> copyMessage(MailboxMembership<String> originalMessage, long uid) {
+    protected MailboxMembership<String> copyMessage(MailboxMembership<String> originalMessage, long uid) throws MailboxException {
         MailboxMembership<String> newRow = new JCRMailboxMembership(getMailboxId(), uid, (JCRMailboxMembership) originalMessage, log);
         return newRow;
     }

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/Persistent.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/Persistent.java?rev=931646&r1=931645&r2=931646&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/Persistent.java (original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/Persistent.java Wed Apr  7 19:17:17 2010
@@ -18,6 +18,8 @@
  ****************************************************************/
 package org.apache.james.imap.jcr;
 
+import java.io.IOException;
+
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 
@@ -28,7 +30,7 @@ public interface Persistent {
 	 * 
 	 * @param node
 	 */
-	public void merge(Node node) throws RepositoryException;
+	public void merge(Node node) throws RepositoryException,IOException;
 
 	/**
 	 * Return underlying Node

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMessageMapper.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMessageMapper.java?rev=931646&r1=931645&r2=931646&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMessageMapper.java (original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMessageMapper.java Wed Apr  7 19:17:17 2010
@@ -18,6 +18,7 @@
  ****************************************************************/
 package org.apache.james.imap.jcr.mail;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -413,6 +414,8 @@ public class JCRMessageMapper extends Ab
         } catch (RepositoryException e) {
             e.printStackTrace();
             throw new StorageException(HumanReadableText.SAVE_FAILED, e);
+        } catch (IOException e) {
+            throw new StorageException(HumanReadableText.SAVE_FAILED, e);
         }
 
     }

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRMailboxMembership.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRMailboxMembership.java?rev=931646&r1=931645&r2=931646&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRMailboxMembership.java (original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRMailboxMembership.java Wed Apr  7 19:17:17 2010
@@ -18,6 +18,7 @@
  ****************************************************************/
 package org.apache.james.imap.jcr.mail.model;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.util.Calendar;
 import java.util.Date;
@@ -29,8 +30,10 @@ import javax.mail.Flags;
 
 import org.apache.commons.logging.Log;
 import org.apache.jackrabbit.JcrConstants;
+import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.jcr.JCRImapConstants;
 import org.apache.james.imap.jcr.Persistent;
+import org.apache.james.imap.mailbox.MailboxException;
 import org.apache.james.imap.store.mail.model.AbstractMailboxMembership;
 import org.apache.james.imap.store.mail.model.Document;
 import org.apache.james.imap.store.mail.model.MailboxMembership;
@@ -97,9 +100,10 @@ public class JCRMailboxMembership extend
 	 *            new UID
 	 * @param original
 	 *            message to be copied, not null
+	 * @throws MailboxException 
 	 */
 	public JCRMailboxMembership(String mailboxUUID, long uid,
-			JCRMailboxMembership original, Log logger) {
+			JCRMailboxMembership original, Log logger) throws MailboxException {
 		super();
 		this.mailboxUUID = mailboxUUID;
 		this.uid = uid;
@@ -111,8 +115,12 @@ public class JCRMailboxMembership extend
 		this.flagged = original.isFlagged();
 		this.recent = original.isRecent();
 		this.seen = original.isSeen();
-		this.message = new JCRMessage((JCRMessage) original.getDocument(),
-				logger);
+		try {
+            this.message = new JCRMessage((JCRMessage) original.getDocument(),
+            		logger);
+        } catch (IOException e) {
+            throw new MailboxException(HumanReadableText.FAILURE_MAIL_PARSE, e);
+        }
 	}
 
 	public JCRMailboxMembership(Node node, Log logger) {
@@ -406,7 +414,7 @@ public class JCRMailboxMembership extend
 	 * 
 	 * @see org.apache.james.imap.jcr.Persistent#merge(javax.jcr.Node)
 	 */
-	public void merge(Node node) throws RepositoryException {
+	public void merge(Node node) throws RepositoryException, IOException {
 		node.setProperty(MAILBOX_UUID_PROPERTY, getMailboxId());
 		node.setProperty(UID_PROPERTY, getUid());
 		node.setProperty(SIZE_PROPERTY, getSize());

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRMessage.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRMessage.java?rev=931646&r1=931645&r2=931646&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRMessage.java (original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRMessage.java Wed Apr  7 19:17:17 2010
@@ -18,8 +18,9 @@
  ****************************************************************/
 package org.apache.james.imap.jcr.mail.model;
 
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
 import java.io.InputStream;
-import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -32,6 +33,9 @@ import org.apache.jackrabbit.JcrConstant
 import org.apache.james.imap.jcr.JCRImapConstants;
 import org.apache.james.imap.jcr.JCRUtils;
 import org.apache.james.imap.jcr.Persistent;
+import org.apache.james.imap.store.LazySkippingInputStream;
+import org.apache.james.imap.store.RewindableInputStream;
+import org.apache.james.imap.store.StreamUtils;
 import org.apache.james.imap.store.mail.model.AbstractDocument;
 import org.apache.james.imap.store.mail.model.Document;
 import org.apache.james.imap.store.mail.model.Header;
@@ -96,11 +100,11 @@ public class JCRMessage extends Abstract
      * Create a copy of the given message
      * 
      * @param message
+     * @throws IOException 
      */
-    public JCRMessage(JCRMessage message, Log logger) {
+    public JCRMessage(JCRMessage message, Log logger) throws IOException {
         this.logger = logger;
-        ByteBuffer buf = message.getFullContent().duplicate();
-        this.content = new ByteBufferInputStream(buf);
+        this.content = new ByteArrayInputStream(StreamUtils.toByteArray(message.getFullContent()));
        
         this.fullContentOctets = message.getFullContentOctets();
         this.bodyStartOctet = (int) (message.getFullContentOctets() - message.getBodyOctets());
@@ -127,18 +131,23 @@ public class JCRMessage extends Abstract
      * (non-Javadoc)
      * @see org.apache.james.imap.store.mail.model.Document#getFullContent()
      */
-    public ByteBuffer getFullContent() {
+    public RewindableInputStream getFullContent() throws IOException {
+        return new RewindableInputStream(getFullContentInternal());
+    }
+    
+    
+    public InputStream getFullContentInternal() throws IOException {
         if (isPersistent()) {
             try {
                 //TODO: Maybe we should cache this somehow...
                 InputStream contentStream = node.getNode(JcrConstants.JCR_CONTENT).getProperty(JcrConstants.JCR_DATA).getStream();
-                return getContentAsByteBuffer(contentStream);
+                return contentStream;
             } catch (RepositoryException e) {
                 logger.error("Unable to retrieve property " + JcrConstants.JCR_CONTENT, e);
             }
             return null;
         }
-        return getContentAsByteBuffer(content);
+        return content;
     }
 
     /*
@@ -278,14 +287,14 @@ public class JCRMessage extends Abstract
      * (non-Javadoc)
      * @see org.apache.james.imap.jcr.Persistent#merge(javax.jcr.Node)
      */
-    public void merge(Node node) throws RepositoryException {
+    public void merge(Node node) throws RepositoryException, IOException {
         Node contentNode;
         if (node.hasNode(JcrConstants.JCR_CONTENT) == false) {
             contentNode = node.addNode(JcrConstants.JCR_CONTENT, JcrConstants.NT_RESOURCE);
         } else {
             contentNode = node.getNode(JcrConstants.JCR_CONTENT);
         }
-        contentNode.setProperty(JcrConstants.JCR_DATA, new ByteBufferInputStream(getFullContent()));
+        contentNode.setProperty(JcrConstants.JCR_DATA, getFullContent());
         contentNode.setProperty(JcrConstants.JCR_MIMETYPE, getMediaType());
 
         node.setProperty(FULL_CONTENT_OCTETS_PROPERTY, getFullContentOctets());
@@ -413,5 +422,13 @@ public class JCRMessage extends Abstract
         return retValue;
     }
 
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.mail.model.Document#getBodyContent()
+     */
+    public RewindableInputStream getBodyContent() throws IOException {
+        return new RewindableInputStream(new LazySkippingInputStream(getFullContentInternal(), getBodyStartOctet()));
+    }
+
 
 }

Modified: james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java?rev=931646&r1=931645&r2=931646&view=diff
==============================================================================
--- james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java (original)
+++ james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java Wed Apr  7 19:17:17 2010
@@ -82,7 +82,7 @@ public abstract class JPAMailbox extends
     
     @Override
     protected MailboxMembership<Long> createMessage(Date internalDate, final long uid, final int size, int bodyStartOctet, final InputStream document, 
-            final Flags flags, final List<Header> headers, PropertyBuilder propertyBuilder) {
+            final Flags flags, final List<Header> headers, PropertyBuilder propertyBuilder) throws MailboxException{
         final List<JPAHeader> jpaHeaders = new ArrayList<JPAHeader>(headers.size());
         for (Header header: headers) {
             jpaHeaders.add((JPAHeader) header);
@@ -93,7 +93,7 @@ public abstract class JPAMailbox extends
     }
     
     @Override
-    protected MailboxMembership<Long> copyMessage(MailboxMembership<Long> originalMessage, long uid) {
+    protected MailboxMembership<Long> copyMessage(MailboxMembership<Long> originalMessage, long uid) throws MailboxException{
         MailboxMembership<Long> newRow = new JPAMailboxMembership(getMailboxId(), uid, (JPAMailboxMembership) originalMessage);
         return newRow;
     }

Modified: james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/JPAMailboxMembership.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/JPAMailboxMembership.java?rev=931646&r1=931645&r2=931646&view=diff
==============================================================================
--- james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/JPAMailboxMembership.java (original)
+++ james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/JPAMailboxMembership.java Wed Apr  7 19:17:17 2010
@@ -18,6 +18,7 @@
  ****************************************************************/
 package org.apache.james.imap.jpa.mail.model;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.Serializable;
 import java.util.Date;
@@ -34,6 +35,8 @@ import javax.persistence.ManyToOne;
 import javax.persistence.NamedQueries;
 import javax.persistence.NamedQuery;
 
+import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.mailbox.MailboxException;
 import org.apache.james.imap.store.mail.model.AbstractMailboxMembership;
 import org.apache.james.imap.store.mail.model.Document;
 import org.apache.james.imap.store.mail.model.PropertyBuilder;
@@ -146,13 +149,17 @@ public class JPAMailboxMembership extend
     public JPAMailboxMembership() {}
 
     public JPAMailboxMembership(long mailboxId, long uid, Date internalDate, int size, Flags flags, 
-            InputStream content, int bodyStartOctet, final List<JPAHeader> headers, final PropertyBuilder propertyBuilder) {
+            InputStream content, int bodyStartOctet, final List<JPAHeader> headers, final PropertyBuilder propertyBuilder) throws MailboxException {
         super();
         this.mailboxId = mailboxId;
         this.uid = uid;
         this.internalDate = internalDate;
         this.size = size;
-        this.message = new JPAMessage(content, size, bodyStartOctet, headers, propertyBuilder);
+        try {
+            this.message = new JPAMessage(content, size, bodyStartOctet, headers, propertyBuilder);
+        } catch (IOException e) {
+            throw new MailboxException(HumanReadableText.FAILURE_MAILBOX_EXISTS,e);
+        }
         setFlags(flags);
     }
 
@@ -162,8 +169,9 @@ public class JPAMailboxMembership extend
      * @param mailboxId new mailbox ID
      * @param uid new UID
      * @param original message to be copied, not null
+     * @throws IOException 
      */
-    public JPAMailboxMembership(long mailboxId, long uid, JPAMailboxMembership original) {
+    public JPAMailboxMembership(long mailboxId, long uid, JPAMailboxMembership original) throws MailboxException {
         super();
         this.mailboxId = mailboxId;
         this.uid = uid;
@@ -175,7 +183,11 @@ public class JPAMailboxMembership extend
         this.flagged = original.isFlagged();
         this.recent = original.isRecent();
         this.seen = original.isSeen();
-        this.message = new JPAMessage((JPAMessage) original.getDocument());
+        try {
+            this.message = new JPAMessage((JPAMessage) original.getDocument());
+        } catch (IOException e) {
+            throw new MailboxException(HumanReadableText.FAILURE_MAILBOX_EXISTS,e);
+        }
     }
 
     /**

Modified: james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/JPAMessage.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/JPAMessage.java?rev=931646&r1=931645&r2=931646&view=diff
==============================================================================
--- james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/JPAMessage.java (original)
+++ james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/JPAMessage.java Wed Apr  7 19:17:17 2010
@@ -18,9 +18,9 @@
  ****************************************************************/
 package org.apache.james.imap.jpa.mail.model;
 
-import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
 import java.io.InputStream;
-import java.nio.ByteBuffer;
 import java.util.List;
 
 import javax.persistence.Basic;
@@ -29,6 +29,9 @@ import javax.persistence.Entity;
 import javax.persistence.FetchType;
 import javax.persistence.Lob;
 
+import org.apache.james.imap.store.LazySkippingInputStream;
+import org.apache.james.imap.store.RewindableInputStream;
+import org.apache.james.imap.store.StreamUtils;
 import org.apache.james.imap.store.mail.model.PropertyBuilder;
 
 @Entity(name="Message")
@@ -42,22 +45,9 @@ public class JPAMessage extends Abstract
     @Deprecated
     public JPAMessage() {}
 
-    public JPAMessage(final InputStream content, final long contentOctets, final int bodyStartOctet, final List<JPAHeader> headers, final PropertyBuilder propertyBuilder) {
+    public JPAMessage(final InputStream content, final long contentOctets, final int bodyStartOctet, final List<JPAHeader> headers, final PropertyBuilder propertyBuilder) throws IOException {
         super(contentOctets,bodyStartOctet,headers,propertyBuilder);
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        try {
-            byte[] buf = new byte[1024];
-            int i = 0;
-            while ((i = content.read(buf)) != -1) {
-                out.write(buf, 0, i);
-            }
-            this.content = out.toByteArray();
-            if (out != null)
-                out.close();
-
-        } catch (Exception e) {
-            this.content = new byte[0];
-        }
+        this.content = StreamUtils.out(content).toByteArray();
     }
 
     /**
@@ -65,23 +55,26 @@ public class JPAMessage extends Abstract
      * 
      * @param message
      */
-    public JPAMessage(JPAMessage message) {
+    public JPAMessage(JPAMessage message) throws IOException{
         super(message);
-        ByteBuffer buf = message.getFullContent().duplicate(); 
-        int a = 0;
-        this.content = new byte[buf.capacity()];
-        while(buf.hasRemaining()) {
-            content[a] = buf.get();
-            a++;
-        }     
+        this.content = StreamUtils.out(message.getFullContent()).toByteArray();
+        
     }
 
     /*
      * (non-Javadoc)
      * @see org.apache.james.imap.store.mail.model.Document#getFullContent()
      */
-    public ByteBuffer getFullContent() {
-        return ByteBuffer.wrap(content);
+    public RewindableInputStream getFullContent() throws IOException{
+        return new RewindableInputStream(new ByteArrayInputStream(content));
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.mail.model.Document#getBodyContent()
+     */
+    public RewindableInputStream getBodyContent() throws IOException {
+        return new RewindableInputStream(new LazySkippingInputStream(new ByteArrayInputStream(content), getBodyStartOctet()));
     }
 
 }

Modified: james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/openjpa/JPAStreamingMessage.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/openjpa/JPAStreamingMessage.java?rev=931646&r1=931645&r2=931646&view=diff
==============================================================================
--- james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/openjpa/JPAStreamingMessage.java (original)
+++ james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/openjpa/JPAStreamingMessage.java Wed Apr  7 19:17:17 2010
@@ -18,8 +18,10 @@
  ****************************************************************/
 package org.apache.james.imap.jpa.mail.model.openjpa;
 
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
 import java.io.InputStream;
-import java.nio.ByteBuffer;
+
 import java.util.List;
 
 import javax.persistence.Column;
@@ -29,6 +31,9 @@ import javax.persistence.FetchType;
 import org.apache.james.imap.jpa.mail.model.AbstractJPAMessage;
 import org.apache.james.imap.jpa.mail.model.JPAHeader;
 import org.apache.james.imap.jpa.mail.model.JPAMessage;
+import org.apache.james.imap.store.LazySkippingInputStream;
+import org.apache.james.imap.store.RewindableInputStream;
+import org.apache.james.imap.store.StreamUtils;
 import org.apache.james.imap.store.mail.model.PropertyBuilder;
 import org.apache.openjpa.persistence.Persistent;
 
@@ -60,18 +65,28 @@ public class JPAStreamingMessage extends
      * Create a copy of the given message
      * 
      * @param message
+     * @throws IOException 
      */
-    public JPAStreamingMessage(JPAStreamingMessage message) {
+    public JPAStreamingMessage(JPAStreamingMessage message) throws IOException {
         super(message);
-        this.content = new ByteBufferInputStream(message.getFullContent().duplicate());
+        this.content = new ByteArrayInputStream(StreamUtils.toByteArray(message.getFullContent()));
     }
 
     /*
      * (non-Javadoc)
      * @see org.apache.james.imap.store.mail.model.Document#getFullContent()
      */
-    public ByteBuffer getFullContent() {
-        return getContentAsByteBuffer(content);
+    public RewindableInputStream getFullContent() throws IOException {
+        return new RewindableInputStream(content);
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.mail.model.Document#getBodyContent()
+     */
+    public RewindableInputStream getBodyContent() throws IOException {
+        return new RewindableInputStream(new LazySkippingInputStream(content, getBodyStartOctet()));
+
     }
 
 }

Modified: james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/SimpleMailboxMembership.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/SimpleMailboxMembership.java?rev=931646&r1=931645&r2=931646&view=diff
==============================================================================
--- james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/SimpleMailboxMembership.java (original)
+++ james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/SimpleMailboxMembership.java Wed Apr  7 19:17:17 2010
@@ -21,7 +21,6 @@ package org.apache.james.imap.inmemory;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
-import java.nio.ByteBuffer;
 import java.util.Date;
 import java.util.List;
 

Modified: james/imap/trunk/store/src/main/java/org/apache/james/imap/store/CountingInputStream.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/CountingInputStream.java?rev=931646&r1=931645&r2=931646&view=diff
==============================================================================
--- james/imap/trunk/store/src/main/java/org/apache/james/imap/store/CountingInputStream.java (original)
+++ james/imap/trunk/store/src/main/java/org/apache/james/imap/store/CountingInputStream.java Wed Apr  7 19:17:17 2010
@@ -24,6 +24,12 @@ package org.apache.james.imap.store;
 import java.io.IOException;
 import java.io.InputStream;
 
+/**
+ * {@link InputStream} implementation which just consume the the wrapped {@link InputStream} and count
+ * the lines which are contained within the wrapped stream
+ * 
+ *
+ */
 final class CountingInputStream extends InputStream {
 
     private final InputStream in;
@@ -52,10 +58,20 @@ final class CountingInputStream extends 
         return next;
     }
 
+    /**
+     * Return the line count 
+     * 
+     * @return lineCount
+     */
     public final int getLineCount() {
         return lineCount;
     }
 
+    /**
+     * Return the octet count
+     * 
+     * @return octetCount
+     */
     public final int getOctetCount() {
         return octetCount;
     }

Modified: james/imap/trunk/store/src/main/java/org/apache/james/imap/store/InputStreamContent.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/InputStreamContent.java?rev=931646&r1=931645&r2=931646&view=diff
==============================================================================
--- james/imap/trunk/store/src/main/java/org/apache/james/imap/store/InputStreamContent.java (original)
+++ james/imap/trunk/store/src/main/java/org/apache/james/imap/store/InputStreamContent.java Wed Apr  7 19:17:17 2010
@@ -51,18 +51,20 @@ public final class InputStreamContent im
      * (non-Javadoc)
      * @see org.apache.james.imap.mailbox.Content#writeTo(java.nio.channels.WritableByteChannel)
      */
-    @SuppressWarnings("unused")
     public void writeTo(WritableByteChannel channel) throws IOException {
         
         // rewind the stream before write it to the channel
         in.rewind();
         
-        // read all the content of the underlying InputStream in 8096 byte chunks, wrap them
+        // read all the content of the underlying InputStream in 16384 byte chunks, wrap them
         // in a ByteBuffer and finally write the Buffer to the channel
-        byte[] buf = new byte[1];
+        byte[] buf = new byte[16384];
         int i = 0;
         while ((i = in.read(buf)) != -1) {
-            channel.write(ByteBuffer.wrap(buf));
+            ByteBuffer buffer = ByteBuffer.wrap(buf);
+            // set the limit of the buffer to the returned bytes
+            buffer.limit(i);
+            channel.write(buffer);
         }  
     }
 

Modified: james/imap/trunk/store/src/main/java/org/apache/james/imap/store/InputStreamFullContent.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/InputStreamFullContent.java?rev=931646&r1=931645&r2=931646&view=diff
==============================================================================
--- james/imap/trunk/store/src/main/java/org/apache/james/imap/store/InputStreamFullContent.java (original)
+++ james/imap/trunk/store/src/main/java/org/apache/james/imap/store/InputStreamFullContent.java Wed Apr  7 19:17:17 2010
@@ -55,19 +55,20 @@ public class InputStreamFullContent exte
         return size;
     }
 
-    @SuppressWarnings("unused")
     @Override
     protected void bodyWriteTo(WritableByteChannel channel) throws IOException {
         // rewind the stream before write it to the channel
         in.rewind();
         
-        // read all the content of the underlying InputStream in 8096 byte chunks, wrap them
+        // read all the content of the underlying InputStream in 16384 byte chunks, wrap them
         // in a ByteBuffer and finally write the Buffer to the channel
-        byte[] buf = new byte[1];
+        byte[] buf = new byte[16384];
         int i = 0;
         while ((i = in.read(buf)) != -1) {
-            channel.write(ByteBuffer.wrap(buf));
-
+            ByteBuffer buffer = ByteBuffer.wrap(buf);
+            // set the limit of the buffer to the returned bytes
+            buffer.limit(i);
+            channel.write(buffer);
         }  
     }
 

Modified: james/imap/trunk/store/src/main/java/org/apache/james/imap/store/LazySkippingInputStream.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/LazySkippingInputStream.java?rev=931646&r1=931645&r2=931646&view=diff
==============================================================================
--- james/imap/trunk/store/src/main/java/org/apache/james/imap/store/LazySkippingInputStream.java (original)
+++ james/imap/trunk/store/src/main/java/org/apache/james/imap/store/LazySkippingInputStream.java Wed Apr  7 19:17:17 2010
@@ -33,6 +33,12 @@ public class LazySkippingInputStream ext
     private long skipBytes;
     private boolean skipped = false;
 
+    /**
+     * Construct the {@link LazySkippingInputStream}
+     * 
+     * @param in {@link InputStream} to wrap
+     * @param skipBytes bytes to skip
+     */
     public LazySkippingInputStream(InputStream in, long skipBytes) {
         super(in);
         this.skipBytes = skipBytes;
@@ -80,6 +86,11 @@ public class LazySkippingInputStream ext
         return super.skip(n);
     }
 
+    /**
+     * Check if the bytes are skipped already. If not do now
+     * 
+     * @throws IOException
+     */
     private void skipIfNeeded() throws IOException {
         if (skipped == false) {
             super.skip(skipBytes);

Modified: james/imap/trunk/store/src/main/java/org/apache/james/imap/store/RewindableInputStream.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/RewindableInputStream.java?rev=931646&r1=931645&r2=931646&view=diff
==============================================================================
--- james/imap/trunk/store/src/main/java/org/apache/james/imap/store/RewindableInputStream.java (original)
+++ james/imap/trunk/store/src/main/java/org/apache/james/imap/store/RewindableInputStream.java Wed Apr  7 19:17:17 2010
@@ -28,7 +28,7 @@ import java.io.OutputStream;
 
 /**
  * {@link FilterInputStream} which support the get rewinded. This is done by copy over every byte
- * to a File after it was read. The rewinding will get queued as long as possible. So if you call
+ * to a File after it was read. The rewinding will get delayed as long as possible. So if you call
  * rewind, it will only get performed when needed
  * 
  *
@@ -106,14 +106,27 @@ public class RewindableInputStream exten
         return read(b,0,b.length);
     }
     
+    /**
+     * Mark the stream for rewind. The rewind itself will get delayed as long as possible
+     */
     public void rewind() {
         rewind = true;
     }
 
+    /**
+     * Check if the stream needs to get rewind
+     * 
+     * @return true if the stream is marked for rewind
+     */
     protected boolean needsRewind() {
         return rewind;
     }
     
+    /**
+     * Do the real rewind if needed
+     * 
+     * @throws IOException
+     */
     protected void rewindIfNeeded() throws IOException {
         if (needsRewind()) {
             rewind = false;
@@ -134,17 +147,23 @@ public class RewindableInputStream exten
         }
     }
 
-    @Override
+    /**
+     * Mark is not supported
+     */
     public synchronized void mark(int readlimit) {
         // do nothing
     }
 
-    @Override
+    /**
+     * Mark is not supported
+     */
     public boolean markSupported() {
         return false;
     }
 
-    @Override
+    /**
+     * Reset is not supported
+     */
     public synchronized void reset() throws IOException {
         // do nothing
     }

Modified: james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailbox.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailbox.java?rev=931646&r1=931645&r2=931646&view=diff
==============================================================================
--- james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailbox.java (original)
+++ james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailbox.java Wed Apr  7 19:17:17 2010
@@ -101,7 +101,7 @@ public abstract class StoreMailbox<Id> i
      * @param uid
      * @return membershipCopy
      */
-    protected abstract MailboxMembership<Id> copyMessage(MailboxMembership<Id> originalMessage, long uid);
+    protected abstract MailboxMembership<Id> copyMessage(MailboxMembership<Id> originalMessage, long uid) throws MailboxException;
     
     /**
      * Create a new {@link MessageMapper} to use
@@ -351,9 +351,10 @@ public abstract class StoreMailbox<Id> i
      * @param headers
      * @param propertyBuilder
      * @return membership
+     * @throws MailboxException 
      */
     protected abstract MailboxMembership<Id> createMessage(Date internalDate, final long uid, final int size, int bodyStartOctet, 
-            final InputStream documentIn, final Flags flags, final List<Header> headers, PropertyBuilder propertyBuilder);
+            final InputStream documentIn, final Flags flags, final List<Header> headers, PropertyBuilder propertyBuilder) throws MailboxException;
     
     /**
      * Create a new {@link Header} for the given data



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