james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1482291 - in /james/mime4j/trunk: benchmark/src/main/java/org/apache/james/mime4j/ core/src/main/java/org/apache/james/mime4j/codec/ core/src/main/java/org/apache/james/mime4j/util/ core/src/test/java/org/apache/james/mime4j/codec/ dom/src...
Date Tue, 14 May 2013 10:44:13 GMT
Author: olegk
Date: Tue May 14 10:44:12 2013
New Revision: 1482291

URL: http://svn.apache.org/r1482291
Log:
Moved CodecUtil methods to ContentUtil / EncoderUtil

Removed:
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/CodecUtil.java
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/CodecUtilTest.java
Modified:
    james/mime4j/trunk/benchmark/src/main/java/org/apache/james/mime4j/Base64InputStreamBench.java
    james/mime4j/trunk/benchmark/src/main/java/org/apache/james/mime4j/LongMultipartReadBench.java
    james/mime4j/trunk/benchmark/src/main/java/org/apache/james/mime4j/QuotedPrintableInputStreamBench.java
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/EncoderUtil.java
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/util/ContentUtil.java
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/Base64InputStreamTest.java
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/EncoderUtilTest.java
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableEncodeTest.java
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableTextEncodeTest.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/DefaultMessageWriter.java
    james/mime4j/trunk/storage/src/main/java/org/apache/james/mime4j/storage/AbstractStorageProvider.java
    james/mime4j/trunk/storage/src/main/java/org/apache/james/mime4j/storage/StorageBinaryBody.java
    james/mime4j/trunk/storage/src/test/java/org/apache/james/mime4j/storage/StorageProviderTest.java

Modified: james/mime4j/trunk/benchmark/src/main/java/org/apache/james/mime4j/Base64InputStreamBench.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/benchmark/src/main/java/org/apache/james/mime4j/Base64InputStreamBench.java?rev=1482291&r1=1482290&r2=1482291&view=diff
==============================================================================
--- james/mime4j/trunk/benchmark/src/main/java/org/apache/james/mime4j/Base64InputStreamBench.java
(original)
+++ james/mime4j/trunk/benchmark/src/main/java/org/apache/james/mime4j/Base64InputStreamBench.java
Tue May 14 10:44:12 2013
@@ -28,7 +28,8 @@ import java.util.Random;
 
 import org.apache.commons.io.output.NullOutputStream;
 import org.apache.james.mime4j.codec.Base64InputStream;
-import org.apache.james.mime4j.codec.CodecUtil;
+import org.apache.james.mime4j.codec.EncoderUtil;
+import org.apache.james.mime4j.util.ContentUtil;
 
 public class Base64InputStreamBench {
 
@@ -47,7 +48,7 @@ public class Base64InputStreamBench {
         for (int i = 0; i < 5; i++) {
             ByteArrayInputStream ed = new ByteArrayInputStream(encoded);
             InputStream in = new Base64InputStream(ed);
-            CodecUtil.copy(in, nullOut);
+            ContentUtil.copy(in, nullOut);
         }
         Thread.sleep(100);
 
@@ -59,7 +60,7 @@ public class Base64InputStreamBench {
         for (int i = 0; i < repetitions; i++) {
             ByteArrayInputStream ed = new ByteArrayInputStream(encoded);
             InputStream in = new Base64InputStream(ed);
-            CodecUtil.copy(in, nullOut);
+            ContentUtil.copy(in, nullOut);
         }
 
         long dt = System.currentTimeMillis() - t0;
@@ -82,7 +83,7 @@ public class Base64InputStreamBench {
     private static byte[] encode(byte[] data) throws IOException {
         InputStream in = new ByteArrayInputStream(data);
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        CodecUtil.encodeBase64(in, out);
+        EncoderUtil.encodeB(in, out);
         return out.toByteArray();
     }
 
@@ -91,7 +92,7 @@ public class Base64InputStreamBench {
         ByteArrayInputStream ed = new ByteArrayInputStream(encoded);
         InputStream in = new Base64InputStream(ed);
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        CodecUtil.copy(in, out);
+        ContentUtil.copy(in, out);
 
         compare(data, out.toByteArray());
     }

Modified: james/mime4j/trunk/benchmark/src/main/java/org/apache/james/mime4j/LongMultipartReadBench.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/benchmark/src/main/java/org/apache/james/mime4j/LongMultipartReadBench.java?rev=1482291&r1=1482290&r2=1482291&view=diff
==============================================================================
--- james/mime4j/trunk/benchmark/src/main/java/org/apache/james/mime4j/LongMultipartReadBench.java
(original)
+++ james/mime4j/trunk/benchmark/src/main/java/org/apache/james/mime4j/LongMultipartReadBench.java
Tue May 14 10:44:12 2013
@@ -24,7 +24,6 @@ import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 
-import org.apache.james.mime4j.codec.CodecUtil;
 import org.apache.james.mime4j.dom.Header;
 import org.apache.james.mime4j.dom.MessageBuilder;
 import org.apache.james.mime4j.message.DefaultMessageBuilder;
@@ -37,6 +36,7 @@ import org.apache.james.mime4j.storage.M
 import org.apache.james.mime4j.stream.BodyDescriptor;
 import org.apache.james.mime4j.stream.EntityState;
 import org.apache.james.mime4j.stream.MimeTokenStream;
+import org.apache.james.mime4j.util.ContentUtil;
 
 public class LongMultipartReadBench {
 
@@ -107,7 +107,7 @@ public class LongMultipartReadBench {
             return null;
         }
         try {
-            CodecUtil.copy(instream, outstream);
+            ContentUtil.copy(instream, outstream);
         } finally {
             instream.close();
         }

Modified: james/mime4j/trunk/benchmark/src/main/java/org/apache/james/mime4j/QuotedPrintableInputStreamBench.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/benchmark/src/main/java/org/apache/james/mime4j/QuotedPrintableInputStreamBench.java?rev=1482291&r1=1482290&r2=1482291&view=diff
==============================================================================
--- james/mime4j/trunk/benchmark/src/main/java/org/apache/james/mime4j/QuotedPrintableInputStreamBench.java
(original)
+++ james/mime4j/trunk/benchmark/src/main/java/org/apache/james/mime4j/QuotedPrintableInputStreamBench.java
Tue May 14 10:44:12 2013
@@ -27,8 +27,9 @@ import java.io.OutputStream;
 import java.util.Random;
 
 import org.apache.commons.io.output.NullOutputStream;
-import org.apache.james.mime4j.codec.CodecUtil;
+import org.apache.james.mime4j.codec.EncoderUtil;
 import org.apache.james.mime4j.codec.QuotedPrintableInputStream;
+import org.apache.james.mime4j.util.ContentUtil;
 
 public class QuotedPrintableInputStreamBench {
 
@@ -47,7 +48,7 @@ public class QuotedPrintableInputStreamB
         for (int i = 0; i < 5; i++) {
             ByteArrayInputStream ed = new ByteArrayInputStream(encoded);
             InputStream in = new QuotedPrintableInputStream(ed);
-            CodecUtil.copy(in, nullOut);
+            ContentUtil.copy(in, nullOut);
         }
         Thread.sleep(100);
 
@@ -59,7 +60,7 @@ public class QuotedPrintableInputStreamB
         for (int i = 0; i < repetitions; i++) {
             ByteArrayInputStream ed = new ByteArrayInputStream(encoded);
             InputStream in = new QuotedPrintableInputStream(ed);
-            CodecUtil.copy(in, nullOut);
+            ContentUtil.copy(in, nullOut);
         }
 
         long dt = System.currentTimeMillis() - t0;
@@ -82,7 +83,7 @@ public class QuotedPrintableInputStreamB
     private static byte[] encode(byte[] data) throws IOException {
         InputStream in = new ByteArrayInputStream(data);
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        CodecUtil.encodeQuotedPrintableBinary(in, out);
+        EncoderUtil.encodeQBinary(in, out);
         return out.toByteArray();
     }
 
@@ -91,7 +92,7 @@ public class QuotedPrintableInputStreamB
         ByteArrayInputStream ed = new ByteArrayInputStream(encoded);
         InputStream in = new QuotedPrintableInputStream(ed);
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        CodecUtil.copy(in, out);
+        ContentUtil.copy(in, out);
 
         compare(data, out.toByteArray());
     }

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/EncoderUtil.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/EncoderUtil.java?rev=1482291&r1=1482290&r2=1482291&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/EncoderUtil.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/EncoderUtil.java Tue
May 14 10:44:12 2013
@@ -19,6 +19,9 @@
 
 package org.apache.james.mime4j.codec;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.nio.ByteBuffer;
 import java.nio.charset.Charset;
 import java.util.BitSet;
@@ -26,6 +29,7 @@ import java.util.Locale;
 
 import org.apache.james.mime4j.Charsets;
 import org.apache.james.mime4j.util.CharsetUtil;
+import org.apache.james.mime4j.util.ContentUtil;
 
 /**
  * Static methods for encoding header field values. This includes encoded-words
@@ -398,6 +402,47 @@ public class EncoderUtil {
     }
 
     /**
+     * Encodes the given stream using Quoted-Printable.
+     * This assumes that stream is binary and therefore escapes
+     * all line endings.
+     * @param in not null
+     * @param out not null
+     * @throws IOException
+     */
+    public static void encodeQBinary(final InputStream in, final OutputStream out) throws
IOException {
+        QuotedPrintableOutputStream qpOut = new QuotedPrintableOutputStream(out, true);
+        ContentUtil.copy(in, qpOut);
+        qpOut.close();
+    }
+
+    /**
+     * Encodes the given stream using Quoted-Printable.
+     * This assumes that stream is text and therefore does not escape
+     * all line endings.
+     * @param in not null
+     * @param out not null
+     * @throws IOException
+     */
+    public static void encodeQ(final InputStream in, final OutputStream out) throws IOException
{
+        QuotedPrintableOutputStream qpOut = new QuotedPrintableOutputStream(out, false);
+        ContentUtil.copy(in, qpOut);
+        qpOut.close();
+    }
+
+    /**
+     * Encodes the given stream using base64.
+     *
+     * @param in not null
+     * @param out not null
+     * @throws IOException if an I/O error occurs
+     */
+    public static void encodeB(final InputStream in, final OutputStream out) throws IOException
{
+        Base64OutputStream b64Out = new Base64OutputStream(out);
+        ContentUtil.copy(in, b64Out);
+        b64Out.close();
+    }
+
+    /**
      * Tests whether the specified string is a token as defined in RFC 2045
      * section 5.1.
      *

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/util/ContentUtil.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/util/ContentUtil.java?rev=1482291&r1=1482290&r2=1482291&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/util/ContentUtil.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/util/ContentUtil.java Tue
May 14 10:44:12 2013
@@ -19,6 +19,9 @@
 
 package org.apache.james.mime4j.util;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
 import java.nio.ByteBuffer;
 import java.nio.CharBuffer;
@@ -34,6 +37,22 @@ public class ContentUtil {
     private ContentUtil() {
     }
 
+    static final int DEFAULT_COPY_BUFFER_SIZE = 1024;
+
+    /**
+     * Copies the contents of one stream to the other.
+     * @param in not null
+     * @param out not null
+     * @throws IOException
+     */
+    public static void copy(final InputStream in, final OutputStream out) throws IOException
{
+        final byte[] buffer = new byte[DEFAULT_COPY_BUFFER_SIZE];
+        int inputLength;
+        while (-1 != (inputLength = in.read(buffer))) {
+            out.write(buffer, 0, inputLength);
+        }
+    }
+
     /**
      * Encodes the specified string into an immutable sequence of bytes using
      * the US-ASCII charset.

Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/Base64InputStreamTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/Base64InputStreamTest.java?rev=1482291&r1=1482290&r2=1482291&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/Base64InputStreamTest.java
(original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/Base64InputStreamTest.java
Tue May 14 10:44:12 2013
@@ -155,7 +155,7 @@ public class Base64InputStreamTest {
         new Random(0).nextBytes(data);
 
         ByteArrayOutputStream eOut = new ByteArrayOutputStream();
-        CodecUtil.encodeBase64(InputStreams.create(data), eOut);
+        EncoderUtil.encodeB(InputStreams.create(data), eOut);
         byte[] encoded = eOut.toByteArray();
 
         for (int bufferSize = 1; bufferSize <= 1009; bufferSize++) {
@@ -221,7 +221,7 @@ public class Base64InputStreamTest {
     public void testStrictUnexpectedEof() throws Exception {
         Base64InputStream decoder = createStrict("VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBtZXNzYWdlI");
         try {
-            CodecUtil.copy(decoder, new NullOutputStream());
+            ContentUtil.copy(decoder, new NullOutputStream());
             Assert.fail();
         } catch (IOException expected) {
             Assert.assertTrue(expected.getMessage().toLowerCase().contains(
@@ -233,7 +233,7 @@ public class Base64InputStreamTest {
     public void testLenientUnexpectedEof() throws Exception {
         Base64InputStream decoder = create("VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBtZXNzYWdlI");
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        CodecUtil.copy(decoder, out);
+        ContentUtil.copy(decoder, out);
         Assert.assertEquals("This is the plain text message", ContentUtil.toAsciiString(
                 out.toByteArray()));
     }
@@ -242,7 +242,7 @@ public class Base64InputStreamTest {
     public void testStrictUnexpectedPad() throws Exception {
         Base64InputStream decoder = createStrict("VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBtZXNzYWdlI=");
         try {
-            CodecUtil.copy(decoder, new NullOutputStream());
+            ContentUtil.copy(decoder, new NullOutputStream());
             Assert.fail();
         } catch (IOException expected) {
             Assert.assertTrue(expected.getMessage().toLowerCase().contains("pad"));
@@ -253,7 +253,7 @@ public class Base64InputStreamTest {
     public void testLenientUnexpectedPad() throws Exception {
         Base64InputStream decoder = create("VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBtZXNzYWdlI=");
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        CodecUtil.copy(decoder, out);
+        ContentUtil.copy(decoder, out);
         Assert.assertEquals("This is the plain text message", ContentUtil.toAsciiString(
                 out.toByteArray()));
     }

Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/EncoderUtilTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/EncoderUtilTest.java?rev=1482291&r1=1482290&r2=1482291&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/EncoderUtilTest.java
(original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/EncoderUtilTest.java
Tue May 14 10:44:12 2013
@@ -19,12 +19,17 @@
 
 package org.apache.james.mime4j.codec;
 
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
 import java.nio.charset.Charset;
 
 import org.apache.james.mime4j.Charsets;
 import org.apache.james.mime4j.codec.EncoderUtil.Encoding;
 import org.apache.james.mime4j.codec.EncoderUtil.Usage;
+import org.apache.james.mime4j.io.InputStreams;
+import org.apache.james.mime4j.util.ContentUtil;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -212,4 +217,77 @@ public class EncoderUtilTest {
         }
     }
 
+    @Test
+    public void testEncodeQuotedPrintableLargeInput() throws Exception {
+        StringBuilder sb = new StringBuilder();
+        for (int i = 0; i < 1024 * 5; i++) {
+            sb.append((char) ('0' + (i % 10)));
+        }
+        String expected = sb.toString().replaceAll("(\\d{75})", "$1=\r\n");
+
+        InputStream in = InputStreams.createAscii(sb.toString());
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        EncoderUtil.encodeQBinary(in, out);
+        String actual = ContentUtil.toAsciiString(out.toByteArray());
+        Assert.assertEquals(expected, actual);
+    }
+
+    @Test
+    public void testEncodeQuotedPrintableNonAsciiChars() throws Exception {
+        String s = "7bit content with euro \u20AC symbol";
+        InputStream in = InputStreams.create(s, Charset.forName("iso-8859-15"));
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        EncoderUtil.encodeQBinary(in, out);
+        String actual = new String(out.toByteArray(), "US-ASCII");
+        Assert.assertEquals("7bit=20content=20with=20euro=20=A4=20symbol", actual);
+    }
+
+    @Test
+    public void testBase64OutputStream() throws Exception {
+        StringBuilder sb = new StringBuilder(2048);
+        for (int i = 0; i < 128; i++) {
+            sb.append("0123456789ABCDEF");
+        }
+        String input = sb.toString();
+        String output = roundtripUsingOutputStream(input);
+        Assert.assertEquals(input, output);
+    }
+
+    private String roundtripUsingOutputStream(String input) throws IOException {
+        ByteArrayOutputStream out2 = new ByteArrayOutputStream();
+        Base64OutputStream outb64 = new Base64OutputStream(out2, 76);
+        ContentUtil.copy(InputStreams.create(input, Charsets.ISO_8859_1), outb64);
+        outb64.flush();
+        outb64.close();
+
+        InputStream is = new Base64InputStream(InputStreams.create(out2.toByteArray()));
+        ByteArrayOutputStream outRoundtrip = new ByteArrayOutputStream();
+        ContentUtil.copy(is, outRoundtrip);
+        return new String(outRoundtrip.toByteArray());
+    }
+
+    /**
+     * This test is a proof for MIME4J-67
+     */
+    @Test
+    public void testBase64Encoder() throws Exception {
+        StringBuilder sb = new StringBuilder(2048);
+        for (int i = 0; i < 128; i++) {
+            sb.append("0123456789ABCDEF");
+        }
+        String input = sb.toString();
+        String output = roundtripUsingEncoder(input);
+        Assert.assertEquals(input, output);
+    }
+
+    private String roundtripUsingEncoder(String input) throws IOException {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        EncoderUtil.encodeB(InputStreams.createAscii(input), out);
+
+        InputStream is = new Base64InputStream(InputStreams.create(out.toByteArray()));
+        ByteArrayOutputStream outRoundtrip = new ByteArrayOutputStream();
+        ContentUtil.copy(is, outRoundtrip);
+        return new String(outRoundtrip.toByteArray());
+    }
+
 }

Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableEncodeTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableEncodeTest.java?rev=1482291&r1=1482290&r2=1482291&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableEncodeTest.java
(original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableEncodeTest.java
Tue May 14 10:44:12 2013
@@ -112,7 +112,7 @@ public class QuotedPrintableEncodeTest {
     private void checkRoundtrip(byte[] content) throws Exception {
         InputStream in = InputStreams.create(content);
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        CodecUtil.encodeQuotedPrintableBinary(in, out);
+        EncoderUtil.encodeQBinary(in, out);
         // read back through decoder
         in = new QuotedPrintableInputStream(InputStreams.create(out.toByteArray()));
         out = new ByteArrayOutputStream();
@@ -123,7 +123,7 @@ public class QuotedPrintableEncodeTest {
     private void check(byte[] content, byte[] expected) throws Exception {
         InputStream in = InputStreams.create(content);
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        CodecUtil.encodeQuotedPrintableBinary(in, out);
+        EncoderUtil.encodeQBinary(in, out);
         assertEquals(expected, out.toByteArray());
     }
 

Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableTextEncodeTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableTextEncodeTest.java?rev=1482291&r1=1482290&r2=1482291&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableTextEncodeTest.java
(original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableTextEncodeTest.java
Tue May 14 10:44:12 2013
@@ -156,7 +156,7 @@ public class QuotedPrintableTextEncodeTe
     private void checkRoundtrip(byte[] content) throws Exception {
         InputStream in = InputStreams.create(content);
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        CodecUtil.encodeQuotedPrintable(in, out);
+        EncoderUtil.encodeQ(in, out);
         // read back through decoder
         in = new QuotedPrintableInputStream(InputStreams.create(out.toByteArray()));
         out = new ByteArrayOutputStream();
@@ -171,7 +171,7 @@ public class QuotedPrintableTextEncodeTe
     private void check(byte[] content, byte[] expected) throws Exception {
         InputStream in = InputStreams.create(content);
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        CodecUtil.encodeQuotedPrintable(in, out);
+        EncoderUtil.encodeQ(in, out);
         assertEquals(expected, out.toByteArray());
     }
 

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/DefaultMessageWriter.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/DefaultMessageWriter.java?rev=1482291&r1=1482290&r2=1482291&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/DefaultMessageWriter.java
(original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/DefaultMessageWriter.java
Tue May 14 10:44:12 2013
@@ -22,7 +22,8 @@ package org.apache.james.mime4j.message;
 import java.io.IOException;
 import java.io.OutputStream;
 
-import org.apache.james.mime4j.codec.CodecUtil;
+import org.apache.james.mime4j.codec.Base64OutputStream;
+import org.apache.james.mime4j.codec.QuotedPrintableOutputStream;
 import org.apache.james.mime4j.dom.BinaryBody;
 import org.apache.james.mime4j.dom.Body;
 import org.apache.james.mime4j.dom.Entity;
@@ -221,9 +222,9 @@ public class DefaultMessageWriter implem
     protected OutputStream encodeStream(OutputStream out, String encoding,
             boolean binaryBody) throws IOException {
         if (MimeUtil.isBase64Encoding(encoding)) {
-            return CodecUtil.wrapBase64(out);
+            return new Base64OutputStream(out);
         } else if (MimeUtil.isQuotedPrintableEncoded(encoding)) {
-            return CodecUtil.wrapQuotedPrintable(out, binaryBody);
+            return new QuotedPrintableOutputStream(out, binaryBody);
         } else {
             return out;
         }

Modified: james/mime4j/trunk/storage/src/main/java/org/apache/james/mime4j/storage/AbstractStorageProvider.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/storage/src/main/java/org/apache/james/mime4j/storage/AbstractStorageProvider.java?rev=1482291&r1=1482290&r2=1482291&view=diff
==============================================================================
--- james/mime4j/trunk/storage/src/main/java/org/apache/james/mime4j/storage/AbstractStorageProvider.java
(original)
+++ james/mime4j/trunk/storage/src/main/java/org/apache/james/mime4j/storage/AbstractStorageProvider.java
Tue May 14 10:44:12 2013
@@ -22,7 +22,7 @@ package org.apache.james.mime4j.storage;
 import java.io.IOException;
 import java.io.InputStream;
 
-import org.apache.james.mime4j.codec.CodecUtil;
+import org.apache.james.mime4j.util.ContentUtil;
 
 /**
  * Abstract implementation of {@link StorageProvider} that implements
@@ -54,7 +54,7 @@ public abstract class AbstractStoragePro
      */
     public final Storage store(InputStream in) throws IOException {
         StorageOutputStream out = createStorageOutputStream();
-        CodecUtil.copy(in, out);
+        ContentUtil.copy(in, out);
         return out.toStorage();
     }
 

Modified: james/mime4j/trunk/storage/src/main/java/org/apache/james/mime4j/storage/StorageBinaryBody.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/storage/src/main/java/org/apache/james/mime4j/storage/StorageBinaryBody.java?rev=1482291&r1=1482290&r2=1482291&view=diff
==============================================================================
--- james/mime4j/trunk/storage/src/main/java/org/apache/james/mime4j/storage/StorageBinaryBody.java
(original)
+++ james/mime4j/trunk/storage/src/main/java/org/apache/james/mime4j/storage/StorageBinaryBody.java
Tue May 14 10:44:12 2013
@@ -23,8 +23,9 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 
-import org.apache.james.mime4j.codec.CodecUtil;
 import org.apache.james.mime4j.dom.BinaryBody;
+import org.apache.james.mime4j.util.ContentUtil;
+;
 
 /**
  * Binary body backed by a
@@ -49,7 +50,7 @@ class StorageBinaryBody extends BinaryBo
             throw new IllegalArgumentException();
 
         InputStream in = storage.getInputStream();
-        CodecUtil.copy(in, out);
+        ContentUtil.copy(in, out);
         in.close();
     }
 

Modified: james/mime4j/trunk/storage/src/test/java/org/apache/james/mime4j/storage/StorageProviderTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/storage/src/test/java/org/apache/james/mime4j/storage/StorageProviderTest.java?rev=1482291&r1=1482290&r2=1482291&view=diff
==============================================================================
--- james/mime4j/trunk/storage/src/test/java/org/apache/james/mime4j/storage/StorageProviderTest.java
(original)
+++ james/mime4j/trunk/storage/src/test/java/org/apache/james/mime4j/storage/StorageProviderTest.java
Tue May 14 10:44:12 2013
@@ -19,14 +19,14 @@
 
 package org.apache.james.mime4j.storage;
 
-import org.apache.james.mime4j.codec.CodecUtil;
-import org.junit.Assert;
-import org.junit.Test;
-
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 
+import org.apache.james.mime4j.util.ContentUtil;
+import org.junit.Assert;
+import org.junit.Test;
+
 public class StorageProviderTest {
 
     @Test
@@ -98,7 +98,7 @@ public class StorageProviderTest {
         Storage storage = provider.store(new ByteArrayInputStream(data));
 
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        CodecUtil.copy(storage.getInputStream(), baos);
+        ContentUtil.copy(storage.getInputStream(), baos);
         verifyData(data, baos.toByteArray());
     }
 
@@ -108,11 +108,11 @@ public class StorageProviderTest {
         Assert.assertEquals(size, data.length);
 
         StorageOutputStream out = provider.createStorageOutputStream();
-        CodecUtil.copy(new ByteArrayInputStream(data), out);
+        ContentUtil.copy(new ByteArrayInputStream(data), out);
         Storage storage = out.toStorage();
 
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        CodecUtil.copy(storage.getInputStream(), baos);
+        ContentUtil.copy(storage.getInputStream(), baos);
         verifyData(data, baos.toByteArray());
     }
 



Mime
View raw message