Author: norman Date: Thu Nov 18 11:52:13 2010 New Revision: 1036424 URL: http://svn.apache.org/viewvc?rev=1036424&view=rev Log: Replace usage of RewindableInputStream with InputStream. See IMAP-230
Removed: james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/streaming/RewindableInputStream.java Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRMessage.java james/imap/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAMessage.java james/imap/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAStreamingMessage.java james/imap/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/LazyLoadingMaildirMessage.java james/imap/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMessage.java james/imap/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/model/SimpleMailboxMembership.java james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/MessageSearches.java james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/ResultUtils.java james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/model/AbstractMessage.java james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/model/Message.java james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/streaming/InputStreamContent.java james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/streaming/InputStreamFullContent.java james/imap/trunk/store/src/test/java/org/apache/james/mailbox/store/SimpleMessage.java Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRMessage.java URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRMessage.java?rev=1036424&r1=1036423&r2=1036424&view=diff ============================================================================== --- james/imap/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRMessage.java (original) +++ james/imap/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRMessage.java Thu Nov 18 11:52:13 2010 @@ -44,6 +44,7 @@ import org.apache.james.mailbox.store.ma import org.apache.james.mailbox.store.mail.model.Message; import org.apache.james.mailbox.store.mail.model.Property; import org.apache.james.mailbox.store.mail.model.PropertyBuilder; +import org.apache.james.mailbox.store.streaming.LazySkippingInputStream; import org.apache.james.mailbox.store.streaming.StreamUtils; /** @@ -428,25 +429,6 @@ public class JCRMessage extends Abstract /* * (non-Javadoc) - * @see org.apache.james.mailbox.store.mail.model.AbstractDocument#getRawFullContent() - */ - protected InputStream getRawFullContent() { - if (isPersistent()) { - try { - //TODO: Maybe we should cache this somehow... - InputStream contentStream = node.getNode(JcrConstants.JCR_CONTENT).getProperty(JcrConstants.JCR_DATA).getBinary().getStream(); - return contentStream; - } catch (RepositoryException e) { - logger.error("Unable to retrieve property " + JcrConstants.JCR_CONTENT, e); - } - return null; - } - return content; - } - - - /* - * (non-Javadoc) * @see org.apache.james.mailbox.store.mail.model.MailboxMembership#createFlags() */ public Flags createFlags() { @@ -763,4 +745,32 @@ public class JCRMessage extends Abstract return retValue; } + + public InputStream getFullContent() throws IOException { + if (isPersistent()) { + try { + //TODO: Maybe we should cache this somehow... + InputStream contentStream = node.getNode(JcrConstants.JCR_CONTENT).getProperty(JcrConstants.JCR_DATA).getBinary().getStream(); + return contentStream; + } catch (RepositoryException e) { + logger.error("Unable to retrieve property " + JcrConstants.JCR_CONTENT, e); + } + return null; + } + return content; + } + + public InputStream getBodyContent() throws IOException { + if (isPersistent()) { + try { + //TODO: Maybe we should cache this somehow... + InputStream contentStream = node.getNode(JcrConstants.JCR_CONTENT).getProperty(JcrConstants.JCR_DATA).getBinary().getStream(); + return new LazySkippingInputStream(contentStream, getBodyStartOctet()); + } catch (RepositoryException e) { + logger.error("Unable to retrieve property " + JcrConstants.JCR_CONTENT, e); + } + return null; + } + return content; + } } Modified: james/imap/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAMessage.java URL: http://svn.apache.org/viewvc/james/imap/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAMessage.java?rev=1036424&r1=1036423&r2=1036424&view=diff ============================================================================== --- james/imap/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAMessage.java (original) +++ james/imap/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAMessage.java Thu Nov 18 11:52:13 2010 @@ -32,6 +32,7 @@ import javax.persistence.Lob; import org.apache.james.mailbox.jpa.mail.model.JPAHeader; import org.apache.james.mailbox.store.mail.model.Message; import org.apache.james.mailbox.store.mail.model.PropertyBuilder; +import org.apache.james.mailbox.store.streaming.LazySkippingInputStream; import org.apache.james.mailbox.store.streaming.StreamUtils; @Entity(name="Message") @@ -63,11 +64,20 @@ public class JPAMessage extends Abstract /* * (non-Javadoc) - * @see org.apache.james.mailbox.store.mail.model.AbstractDocument#getRawFullContent() + * @see org.apache.james.mailbox.store.mail.model.Message#getFullContent() */ - protected InputStream getRawFullContent() { + public InputStream getFullContent() throws IOException { return new ByteArrayInputStream(content); } + /* + * (non-Javadoc) + * @see org.apache.james.mailbox.store.mail.model.Message#getBodyContent() + */ + public InputStream getBodyContent() throws IOException { + return new ByteArrayInputStream(content, getBodyStartOctet(), (int)getFullContentOctets()); + } + + } Modified: james/imap/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAStreamingMessage.java URL: http://svn.apache.org/viewvc/james/imap/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAStreamingMessage.java?rev=1036424&r1=1036423&r2=1036424&view=diff ============================================================================== --- james/imap/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAStreamingMessage.java (original) +++ james/imap/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/JPAStreamingMessage.java Thu Nov 18 11:52:13 2010 @@ -31,6 +31,7 @@ import javax.persistence.FetchType; import org.apache.james.mailbox.jpa.mail.model.JPAHeader; import org.apache.james.mailbox.store.mail.model.Message; import org.apache.james.mailbox.store.mail.model.PropertyBuilder; +import org.apache.james.mailbox.store.streaming.LazySkippingInputStream; import org.apache.james.mailbox.store.streaming.StreamUtils; import org.apache.openjpa.persistence.Persistent; @@ -42,6 +43,7 @@ import org.apache.openjpa.persistence.Pe * * If your DB is not supported by this, use {...@link JPAMessage} * + * TODO: Fix me! */ @Entity(name="Message") public class JPAStreamingMessage extends AbstractJPAMessage{ @@ -69,9 +71,13 @@ public class JPAStreamingMessage extends this.content = new ByteArrayInputStream(StreamUtils.toByteArray(message.getFullContent())); } - @Override - protected InputStream getRawFullContent() { + public InputStream getFullContent() throws IOException { return content; } + + public InputStream getBodyContent() throws IOException { + return new LazySkippingInputStream(content, getBodyStartOctet()); + } + } Modified: james/imap/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/LazyLoadingMaildirMessage.java URL: http://svn.apache.org/viewvc/james/imap/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/LazyLoadingMaildirMessage.java?rev=1036424&r1=1036423&r2=1036424&view=diff ============================================================================== --- james/imap/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/LazyLoadingMaildirMessage.java (original) +++ james/imap/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/LazyLoadingMaildirMessage.java Thu Nov 18 11:52:13 2010 @@ -18,6 +18,7 @@ ****************************************************************/ package org.apache.james.mailbox.maildir.mail.model; +import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PushbackInputStream; @@ -34,7 +35,7 @@ import org.apache.james.mailbox.store.ma import org.apache.james.mailbox.store.mail.model.PropertyBuilder; import org.apache.james.mailbox.store.streaming.ConfigurableMimeTokenStream; import org.apache.james.mailbox.store.streaming.CountingInputStream; -import org.apache.james.mailbox.store.streaming.RewindableInputStream; +import org.apache.james.mailbox.store.streaming.LazySkippingInputStream; import org.apache.james.mime4j.MimeException; import org.apache.james.mime4j.descriptor.MaximalBodyDescriptor; import org.apache.james.mime4j.parser.MimeEntityConfig; @@ -274,32 +275,17 @@ public class LazyLoadingMaildirMessage e * (non-Javadoc) * @see org.apache.james.mailbox.store.mail.model.Message#getFullContent() */ - public RewindableInputStream getFullContent() throws IOException { - return new MyRewindableInputStream(new SharedFileInputStream(messageName.getFile())); + public InputStream getFullContent() throws IOException { + return new FileInputStream(messageName.getFile()); } /* * (non-Javadoc) * @see org.apache.james.mailbox.store.mail.model.Message#getBodyContent() */ - public RewindableInputStream getBodyContent() throws IOException { + public InputStream getBodyContent() throws IOException { parseMessage(); + return new LazySkippingInputStream(getFullContent(), bodyStartOctet); - SharedFileInputStream in = new SharedFileInputStream(messageName.getFile()); - return new MyRewindableInputStream(in.newStream(bodyStartOctet, -1)); - } - - private final class MyRewindableInputStream extends RewindableInputStream { - - protected MyRewindableInputStream(InputStream in) { - super(in); - - } - - @Override - protected void rewindIfNeeded() throws IOException { - in.reset(); - } - } } Modified: james/imap/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMessage.java URL: http://svn.apache.org/viewvc/james/imap/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMessage.java?rev=1036424&r1=1036423&r2=1036424&view=diff ============================================================================== --- james/imap/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMessage.java (original) +++ james/imap/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMessage.java Thu Nov 18 11:52:13 2010 @@ -31,11 +31,9 @@ import org.apache.commons.lang.NotImplem import org.apache.james.mailbox.MailboxException; import org.apache.james.mailbox.store.mail.model.Header; import org.apache.james.mailbox.store.mail.model.Mailbox; -import org.apache.james.mailbox.store.mail.model.Message; import org.apache.james.mailbox.store.mail.model.Property; import org.apache.james.mailbox.store.mail.model.PropertyBuilder; import org.apache.james.mailbox.store.streaming.LazySkippingInputStream; -import org.apache.james.mailbox.store.streaming.RewindableInputStream; import org.apache.james.mailbox.store.streaming.StreamUtils; public class MaildirMessage extends AbstractMaildirMessage { @@ -248,14 +246,6 @@ public class MaildirMessage extends Abst /* * (non-Javadoc) - * @see org.apache.james.mailbox.store.mail.model.MailboxMembership#getMessage() - */ - public Message getMessage() { - return this; - } - - /* - * (non-Javadoc) * @see org.apache.james.mailbox.store.mail.model.MailboxMembership#getInternalDate() */ public Date getInternalDate() { @@ -319,30 +309,16 @@ public class MaildirMessage extends Abst return modified; } - public RewindableInputStream getFullContent() throws IOException { - // TODO Auto-generated method stub - return new MyRewindableInputStream(rawFullContent); + public InputStream getFullContent() throws IOException { + return rawFullContent; } - public RewindableInputStream getBodyContent() throws IOException { - return new MyRewindableInputStream(new LazySkippingInputStream(rawFullContent, bodyStartOctet)); + public InputStream getBodyContent() throws IOException { + return new LazySkippingInputStream(rawFullContent, bodyStartOctet); } public long getBodyOctets() { return getFullContentOctets() - bodyStartOctet; } - - private class MyRewindableInputStream extends RewindableInputStream { - - protected MyRewindableInputStream(InputStream in) { - super(in); - } - - @Override - protected void rewindIfNeeded() throws IOException { - // do nothing.. - } - - } - + } Modified: james/imap/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/model/SimpleMailboxMembership.java URL: http://svn.apache.org/viewvc/james/imap/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/model/SimpleMailboxMembership.java?rev=1036424&r1=1036423&r2=1036424&view=diff ============================================================================== --- james/imap/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/model/SimpleMailboxMembership.java (original) +++ james/imap/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/model/SimpleMailboxMembership.java Thu Nov 18 11:52:13 2010 @@ -21,6 +21,7 @@ package org.apache.james.mailbox.inmemor import java.io.ByteArrayInputStream; import java.io.IOException; +import java.io.InputStream; import java.util.Date; import java.util.List; @@ -33,7 +34,6 @@ import org.apache.james.mailbox.store.ma import org.apache.james.mailbox.store.mail.model.Property; import org.apache.james.mailbox.store.mail.model.PropertyBuilder; import org.apache.james.mailbox.store.streaming.LazySkippingInputStream; -import org.apache.james.mailbox.store.streaming.RewindableInputStream; public class SimpleMailboxMembership extends AbstractMailboxMembership<Long> implements Message, Comparable<MailboxMembership<Long>> { @@ -149,29 +149,16 @@ public class SimpleMailboxMembership ext recent = false; } - public RewindableInputStream getBodyContent() throws IOException { - return new RewindableInputStream(new LazySkippingInputStream(new ByteArrayInputStream(document),bodyStartOctet)) { - - @Override - protected void rewindIfNeeded() throws IOException { - in = new LazySkippingInputStream(new ByteArrayInputStream(document),bodyStartOctet); - } - }; + public InputStream getBodyContent() throws IOException { + return new ByteArrayInputStream(document,bodyStartOctet, (int) getFullContentOctets()); } public long getBodyOctets() { return getFullContentOctets() - bodyStartOctet; } - public RewindableInputStream getFullContent() throws IOException { - return new RewindableInputStream(new ByteArrayInputStream(document)) { - - @Override - protected void rewindIfNeeded() throws IOException { - in = new ByteArrayInputStream(document); - } - - }; + public InputStream getFullContent() throws IOException { + return new ByteArrayInputStream(document); } public long getFullContentOctets() { Modified: james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/MessageSearches.java URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/MessageSearches.java?rev=1036424&r1=1036423&r2=1036424&view=diff ============================================================================== --- james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/MessageSearches.java (original) +++ james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/MessageSearches.java Thu Nov 18 11:52:13 2010 @@ -152,7 +152,7 @@ public class MessageSearches { private boolean bodyContains(String value, MailboxMembership<?> message) throws IOException, MimeException { - final InputStream input = ResultUtils.toInput(message); + final InputStream input = ResultUtils.toInput(message.getMessage()); final boolean result = isInMessage(value, input, false); return result; } @@ -170,7 +170,7 @@ public class MessageSearches { private boolean messageContains(String value, MailboxMembership<?> message) throws IOException, MimeException { - final InputStream input = ResultUtils.toInput(message); + final InputStream input = ResultUtils.toInput(message.getMessage()); final boolean result = isInMessage(value, input, true); return result; } Modified: james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/ResultUtils.java URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/ResultUtils.java?rev=1036424&r1=1036423&r2=1036424&view=diff ============================================================================== --- james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/ResultUtils.java (original) +++ james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/ResultUtils.java Thu Nov 18 11:52:13 2010 @@ -34,14 +34,14 @@ import javax.swing.text.Document; import org.apache.james.mailbox.Content; import org.apache.james.mailbox.MailboxException; import org.apache.james.mailbox.MessageResult; -import org.apache.james.mailbox.MimeDescriptor; import org.apache.james.mailbox.MessageResult.FetchGroup; import org.apache.james.mailbox.MessageResult.MimePath; +import org.apache.james.mailbox.MimeDescriptor; import org.apache.james.mailbox.store.mail.model.Header; import org.apache.james.mailbox.store.mail.model.MailboxMembership; import org.apache.james.mailbox.store.streaming.InputStreamContent; +import org.apache.james.mailbox.store.streaming.InputStreamContent.Type; import org.apache.james.mailbox.store.streaming.PartContentBuilder; -import org.apache.james.mailbox.store.streaming.RewindableInputStream; import org.apache.james.mailbox.util.MessageResultImpl; import org.apache.james.mime4j.MimeException; @@ -86,8 +86,7 @@ public class ResultUtils { * @throws IOException */ public static Content createBodyContent(MailboxMembership<?> membership) throws IOException { - final RewindableInputStream stream = membership.getMessage().getBodyContent(); - final InputStreamContent result = new InputStreamContent(stream); + final InputStreamContent result = new InputStreamContent(membership.getMessage(), Type.Body); return result; } @@ -99,9 +98,8 @@ public class ResultUtils { * @throws IOException */ public static Content createFullContent(final MailboxMembership<?> membership) throws IOException { - final RewindableInputStream stream = membership.getMessage().getFullContent(); - final InputStreamContent results = new InputStreamContent(stream); - return results; + final InputStreamContent result = new InputStreamContent(membership.getMessage(), Type.Full); + return result; } /** @@ -215,7 +213,7 @@ public class ResultUtils { private static PartContentBuilder build(int[] path, final MailboxMembership<?> message) throws IOException, MimeException { - final InputStream stream = toInput(message); + final InputStream stream = toInput(message.getMessage()); PartContentBuilder result = new PartContentBuilder(); result.parse(stream); try { @@ -230,19 +228,6 @@ public class ResultUtils { } return result; } - - /** - * Return an {...@link InputStream} which holds the content of the {...@link org.apache.james.mailbox.store.mail.model.Message} which is linked in the {...@link MailboxMembership} - * - * @param membership - * @return stream - * @throws IOException - */ - - public static InputStream toInput(final MailboxMembership<?> membership) throws IOException { - final org.apache.james.mailbox.store.mail.model.Message document = membership.getMessage(); - return toInput(document); - } /** @@ -262,7 +247,7 @@ public class ResultUtils { headersToString.append("\r\n"); } headersToString.append("\r\n"); - final RewindableInputStream bodyContent = document.getBodyContent(); + final InputStream bodyContent = document.getBodyContent(); final MessageInputStream stream = new MessageInputStream(headersToString, bodyContent); return stream; } @@ -273,11 +258,10 @@ public class ResultUtils { private int headerPosition = 0; public MessageInputStream(final StringBuffer headers, - final RewindableInputStream bodyContent) throws IOException{ + final InputStream bodyContent) throws IOException{ super(bodyContent); this.headers = headers; - bodyContent.rewind(); } public int read() throws IOException { Modified: james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/model/AbstractMessage.java URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/model/AbstractMessage.java?rev=1036424&r1=1036423&r2=1036424&view=diff ============================================================================== --- james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/model/AbstractMessage.java (original) +++ james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/model/AbstractMessage.java Thu Nov 18 11:52:13 2010 @@ -18,11 +18,6 @@ ****************************************************************/ package org.apache.james.mailbox.store.mail.model; -import java.io.IOException; -import java.io.InputStream; - -import org.apache.james.mailbox.store.streaming.LazySkippingInputStream; -import org.apache.james.mailbox.store.streaming.RewindableInputStream; /** @@ -47,41 +42,7 @@ public abstract class AbstractMessage im * @return startOctet */ protected abstract int getBodyStartOctet(); - - /* - * (non-Javadoc) - * @see org.apache.james.mailbox.store.mail.model.Document#getFullContent() - */ - public RewindableInputStream getFullContent() throws IOException { - return new RewindableInputStream(getRawFullContent()) { - - @Override - protected void rewindIfNeeded() throws IOException { - in = getFullContent(); - } - }; - } - /* - * (non-Javadoc) - * @see org.apache.james.mailbox.store.mail.model.Document#getBodyContent() - */ - public RewindableInputStream getBodyContent() throws IOException { - return new RewindableInputStream(new LazySkippingInputStream(getRawFullContent(), getBodyStartOctet())) { - - @Override - protected void rewindIfNeeded() throws IOException { - in = new LazySkippingInputStream(getRawFullContent(), getBodyStartOctet()); - } - }; - } - - /** - * Return the raw {...@link InputStream} of the full content. The InputStream must not be read already. So it need to be on start position - * - * @return rawFullContent - */ - protected abstract InputStream getRawFullContent(); } Modified: james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/model/Message.java URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/model/Message.java?rev=1036424&r1=1036423&r2=1036424&view=diff ============================================================================== --- james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/model/Message.java (original) +++ james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/model/Message.java Thu Nov 18 11:52:13 2010 @@ -19,10 +19,9 @@ package org.apache.james.mailbox.store.mail.model; import java.io.IOException; +import java.io.InputStream; import java.util.List; -import org.apache.james.mailbox.store.streaming.RewindableInputStream; - /** * A MIME message, consisting of meta-data (including MIME headers) * plus body content. In the case of multipart documents, this body content @@ -32,17 +31,23 @@ public interface Message { /** - * Gets the full content (including headers) of the document. + * Gets the full content (including headers) of the document. + * + * Be aware that this method need to return a new fresh {...@link InputStream} + * on every call, which basicly means it need to start at position 0 + * * @return fullContent, not null */ - public abstract RewindableInputStream getFullContent() throws IOException; + public abstract InputStream getFullContent() throws IOException; /** - * Gets the body content of the document. - * Headers are excluded. + * Gets the body content of the document. Headers are excluded. + * + * Be aware that this method need to return a new fresh {...@link InputStream} + * on every call, which basicly means it need to start at position 0 * @return body, not null */ - public abstract RewindableInputStream getBodyContent() throws IOException; + public abstract InputStream getBodyContent() throws IOException; /** * Gets the top level MIME content media type. @@ -81,6 +86,7 @@ public interface Message { /** * Gets a read-only list of headers. + * * @return unmodifiable list of headers, not null */ public abstract List<Header> getHeaders(); @@ -89,6 +95,7 @@ public interface Message { * Gets a read-only list of meta-data properties. * For properties with multiple values, this list will contain * several enteries with the same namespace and local name. + * * @return unmodifiable list of meta-data, not null */ public abstract List<Property> getProperties(); Modified: james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/streaming/InputStreamContent.java URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/streaming/InputStreamContent.java?rev=1036424&r1=1036423&r2=1036424&view=diff ============================================================================== --- james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/streaming/InputStreamContent.java (original) +++ james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/streaming/InputStreamContent.java Thu Nov 18 11:52:13 2010 @@ -24,19 +24,23 @@ import java.nio.ByteBuffer; import java.nio.channels.WritableByteChannel; import org.apache.james.mailbox.Content; +import org.apache.james.mailbox.store.mail.model.Message; /** * {...@link Content} which is stored in a {...@link InputStream} * */ public final class InputStreamContent implements Content{ + private Message m; + private Type type; - private RewindableInputStream in; - private long size; - - public InputStreamContent(RewindableInputStream in) throws IOException{ - this.in = in; - this.size = in.available(); + public enum Type { + Full, + Body + } + public InputStreamContent(Message m, Type type) throws IOException{ + this.m = m; + this.type = type; } /* @@ -44,7 +48,13 @@ public final class InputStreamContent im * @see org.apache.james.mailbox.Content#size() */ public long size() { - return size; + switch (type) { + case Full: + return m.getFullContentOctets(); + + default: + return m.getBodyOctets(); + } } /* @@ -52,11 +62,16 @@ public final class InputStreamContent im * @see org.apache.james.mailbox.Content#writeTo(java.nio.channels.WritableByteChannel) */ public void writeTo(WritableByteChannel channel) throws IOException { - + InputStream in = null; try { - // rewind the stream before write it to the channel - in.rewind(); - + switch (type) { + case Full: + in = m.getFullContent(); + break; + default: + in = m.getBodyContent(); + break; + } // 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[16384]; @@ -68,8 +83,9 @@ public final class InputStreamContent im channel.write(buffer); } } finally { - // close the stream so temporary files could get delete - in.close(); + if(in != null) { + in.close(); + } } } Modified: james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/streaming/InputStreamFullContent.java URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/streaming/InputStreamFullContent.java?rev=1036424&r1=1036423&r2=1036424&view=diff ============================================================================== --- james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/streaming/InputStreamFullContent.java (original) +++ james/imap/trunk/store/src/main/java/org/apache/james/mailbox/store/streaming/InputStreamFullContent.java Thu Nov 18 11:52:13 2010 @@ -34,11 +34,11 @@ import org.apache.james.mailbox.MessageR */ public class InputStreamFullContent extends AbstractFullContent{ - private final RewindableInputStream in; + private final InputStream in; private long size; - public InputStreamFullContent(final RewindableInputStream contents, final List<MessageResult.Header> headers) throws IOException{ + public InputStreamFullContent(final InputStream contents, final List<MessageResult.Header> headers) throws IOException{ super(headers); this.in = contents; this.size = caculateSize(); @@ -56,22 +56,23 @@ public class InputStreamFullContent exte } @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 16384 byte chunks, wrap them - // in a ByteBuffer and finally write the Buffer to the channel - byte[] buf = new byte[16384]; - int i = 0; - while ((i = in.read(buf)) != -1) { - ByteBuffer buffer = ByteBuffer.wrap(buf); - // set the limit of the buffer to the returned bytes - buffer.limit(i); - channel.write(buffer); - } - } - + protected void bodyWriteTo(WritableByteChannel channel) throws IOException { + try { + // 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[16384]; + int i = 0; + while ((i = in.read(buf)) != -1) { + ByteBuffer buffer = ByteBuffer.wrap(buf); + // set the limit of the buffer to the returned bytes + buffer.limit(i); + channel.write(buffer); + } + } finally { + in.close(); + } + } @Override protected long getBodySize() throws IOException{ Modified: james/imap/trunk/store/src/test/java/org/apache/james/mailbox/store/SimpleMessage.java URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/test/java/org/apache/james/mailbox/store/SimpleMessage.java?rev=1036424&r1=1036423&r2=1036424&view=diff ============================================================================== --- james/imap/trunk/store/src/test/java/org/apache/james/mailbox/store/SimpleMessage.java (original) +++ james/imap/trunk/store/src/test/java/org/apache/james/mailbox/store/SimpleMessage.java Thu Nov 18 11:52:13 2010 @@ -21,6 +21,7 @@ package org.apache.james.mailbox.store; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.InputStream; import java.io.OutputStreamWriter; import java.io.Writer; import java.util.ArrayList; @@ -29,7 +30,6 @@ import java.util.List; import org.apache.james.mailbox.store.mail.model.Header; import org.apache.james.mailbox.store.mail.model.Message; import org.apache.james.mailbox.store.mail.model.Property; -import org.apache.james.mailbox.store.streaming.RewindableInputStream; public class SimpleMessage implements Message { @@ -91,8 +91,8 @@ public class SimpleMessage implements Me * @throws IOException * @see org.apache.james.imap.Message.mail.model.Document#getBodyContent() */ - public RewindableInputStream getBodyContent() throws IOException { - return new ByteArrayRewindableInputStream(body); + public InputStream getBodyContent() throws IOException { + return new ByteArrayInputStream(body); } /** @@ -100,8 +100,8 @@ public class SimpleMessage implements Me * @return read only buffer, not null * @throws IOException */ - public RewindableInputStream getFullContent() throws IOException { - return new ByteArrayRewindableInputStream(fullContent); + public InputStream getFullContent() throws IOException { + return new ByteArrayInputStream(fullContent); } /** @@ -134,18 +134,4 @@ public class SimpleMessage implements Me public long getFullContentOctets() { return size; } - - private final class ByteArrayRewindableInputStream extends RewindableInputStream { - - private byte[] content; - public ByteArrayRewindableInputStream(byte[] content) { - super(new ByteArrayInputStream(content)); - this.content = content; - } - @Override - protected void rewindIfNeeded() throws IOException { - in = new ByteArrayInputStream(content); - } - - } } --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org