james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mwiederk...@apache.org
Subject svn commit: r778453 - in /james/mime4j/trunk/core/src: main/java/org/apache/james/mime4j/message/ test/java/org/apache/james/mime4j/message/
Date Mon, 25 May 2009 17:02:25 GMT
Author: mwiederkehr
Date: Mon May 25 17:02:25 2009
New Revision: 778453

URL: http://svn.apache.org/viewvc?rev=778453&view=rev
Log:
MIME4J-136: Pull up getInputStream() from BinaryBody to SingleBody

Modified:
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/BinaryBody.java
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/SingleBody.java
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/StorageTextBody.java
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/StringTextBody.java
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/message/MessageTest.java

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/BinaryBody.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/BinaryBody.java?rev=778453&r1=778452&r2=778453&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/BinaryBody.java
(original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/BinaryBody.java
Mon May 25 17:02:25 2009
@@ -19,9 +19,6 @@
 
 package org.apache.james.mime4j.message;
 
-import java.io.IOException;
-import java.io.InputStream;
-
 /**
  * A body containing binary data.
  */
@@ -33,13 +30,4 @@
     protected BinaryBody() {
     }
 
-    /**
-     * Gets a <code>InputStream</code> which reads the bytes of the body.
-     * 
-     * @return the stream, transfer decoded
-     * @throws IOException
-     *             on I/O errors.
-     */
-    public abstract InputStream getInputStream() throws IOException;
-
 }

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/SingleBody.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/SingleBody.java?rev=778453&r1=778452&r2=778453&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/SingleBody.java
(original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/SingleBody.java
Mon May 25 17:02:25 2009
@@ -20,8 +20,11 @@
 package org.apache.james.mime4j.message;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 
+import org.apache.james.mime4j.codec.CodecUtil;
+
 /**
  * Abstract implementation of a single message body; that is, a body that does
  * not contain (directly or indirectly) any other child bodies. It also provides
@@ -52,14 +55,32 @@
     }
 
     /**
-     * Writes this single body to the given stream.
+     * Gets a <code>InputStream</code> which reads the bytes of the body.
+     * 
+     * @return the stream, transfer decoded
+     * @throws IOException
+     *             on I/O errors.
+     */
+    public abstract InputStream getInputStream() throws IOException;
+
+    /**
+     * Writes this single body to the given stream. The default implementation copies
+     * the input stream obtained by {@link #getInputStream()} to the specified output
+     * stream. May be overwritten by a subclass to improve performance.
      * 
      * @param out
      *            the stream to write to.
      * @throws IOException
      *             in case of an I/O error
      */
-    public abstract void writeTo(OutputStream out) throws IOException;
+    public void writeTo(OutputStream out) throws IOException {
+        if (out == null)
+            throw new IllegalArgumentException();
+
+        InputStream in = getInputStream();
+        CodecUtil.copy(in, out);
+        in.close();
+    }
 
     /**
      * Returns a copy of this <code>SingleBody</code> (optional operation).

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/StorageTextBody.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/StorageTextBody.java?rev=778453&r1=778452&r2=778453&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/StorageTextBody.java
(original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/StorageTextBody.java
Mon May 25 17:02:25 2009
@@ -22,11 +22,9 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.io.OutputStream;
 import java.io.Reader;
 import java.nio.charset.Charset;
 
-import org.apache.james.mime4j.codec.CodecUtil;
 import org.apache.james.mime4j.storage.MultiReferenceStorage;
 import org.apache.james.mime4j.util.CharsetUtil;
 
@@ -54,13 +52,8 @@
     }
 
     @Override
-    public void writeTo(OutputStream out) throws IOException {
-        if (out == null)
-            throw new IllegalArgumentException();
-
-        InputStream in = storage.getInputStream();
-        CodecUtil.copy(in, out);
-        in.close();
+    public InputStream getInputStream() throws IOException {
+        return storage.getInputStream();
     }
 
     @Override

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/StringTextBody.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/StringTextBody.java?rev=778453&r1=778452&r2=778453&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/StringTextBody.java
(original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/StringTextBody.java
Mon May 25 17:02:25 2009
@@ -19,7 +19,9 @@
 
 package org.apache.james.mime4j.message;
 
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.Reader;
@@ -48,6 +50,11 @@
     }
 
     @Override
+    public InputStream getInputStream() throws IOException {
+        return new ByteArrayInputStream(text.getBytes(charset));
+    }
+
+    @Override
     public Reader getReader() throws IOException {
         return new StringReader(text);
     }

Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/message/MessageTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/message/MessageTest.java?rev=778453&r1=778452&r2=778453&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/message/MessageTest.java
(original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/message/MessageTest.java
Mon May 25 17:02:25 2009
@@ -25,7 +25,6 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.io.OutputStream;
 import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
@@ -490,8 +489,8 @@
         public boolean disposed = false;
 
         @Override
-        public void writeTo(OutputStream out) throws IOException {
-            out.write("dummy".getBytes("US-ASCII"));
+        public InputStream getInputStream() throws IOException {
+            return new ByteArrayInputStream("dummy".getBytes("US-ASCII"));
         }
 
         @Override



Mime
View raw message