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/06/11 13:25:17 UTC
svn commit: r953665 - in /james/imap/trunk:
jcr/src/main/java/org/apache/james/imap/jcr/mail/model/
jpa/src/main/java/org/apache/james/imap/jpa/mail/model/
memory/src/main/java/org/apache/james/imap/inmemory/mail/model/
store/src/main/java/org/apache/j...
Author: norman
Date: Fri Jun 11 11:25:16 2010
New Revision: 953665
URL: http://svn.apache.org/viewvc?rev=953665&view=rev
Log:
Rewind the InputStream by creating a new instance, so no need to use a temporary file etc
Removed:
james/imap/trunk/store/src/main/java/org/apache/james/imap/store/streaming/AbstractRewindableInputStream.java
james/imap/trunk/store/src/main/java/org/apache/james/imap/store/streaming/DelegatingRewindableInputStream.java
james/imap/trunk/store/src/main/java/org/apache/james/imap/store/streaming/FileRewindableInputStream.java
james/imap/trunk/store/src/main/java/org/apache/james/imap/store/streaming/InMemoryRewindableInputStream.java
james/imap/trunk/store/src/test/java/org/apache/james/imap/store/FileRewindableInputStreamTest.java
james/imap/trunk/store/src/test/java/org/apache/james/imap/store/InMemoryRewindableInputStreamTest.java
james/imap/trunk/store/src/test/java/org/apache/james/imap/store/RewindableInputStreamTest.java
Modified:
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/mail/model/JPAMessage.java
james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/model/SimpleMailboxMembership.java
james/imap/trunk/store/src/main/java/org/apache/james/imap/store/ResultUtils.java
james/imap/trunk/store/src/main/java/org/apache/james/imap/store/mail/model/AbstractDocument.java
james/imap/trunk/store/src/test/java/org/apache/james/imap/store/SimpleMessage.java
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=953665&r1=953664&r2=953665&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 Fri Jun 11 11:25:16 2010
@@ -389,17 +389,6 @@ public class JCRMessage extends Abstract
this.node = node;
- /*
- content = null;
- headers = new ArrayList<JCRHeader>();
- fullContentOctets = 0;
- mediaType = null;
- textualLineCount = null;
- subType = null;
- properties = null;
- bodyStartOctet = 0;
- */
-
}
@Override
@@ -437,7 +426,10 @@ public class JCRMessage extends Abstract
}
- @Override
+ /*
+ * (non-Javadoc)
+ * @see org.apache.james.imap.store.mail.model.AbstractDocument#getRawFullContent()
+ */
protected InputStream getRawFullContent() {
if (isPersistent()) {
try {
@@ -481,6 +473,7 @@ public class JCRMessage extends Abstract
return flags;
}
+
/*
* (non-Javadoc)
*
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=953665&r1=953664&r2=953665&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 Fri Jun 11 11:25:16 2010
@@ -60,9 +60,13 @@ public class JPAMessage extends Abstract
}
- @Override
+ /*
+ * (non-Javadoc)
+ * @see org.apache.james.imap.store.mail.model.AbstractDocument#getRawFullContent()
+ */
protected InputStream getRawFullContent() {
return new ByteArrayInputStream(content);
}
+
}
Modified: james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/model/SimpleMailboxMembership.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/model/SimpleMailboxMembership.java?rev=953665&r1=953664&r2=953665&view=diff
==============================================================================
--- james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/model/SimpleMailboxMembership.java (original)
+++ james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/model/SimpleMailboxMembership.java Fri Jun 11 11:25:16 2010
@@ -32,7 +32,6 @@ import org.apache.james.imap.store.mail.
import org.apache.james.imap.store.mail.model.MailboxMembership;
import org.apache.james.imap.store.mail.model.Property;
import org.apache.james.imap.store.mail.model.PropertyBuilder;
-import org.apache.james.imap.store.streaming.DelegatingRewindableInputStream;
import org.apache.james.imap.store.streaming.LazySkippingInputStream;
import org.apache.james.imap.store.streaming.RewindableInputStream;
@@ -152,8 +151,13 @@ public class SimpleMailboxMembership ext
}
public RewindableInputStream getBodyContent() throws IOException {
- return new DelegatingRewindableInputStream(new LazySkippingInputStream(new ByteArrayInputStream(document),bodyStartOctet), getFullContentOctets());
-
+ return new RewindableInputStream(new LazySkippingInputStream(new ByteArrayInputStream(document),bodyStartOctet)) {
+
+ @Override
+ protected void rewindIfNeeded() throws IOException {
+ in = new LazySkippingInputStream(new ByteArrayInputStream(document),bodyStartOctet);
+ }
+ };
}
public long getBodyOctets() {
@@ -161,7 +165,14 @@ public class SimpleMailboxMembership ext
}
public RewindableInputStream getFullContent() throws IOException {
- return new DelegatingRewindableInputStream(new ByteArrayInputStream(document), getFullContentOctets());
+ return new RewindableInputStream(new ByteArrayInputStream(document)) {
+
+ @Override
+ protected void rewindIfNeeded() throws IOException {
+ in = new ByteArrayInputStream(document);
+ }
+
+ };
}
public long getFullContentOctets() {
Modified: james/imap/trunk/store/src/main/java/org/apache/james/imap/store/ResultUtils.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/ResultUtils.java?rev=953665&r1=953664&r2=953665&view=diff
==============================================================================
--- james/imap/trunk/store/src/main/java/org/apache/james/imap/store/ResultUtils.java (original)
+++ james/imap/trunk/store/src/main/java/org/apache/james/imap/store/ResultUtils.java Fri Jun 11 11:25:16 2010
@@ -19,6 +19,7 @@
package org.apache.james.imap.store;
+import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
@@ -40,7 +41,6 @@ import org.apache.james.imap.mailbox.Mes
import org.apache.james.imap.mailbox.util.MessageResultImpl;
import org.apache.james.imap.store.mail.model.Header;
import org.apache.james.imap.store.mail.model.MailboxMembership;
-import org.apache.james.imap.store.streaming.DelegatingRewindableInputStream;
import org.apache.james.imap.store.streaming.InputStreamContent;
import org.apache.james.imap.store.streaming.PartContentBuilder;
import org.apache.james.imap.store.streaming.RewindableInputStream;
@@ -264,27 +264,24 @@ public class ResultUtils {
}
headersToString.append("\r\n");
final RewindableInputStream bodyContent = document.getBodyContent();
- final MessageInputStream stream = new MessageInputStream(headersToString, bodyContent, document.getFullContentOctets());
+ final MessageInputStream stream = new MessageInputStream(headersToString, bodyContent);
return stream;
}
- private static final class MessageInputStream extends DelegatingRewindableInputStream {
+ private static final class MessageInputStream extends FilterInputStream {
private final StringBuffer headers;
private int headerPosition = 0;
public MessageInputStream(final StringBuffer headers,
- final RewindableInputStream bodyContent, long bodySize) throws IOException{
- super(bodyContent, bodySize);
+ final RewindableInputStream bodyContent) throws IOException{
+ super(bodyContent);
this.headers = headers;
bodyContent.rewind();
}
public int read() throws IOException {
- if (needsRewind()) {
- rewind();
- }
final int result;
if (headerPosition < headers.length()) {
result = headers.charAt(headerPosition++);
@@ -296,10 +293,6 @@ public class ResultUtils {
@Override
public int read(byte[] b, int off, int len) throws IOException {
- if (needsRewind()) {
- rewind();
- }
-
if (headerPosition < headers.length()) {
int headersLeft = headers.length() - headerPosition;
if (len > headersLeft) {
@@ -332,8 +325,6 @@ public class ResultUtils {
public int read(byte[] b) throws IOException {
return read(b, 0, b.length);
}
-
-
}
private static final int[] path(MimePath mimePath) {
Modified: james/imap/trunk/store/src/main/java/org/apache/james/imap/store/mail/model/AbstractDocument.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/mail/model/AbstractDocument.java?rev=953665&r1=953664&r2=953665&view=diff
==============================================================================
--- james/imap/trunk/store/src/main/java/org/apache/james/imap/store/mail/model/AbstractDocument.java (original)
+++ james/imap/trunk/store/src/main/java/org/apache/james/imap/store/mail/model/AbstractDocument.java Fri Jun 11 11:25:16 2010
@@ -21,7 +21,6 @@ package org.apache.james.imap.store.mail
import java.io.IOException;
import java.io.InputStream;
-import org.apache.james.imap.store.streaming.DelegatingRewindableInputStream;
import org.apache.james.imap.store.streaming.LazySkippingInputStream;
import org.apache.james.imap.store.streaming.RewindableInputStream;
@@ -54,7 +53,13 @@ public abstract class AbstractDocument i
* @see org.apache.james.imap.store.mail.model.Document#getFullContent()
*/
public RewindableInputStream getFullContent() throws IOException {
- return new DelegatingRewindableInputStream(getRawFullContent(), getFullContentOctets());
+ return new RewindableInputStream(getRawFullContent()) {
+
+ @Override
+ protected void rewindIfNeeded() throws IOException {
+ in = getFullContent();
+ }
+ };
}
/*
@@ -62,12 +67,17 @@ public abstract class AbstractDocument i
* @see org.apache.james.imap.store.mail.model.Document#getBodyContent()
*/
public RewindableInputStream getBodyContent() throws IOException {
- return new DelegatingRewindableInputStream(new LazySkippingInputStream(getRawFullContent(), getBodyStartOctet()),getFullContentOctets());
-
+ 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
+ * 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
*/
Modified: james/imap/trunk/store/src/test/java/org/apache/james/imap/store/SimpleMessage.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/test/java/org/apache/james/imap/store/SimpleMessage.java?rev=953665&r1=953664&r2=953665&view=diff
==============================================================================
--- james/imap/trunk/store/src/test/java/org/apache/james/imap/store/SimpleMessage.java (original)
+++ james/imap/trunk/store/src/test/java/org/apache/james/imap/store/SimpleMessage.java Fri Jun 11 11:25:16 2010
@@ -29,7 +29,6 @@ import java.util.List;
import org.apache.james.imap.store.mail.model.Document;
import org.apache.james.imap.store.mail.model.Header;
import org.apache.james.imap.store.mail.model.Property;
-import org.apache.james.imap.store.streaming.InMemoryRewindableInputStream;
import org.apache.james.imap.store.streaming.RewindableInputStream;
public class SimpleMessage implements Document {
@@ -90,7 +89,7 @@ public class SimpleMessage implements Do
* @see org.apache.james.imap.jpa.mail.model.Document#getBodyContent()
*/
public RewindableInputStream getBodyContent() throws IOException {
- return new InMemoryRewindableInputStream(new ByteArrayInputStream(body));
+ return new ByteArrayRewindableInputStream(body);
}
/**
@@ -99,7 +98,7 @@ public class SimpleMessage implements Do
* @throws IOException
*/
public RewindableInputStream getFullContent() throws IOException {
- return new InMemoryRewindableInputStream(new ByteArrayInputStream(fullContent));
+ return new ByteArrayRewindableInputStream(fullContent);
}
/**
@@ -132,4 +131,18 @@ public class SimpleMessage implements Do
public long getFullContentOctets() {
return fullContent.length;
}
+
+ 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-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org