james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1482289 - in /james/mime4j/trunk: core/src/main/java/org/apache/james/mime4j/ core/src/main/java/org/apache/james/mime4j/codec/ core/src/main/java/org/apache/james/mime4j/io/ core/src/main/java/org/apache/james/mime4j/stream/ core/src/main...
Date Tue, 14 May 2013 10:43:36 GMT
Author: olegk
Date: Tue May 14 10:43:35 2013
New Revision: 1482289

URL: http://svn.apache.org/r1482289
Log:
Moved standard charsets to a separate class

Added:
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/Charsets.java
      - copied, changed from r1481814, james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/StringBody.java
Modified:
    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/io/InputStreams.java
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/MimeTokenStream.java
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/util/CharsetUtil.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/ExampleMail.java
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/CodecUtilTest.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/QuotedPrintableInputStreamTest.java
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableTextEncodeTest.java
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/MimeStreamParserExampleMessagesTest.java
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MimeTokenNoRecurseTest.java
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MultipartStreamTest.java
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MultipartTokensTest.java
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/util/CharsetUtilTest.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/BasicBodyFactory.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/BasicTextBody.java
    james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/StringBody.java
    james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/ExampleMessagesRoundtripTest.java
    james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageParserTest.java
    james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/message/StringInputStreamTest.java
    james/mime4j/trunk/storage/src/main/java/org/apache/james/mime4j/storage/StorageBodyFactory.java
    james/mime4j/trunk/storage/src/test/java/org/apache/james/mime4j/storage/SingleBodyCopyTest.java

Copied: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/Charsets.java (from r1481814, james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/StringBody.java)
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/Charsets.java?p2=james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/Charsets.java&p1=james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/StringBody.java&r1=1481814&r2=1482289&rev=1482289&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/StringBody.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/Charsets.java Tue May 14 10:43:35 2013
@@ -17,48 +17,16 @@
  * under the License.                                           *
  ****************************************************************/
 
-package org.apache.james.mime4j.message;
+package org.apache.james.mime4j;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-import java.io.StringReader;
 import java.nio.charset.Charset;
 
-import org.apache.james.mime4j.dom.SingleBody;
-import org.apache.james.mime4j.dom.TextBody;
-import org.apache.james.mime4j.util.CharsetUtil;
-
-class StringBody extends TextBody {
-
-    private final String content;
-    private final Charset charset;
-
-    StringBody(final String content, final Charset charset) {
-        super();
-        this.content = content;
-        this.charset = charset;
-    }
-
-    @Override
-    public String getMimeCharset() {
-        return this.charset != null ? this.charset.name() : null;
-    }
-
-    @Override
-    public Reader getReader() throws IOException {
-        return new StringReader(this.content);
-    }
-
-    @Override
-    public InputStream getInputStream() throws IOException {
-        return new StringInputStream(this.content,
-                this.charset != null ? this.charset : CharsetUtil.DEFAULT_CHARSET, 2048);
-    }
-
-    @Override
-    public SingleBody copy() {
-        return new StringBody(this.content, this.charset);
-    }
+public final class Charsets {
+
+    public static final Charset US_ASCII = Charset.forName("US-ASCII");
+    public static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
+    public static final Charset UTF_8 = Charset.forName("UTF-8");
+
+    public static final Charset DEFAULT_CHARSET = US_ASCII;
 
 }

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=1482289&r1=1482288&r2=1482289&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:43:35 2013
@@ -24,6 +24,7 @@ import java.nio.charset.Charset;
 import java.util.BitSet;
 import java.util.Locale;
 
+import org.apache.james.mime4j.Charsets;
 import org.apache.james.mime4j.util.CharsetUtil;
 
 /**
@@ -567,13 +568,13 @@ public class EncoderUtil {
         for (int index = 0; index < len; index++) {
             char ch = text.charAt(index);
             if (ch > 0xff) {
-                return CharsetUtil.UTF_8;
+                return Charsets.UTF_8;
             }
             if (ch > 0x7f) {
                 ascii = false;
             }
         }
-        return ascii ? CharsetUtil.US_ASCII : CharsetUtil.ISO_8859_1;
+        return ascii ? Charsets.US_ASCII : Charsets.ISO_8859_1;
     }
 
     private static Encoding determineEncoding(byte[] bytes, Usage usage) {

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/InputStreams.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/InputStreams.java?rev=1482289&r1=1482288&r2=1482289&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/InputStreams.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/InputStreams.java Tue May 14 10:43:35 2013
@@ -23,8 +23,8 @@ import java.io.InputStream;
 import java.nio.ByteBuffer;
 import java.nio.charset.Charset;
 
+import org.apache.james.mime4j.Charsets;
 import org.apache.james.mime4j.util.ByteArrayBuffer;
-import org.apache.james.mime4j.util.CharsetUtil;
 
 /**
  * Factory methods for {@link InputStream} instances backed by binary or textual data that attempt
@@ -67,14 +67,14 @@ public final class InputStreams {
         if (s == null) {
             throw new IllegalArgumentException("String may not be null");
         }
-        return new TextInputStream(s, CharsetUtil.US_ASCII, 1024);
+        return new TextInputStream(s, Charsets.US_ASCII, 1024);
     }
 
     public static InputStream create(final String s, final Charset charset) {
         if (s == null) {
             throw new IllegalArgumentException("String may not be null");
         }
-        return new TextInputStream(s, charset != null ? charset : CharsetUtil.DEFAULT_CHARSET, 1024);
+        return new TextInputStream(s, charset != null ? charset : Charsets.DEFAULT_CHARSET, 1024);
     }
 
 }

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/MimeTokenStream.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/MimeTokenStream.java?rev=1482289&r1=1482288&r2=1482289&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/MimeTokenStream.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/MimeTokenStream.java Tue May 14 10:43:35 2013
@@ -24,12 +24,14 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
 import java.nio.charset.Charset;
+import java.nio.charset.IllegalCharsetNameException;
+import java.nio.charset.UnsupportedCharsetException;
 import java.util.LinkedList;
 
+import org.apache.james.mime4j.Charsets;
 import org.apache.james.mime4j.MimeException;
 import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.io.LineNumberInputStream;
-import org.apache.james.mime4j.util.CharsetUtil;
 
 /**
  * <p>
@@ -319,7 +321,7 @@ public class MimeTokenStream {
         final String mimeCharset = bodyDescriptor.getCharset();
         final Charset charset;
         if (mimeCharset == null || "".equals(mimeCharset)) {
-            charset = CharsetUtil.US_ASCII;
+            charset = Charsets.US_ASCII;
         } else {
             charset = Charset.forName(mimeCharset);
         }

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/util/CharsetUtil.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/util/CharsetUtil.java?rev=1482289&r1=1482288&r2=1482289&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/util/CharsetUtil.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/util/CharsetUtil.java Tue May 14 10:43:35 2013
@@ -43,14 +43,6 @@ public class CharsetUtil {
     /** US-ASCII HT, horizontal-tab (9) */
     public static final int HT = '\t';
 
-    public static final Charset US_ASCII = Charset.forName("US-ASCII");
-
-    public static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
-
-    public static final Charset UTF_8 = Charset.forName("UTF-8");
-
-    public static final Charset DEFAULT_CHARSET = US_ASCII;
-
     /**
      * Returns <code>true</code> if the specified character falls into the US
      * ASCII character set (Unicode range 0000 to 007f).

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=1482289&r1=1482288&r2=1482289&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:43:35 2013
@@ -24,6 +24,8 @@ import java.nio.ByteBuffer;
 import java.nio.CharBuffer;
 import java.nio.charset.Charset;
 
+import org.apache.james.mime4j.Charsets;
+
 /**
  * Utility methods for converting textual content of a message.
  */
@@ -168,7 +170,7 @@ public class ContentUtil {
             return null;
         }
         try {
-            return s.getBytes((charset != null ? charset : CharsetUtil.DEFAULT_CHARSET).name());
+            return s.getBytes((charset != null ? charset : Charsets.DEFAULT_CHARSET).name());
         } catch (UnsupportedEncodingException ex) {
             // Should never happen
             throw new Error(ex);
@@ -176,7 +178,7 @@ public class ContentUtil {
     }
 
     public static byte[] toAsciiByteArray(final String s) {
-        return toByteArray(s, CharsetUtil.US_ASCII);
+        return toByteArray(s, Charsets.US_ASCII);
     }
 
     public static String toString(final byte[] b, final Charset charset) {
@@ -184,7 +186,7 @@ public class ContentUtil {
             return null;
         }
         try {
-            return new String(b, (charset != null ? charset : CharsetUtil.DEFAULT_CHARSET).name());
+            return new String(b, (charset != null ? charset : Charsets.DEFAULT_CHARSET).name());
         } catch (UnsupportedEncodingException ex) {
             // Should never happen
             throw new Error(ex);
@@ -192,7 +194,7 @@ public class ContentUtil {
     }
 
     public static String toAsciiString(final byte[] b) {
-        return toString(b, CharsetUtil.US_ASCII);
+        return toString(b, Charsets.US_ASCII);
     }
 
     public static String toString(final byte[] b, int off, int len, final Charset charset) {
@@ -201,7 +203,7 @@ public class ContentUtil {
         }
         try {
             return new String(b, off, len,
-                    (charset != null ? charset : CharsetUtil.DEFAULT_CHARSET).name());
+                    (charset != null ? charset : Charsets.DEFAULT_CHARSET).name());
         } catch (UnsupportedEncodingException ex) {
             // Should never happen
             throw new Error(ex);
@@ -209,7 +211,7 @@ public class ContentUtil {
     }
 
     public static String toAsciiString(final byte[] b, int off, int len) {
-        return toString(b, off, len, CharsetUtil.US_ASCII);
+        return toString(b, off, len, Charsets.US_ASCII);
     }
 
     public static String toString(final ByteArrayBuffer b, final Charset charset) {
@@ -218,7 +220,7 @@ public class ContentUtil {
         }
         try {
             return new String(b.buffer(), 0, b.length(),
-                    (charset != null ? charset : CharsetUtil.DEFAULT_CHARSET).name());
+                    (charset != null ? charset : Charsets.DEFAULT_CHARSET).name());
         } catch (UnsupportedEncodingException ex) {
             // Should never happen
             throw new Error(ex);
@@ -226,7 +228,7 @@ public class ContentUtil {
     }
 
     public static String toAsciiString(final ByteArrayBuffer b) {
-        return toString(b, CharsetUtil.US_ASCII);
+        return toString(b, Charsets.US_ASCII);
     }
 
 }

Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/ExampleMail.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/ExampleMail.java?rev=1482289&r1=1482288&r2=1482289&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/ExampleMail.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/ExampleMail.java Tue May 14 10:43:35 2013
@@ -22,7 +22,6 @@ package org.apache.james.mime4j;
 import java.util.Locale;
 
 import org.apache.james.mime4j.codec.EncoderUtil;
-import org.apache.james.mime4j.util.CharsetUtil;
 import org.apache.james.mime4j.util.ContentUtil;
 
 public class ExampleMail {
@@ -658,7 +657,7 @@ public class ExampleMail {
     }
 
     public static byte[] latin1(final String text) {
-        return ContentUtil.toByteArray(text, CharsetUtil.ISO_8859_1);
+        return ContentUtil.toByteArray(text, Charsets.ISO_8859_1);
     }
 
     public static String ascii(final byte[] b) {
@@ -666,7 +665,7 @@ public class ExampleMail {
     }
 
     public static String latin1(final byte[] b) {
-        return ContentUtil.toString(b, CharsetUtil.ISO_8859_1);
+        return ContentUtil.toString(b, Charsets.ISO_8859_1);
     }
 
     public static byte[] join(byte[] one, byte[] two) {

Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/CodecUtilTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/CodecUtilTest.java?rev=1482289&r1=1482288&r2=1482289&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/CodecUtilTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/CodecUtilTest.java Tue May 14 10:43:35 2013
@@ -26,9 +26,9 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.nio.charset.Charset;
 
+import org.apache.james.mime4j.Charsets;
 import org.apache.james.mime4j.ExampleMail;
 import org.apache.james.mime4j.io.InputStreams;
-import org.apache.james.mime4j.util.CharsetUtil;
 import org.apache.james.mime4j.util.ContentUtil;
 import org.junit.Assert;
 import org.junit.Test;
@@ -82,7 +82,7 @@ public class CodecUtilTest {
     private String roundtripUsingOutputStream(String input) throws IOException {
         ByteArrayOutputStream out2 = new ByteArrayOutputStream();
         Base64OutputStream outb64 = new Base64OutputStream(out2, 76);
-        CodecUtil.copy(InputStreams.create(input, CharsetUtil.ISO_8859_1), outb64);
+        CodecUtil.copy(InputStreams.create(input, Charsets.ISO_8859_1), outb64);
         outb64.flush();
         outb64.close();
 

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=1482289&r1=1482288&r2=1482289&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:43:35 2013
@@ -19,15 +19,15 @@
 
 package org.apache.james.mime4j.codec;
 
+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.util.CharsetUtil;
 import org.junit.Assert;
 import org.junit.Test;
 
-import java.io.UnsupportedEncodingException;
-import java.nio.charset.Charset;
-
 public class EncoderUtilTest {
 
     @Test
@@ -101,7 +101,7 @@ public class EncoderUtilTest {
     @Test
     public void testEncodeEncodedWordForceCharset() throws Exception {
         Assert.assertTrue(EncoderUtil.encodeEncodedWord("only ascii",
-                Usage.TEXT_TOKEN, 0, CharsetUtil.UTF_8, null).startsWith(
+                Usage.TEXT_TOKEN, 0, Charsets.UTF_8, null).startsWith(
                 "=?UTF-8?"));
     }
 

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=1482289&r1=1482288&r2=1482289&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:43:35 2013
@@ -19,17 +19,17 @@
 
 package org.apache.james.mime4j.codec;
 
-import org.apache.commons.io.IOUtils;
-import org.apache.james.mime4j.io.InputStreams;
-import org.apache.james.mime4j.util.CharsetUtil;
-import org.junit.Assert;
-import org.junit.Test;
-
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 import java.nio.charset.Charset;
 import java.util.Arrays;
 
+import org.apache.commons.io.IOUtils;
+import org.apache.james.mime4j.Charsets;
+import org.apache.james.mime4j.io.InputStreams;
+import org.junit.Assert;
+import org.junit.Test;
+
 public class QuotedPrintableEncodeTest {
 
     @Test
@@ -102,7 +102,7 @@ public class QuotedPrintableEncodeTest {
     }
 
     private void checkRoundtrip(String content) throws Exception {
-        checkRoundtrip(content, CharsetUtil.US_ASCII);
+        checkRoundtrip(content, Charsets.US_ASCII);
     }
 
     private void checkRoundtrip(String content, Charset charset) throws Exception {

Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableInputStreamTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableInputStreamTest.java?rev=1482289&r1=1482288&r2=1482289&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableInputStreamTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableInputStreamTest.java Tue May 14 10:43:35 2013
@@ -24,15 +24,15 @@ import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.james.mime4j.Charsets;
 import org.apache.james.mime4j.io.InputStreams;
-import org.apache.james.mime4j.util.CharsetUtil;
 import org.junit.Assert;
 import org.junit.Test;
 
 public class QuotedPrintableInputStreamTest {
 
     private static String readText(final InputStream is) throws IOException {
-        return new String(IOUtils.toByteArray(is), CharsetUtil.ISO_8859_1.name());
+        return IOUtils.toString(is, Charsets.ISO_8859_1.name());
     }
 
     @Test

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=1482289&r1=1482288&r2=1482289&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:43:35 2013
@@ -19,17 +19,18 @@
 
 package org.apache.james.mime4j.codec;
 
-import org.apache.commons.io.IOUtils;
-import org.apache.james.mime4j.io.InputStreams;
-import org.apache.james.mime4j.util.CharsetUtil;
-import org.junit.Assert;
-import org.junit.Test;
-
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 import java.nio.charset.Charset;
 import java.util.Arrays;
 
+import org.apache.commons.io.IOUtils;
+import org.apache.james.mime4j.Charsets;
+import org.apache.james.mime4j.io.InputStreams;
+import org.apache.james.mime4j.util.ContentUtil;
+import org.junit.Assert;
+import org.junit.Test;
+
 public class QuotedPrintableTextEncodeTest {
 
     @Test
@@ -145,7 +146,7 @@ public class QuotedPrintableTextEncodeTe
     }
 
     private void checkRoundtrip(String content) throws Exception {
-        checkRoundtrip(content, CharsetUtil.US_ASCII);
+        checkRoundtrip(content, Charsets.US_ASCII);
     }
 
     private void checkRoundtrip(String content, Charset charset) throws Exception {
@@ -164,11 +165,9 @@ public class QuotedPrintableTextEncodeTe
     }
 
     private void check(String content, String expected) throws Exception {
-        Charset ascii = CharsetUtil.US_ASCII;
-        check(ascii.encode(content).array(), ascii.encode(expected).array());
+        check(ContentUtil.toAsciiByteArray(content), ContentUtil.toAsciiByteArray(expected));
     }
 
-
     private void check(byte[] content, byte[] expected) throws Exception {
         InputStream in = InputStreams.create(content);
         ByteArrayOutputStream out = new ByteArrayOutputStream();

Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/MimeStreamParserExampleMessagesTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/MimeStreamParserExampleMessagesTest.java?rev=1482289&r1=1482288&r2=1482289&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/MimeStreamParserExampleMessagesTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/MimeStreamParserExampleMessagesTest.java Tue May 14 10:43:35 2013
@@ -29,11 +29,11 @@ import java.net.URL;
 import junit.framework.TestSuite;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.james.mime4j.Charsets;
 import org.apache.james.mime4j.ExampleMessageTestCase;
 import org.apache.james.mime4j.ExampleMessageTestCaseFactory;
 import org.apache.james.mime4j.ExampleMessageTestSuiteBuilder;
 import org.apache.james.mime4j.stream.MimeConfig;
-import org.apache.james.mime4j.util.CharsetUtil;
 import org.junit.Assert;
 import org.junit.runner.RunWith;
 import org.junit.runners.AllTests;
@@ -82,7 +82,7 @@ public class MimeStreamParserExampleMess
             String expected;
             InputStream contentstream = xmlFileUrl.openStream();
             try {
-                expected = IOUtils.toString(contentstream, CharsetUtil.ISO_8859_1.name());
+                expected = IOUtils.toString(contentstream, Charsets.ISO_8859_1.name());
             } finally {
                 contentstream.close();
             }
@@ -92,7 +92,7 @@ public class MimeStreamParserExampleMess
             File expectedFileTemplate = new File(getFilenameBase() + ".xml.expected");
             FileOutputStream outstream = new FileOutputStream(expectedFileTemplate);
             try {
-                IOUtils.write(result, outstream, CharsetUtil.ISO_8859_1.name());
+                IOUtils.write(result, outstream, Charsets.ISO_8859_1.name());
             } finally {
                 outstream.close();
             }

Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MimeTokenNoRecurseTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MimeTokenNoRecurseTest.java?rev=1482289&r1=1482288&r2=1482289&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MimeTokenNoRecurseTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MimeTokenNoRecurseTest.java Tue May 14 10:43:35 2013
@@ -19,15 +19,15 @@
 
 package org.apache.james.mime4j.stream;
 
-import org.apache.james.mime4j.util.CharsetUtil;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import org.apache.james.mime4j.util.ContentUtil;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-
 public class MimeTokenNoRecurseTest {
 
     private static final String INNER_MAIL = "From: Timothy Tayler <tim@example.org>\r\n" +
@@ -69,7 +69,7 @@ public class MimeTokenNoRecurseTest {
     @Before
     public void setUp() throws Exception {
         stream = new MimeTokenStream();
-        byte[] bytes = CharsetUtil.US_ASCII.encode(MAIL_WITH_RFC822_PART).array();
+        byte[] bytes = ContentUtil.toAsciiByteArray(MAIL_WITH_RFC822_PART);
         InputStream in = new ByteArrayInputStream(bytes);
         stream.parse(in);
     }

Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MultipartStreamTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MultipartStreamTest.java?rev=1482289&r1=1482288&r2=1482289&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MultipartStreamTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MultipartStreamTest.java Tue May 14 10:43:35 2013
@@ -19,23 +19,20 @@
 
 package org.apache.james.mime4j.stream;
 
+import java.io.IOException;
+import java.io.InputStream;
+
 import org.apache.commons.io.IOUtils;
+import org.apache.james.mime4j.Charsets;
 import org.apache.james.mime4j.MimeException;
-import org.apache.james.mime4j.util.CharsetUtil;
+import org.apache.james.mime4j.io.InputStreams;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.Charset;
-
 public class MultipartStreamTest {
 
-    private static final Charset US_ASCII = CharsetUtil.US_ASCII;
-
     private static final String BODY = "A Preamble\r\n" +
             "--1729\r\n\r\n" +
             "Simple plain text\r\n" +
@@ -82,7 +79,7 @@ public class MultipartStreamTest {
 
     @Test
     public void testShouldSupplyInputStreamForSimpleBody() throws Exception {
-        parser.parse(new ByteArrayInputStream(US_ASCII.encode(MESSAGE).array()));
+        parser.parse(InputStreams.create(MESSAGE, Charsets.US_ASCII));
         checkState(EntityState.T_START_HEADER);
         checkState(EntityState.T_FIELD);
         checkState(EntityState.T_FIELD);
@@ -98,7 +95,7 @@ public class MultipartStreamTest {
 
     @Test
     public void testInputStreamShouldReadOnlyMessage() throws Exception {
-        parser.parse(new ByteArrayInputStream(US_ASCII.encode(COMPLEX_MESSAGE).array()));
+        parser.parse(InputStreams.create(COMPLEX_MESSAGE, Charsets.US_ASCII));
         checkState(EntityState.T_START_HEADER);
         checkState(EntityState.T_FIELD);
         checkState(EntityState.T_FIELD);

Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MultipartTokensTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MultipartTokensTest.java?rev=1482289&r1=1482288&r2=1482289&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MultipartTokensTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MultipartTokensTest.java Tue May 14 10:43:35 2013
@@ -19,22 +19,19 @@
 
 package org.apache.james.mime4j.stream;
 
+import java.io.IOException;
+
 import org.apache.commons.io.IOUtils;
+import org.apache.james.mime4j.Charsets;
 import org.apache.james.mime4j.MimeException;
-import org.apache.james.mime4j.util.CharsetUtil;
+import org.apache.james.mime4j.io.InputStreams;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.nio.charset.Charset;
-
 public class MultipartTokensTest {
 
-    private static final Charset US_ASCII = CharsetUtil.US_ASCII;
-
     private static final String BODY = "A Preamble\r\n" +
             "--1729\r\n\r\n" +
             "Simple plain text\r\n" +
@@ -108,7 +105,7 @@ public class MultipartTokensTest {
 
     @Test
     public void testShouldParseSimpleMessage() throws Exception {
-        parser.parse(new ByteArrayInputStream(US_ASCII.encode(MESSAGE).array()));
+        parser.parse(InputStreams.create(MESSAGE, Charsets.US_ASCII));
         checkState(EntityState.T_START_HEADER);
         checkState(EntityState.T_FIELD);
         checkState(EntityState.T_FIELD);
@@ -152,7 +149,7 @@ public class MultipartTokensTest {
                         "foo\r\n" +
                         "--outer-boundary--\r\n";
 
-        parser.parse(new ByteArrayInputStream(US_ASCII.encode(message).array()));
+        parser.parse(InputStreams.create(message, Charsets.US_ASCII));
         checkState(EntityState.T_START_HEADER);
         checkState(EntityState.T_FIELD);
         checkState(EntityState.T_END_HEADER);
@@ -178,7 +175,7 @@ public class MultipartTokensTest {
 
     @Test
     public void testShouldParseMessageWithEmbeddedMessage() throws Exception {
-        parser.parse(new ByteArrayInputStream(US_ASCII.encode(COMPLEX_MESSAGE).array()));
+        parser.parse(InputStreams.create(COMPLEX_MESSAGE, Charsets.US_ASCII));
         checkState(EntityState.T_START_HEADER);
         checkState(EntityState.T_FIELD);
         checkState(EntityState.T_FIELD);
@@ -236,7 +233,7 @@ public class MultipartTokensTest {
 
     @Test
     public void testShouldParseMessagesWithEmbeddedQuotedPrintableEncodedMessage() throws Exception {
-        parser.parse(new ByteArrayInputStream(US_ASCII.encode(COMPLEX_QP_MESSAGE).array()));
+        parser.parse(InputStreams.create(COMPLEX_QP_MESSAGE, Charsets.US_ASCII));
         checkState(EntityState.T_START_HEADER);
         checkState(EntityState.T_FIELD);
         checkState(EntityState.T_FIELD);
@@ -277,7 +274,7 @@ public class MultipartTokensTest {
 
     @Test
     public void testMultipartMessageWithoutHeader() throws Exception {
-        parser.parseHeadless(new ByteArrayInputStream(US_ASCII.encode(BODY).array()),
+        parser.parseHeadless(InputStreams.create(BODY, Charsets.US_ASCII),
                 "multipart/mixed;boundary=1729");
         // see https://issues.apache.org/jira/browse/MIME4J-153
         // checkState(EntityStates.T_END_HEADER);

Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/util/CharsetUtilTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/util/CharsetUtilTest.java?rev=1482289&r1=1482288&r2=1482289&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/util/CharsetUtilTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/util/CharsetUtilTest.java Tue May 14 10:43:35 2013
@@ -19,11 +19,12 @@
 
 package org.apache.james.mime4j.util;
 
+import java.nio.charset.Charset;
+
+import org.apache.james.mime4j.Charsets;
 import org.junit.Assert;
 import org.junit.Test;
 
-import java.nio.charset.Charset;
-
 public class CharsetUtilTest {
 
     private static final String SWISS_GERMAN_HELLO = "Gr\374ezi_z\344m\344";
@@ -45,8 +46,8 @@ public class CharsetUtilTest {
     public void testCharsetLookup() {
         Charset c1 = CharsetUtil.lookup("us-ascii");
         Charset c2 = CharsetUtil.lookup("ascii");
-        Assert.assertEquals(CharsetUtil.US_ASCII, c1);
-        Assert.assertEquals(CharsetUtil.US_ASCII, c2);
+        Assert.assertEquals(Charsets.US_ASCII, c1);
+        Assert.assertEquals(Charsets.US_ASCII, c2);
     }
 
     @Test

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/BasicBodyFactory.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/BasicBodyFactory.java?rev=1482289&r1=1482288&r2=1482289&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/BasicBodyFactory.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/BasicBodyFactory.java Tue May 14 10:43:35 2013
@@ -26,9 +26,9 @@ import java.io.UnsupportedEncodingExcept
 import java.nio.charset.Charset;
 import java.nio.charset.UnsupportedCharsetException;
 
+import org.apache.james.mime4j.Charsets;
 import org.apache.james.mime4j.dom.BinaryBody;
 import org.apache.james.mime4j.dom.TextBody;
-import org.apache.james.mime4j.util.CharsetUtil;
 
 /**
  * Factory for creating message bodies.
@@ -79,7 +79,7 @@ public class BasicBodyFactory implements
     }
 
     public TextBody textBody(final String text) {
-        return textBody(text, CharsetUtil.DEFAULT_CHARSET);
+        return textBody(text, Charsets.DEFAULT_CHARSET);
     }
 
     public BinaryBody binaryBody(final byte[] buf) {

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/BasicTextBody.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/BasicTextBody.java?rev=1482289&r1=1482288&r2=1482289&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/BasicTextBody.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/BasicTextBody.java Tue May 14 10:43:35 2013
@@ -26,9 +26,9 @@ import java.io.InputStreamReader;
 import java.io.Reader;
 import java.nio.charset.Charset;
 
+import org.apache.james.mime4j.Charsets;
 import org.apache.james.mime4j.dom.SingleBody;
 import org.apache.james.mime4j.dom.TextBody;
-import org.apache.james.mime4j.util.CharsetUtil;
 
 class BasicTextBody extends TextBody {
 
@@ -49,7 +49,7 @@ class BasicTextBody extends TextBody {
     @Override
     public Reader getReader() throws IOException {
         return new InputStreamReader(getInputStream(),
-                this.charset != null ? this.charset : CharsetUtil.DEFAULT_CHARSET);
+                this.charset != null ? this.charset : Charsets.DEFAULT_CHARSET);
     }
 
     @Override

Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/StringBody.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/StringBody.java?rev=1482289&r1=1482288&r2=1482289&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/StringBody.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/StringBody.java Tue May 14 10:43:35 2013
@@ -25,9 +25,9 @@ import java.io.Reader;
 import java.io.StringReader;
 import java.nio.charset.Charset;
 
+import org.apache.james.mime4j.Charsets;
 import org.apache.james.mime4j.dom.SingleBody;
 import org.apache.james.mime4j.dom.TextBody;
-import org.apache.james.mime4j.util.CharsetUtil;
 
 class StringBody extends TextBody {
 
@@ -53,7 +53,7 @@ class StringBody extends TextBody {
     @Override
     public InputStream getInputStream() throws IOException {
         return new StringInputStream(this.content,
-                this.charset != null ? this.charset : CharsetUtil.DEFAULT_CHARSET, 2048);
+                this.charset != null ? this.charset : Charsets.DEFAULT_CHARSET, 2048);
     }
 
     @Override

Modified: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/ExampleMessagesRoundtripTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/ExampleMessagesRoundtripTest.java?rev=1482289&r1=1482288&r2=1482289&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/ExampleMessagesRoundtripTest.java (original)
+++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/ExampleMessagesRoundtripTest.java Tue May 14 10:43:35 2013
@@ -30,13 +30,14 @@ import java.net.URL;
 import junit.framework.TestSuite;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.james.mime4j.Charsets;
 import org.apache.james.mime4j.ExampleMessageTestCase;
 import org.apache.james.mime4j.ExampleMessageTestCaseFactory;
 import org.apache.james.mime4j.ExampleMessageTestSuiteBuilder;
 import org.apache.james.mime4j.message.DefaultMessageBuilder;
 import org.apache.james.mime4j.message.DefaultMessageWriter;
 import org.apache.james.mime4j.stream.MimeConfig;
-import org.apache.james.mime4j.util.CharsetUtil;
+import org.apache.james.mime4j.util.ContentUtil;
 import org.junit.Assert;
 import org.junit.runner.RunWith;
 import org.junit.runners.AllTests;
@@ -82,14 +83,14 @@ public class ExampleMessagesRoundtripTes
         ByteArrayOutputStream outstream = new ByteArrayOutputStream();
         msgwriter.writeMessage(inputMessage, outstream);
 
-        String result = new String(outstream.toByteArray(), CharsetUtil.ISO_8859_1.name());
+        String result = ContentUtil.toString(outstream.toByteArray(), Charsets.ISO_8859_1);
 
         URL outFile = new URL(getResourceBase() + ".out");
         try {
             String expected;
             InputStream contentstream = outFile.openStream();
             try {
-                expected = IOUtils.toString(contentstream, CharsetUtil.ISO_8859_1.name());
+                expected = IOUtils.toString(contentstream, Charsets.ISO_8859_1.name());
             } finally {
                 contentstream.close();
             }
@@ -99,7 +100,7 @@ public class ExampleMessagesRoundtripTes
             File expectedFileTemplate = new File(getFilenameBase() + ".out.expected");
             FileOutputStream templatestream = new FileOutputStream(expectedFileTemplate);
             try {
-                IOUtils.write(result, templatestream, CharsetUtil.ISO_8859_1.name());
+                IOUtils.write(result, templatestream, Charsets.ISO_8859_1.name());
             } finally {
                 templatestream.close();
             }

Modified: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageParserTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageParserTest.java?rev=1482289&r1=1482288&r2=1482289&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageParserTest.java (original)
+++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageParserTest.java Tue May 14 10:43:35 2013
@@ -30,6 +30,7 @@ import java.util.List;
 import junit.framework.TestSuite;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.james.mime4j.Charsets;
 import org.apache.james.mime4j.ExampleMessageTestCase;
 import org.apache.james.mime4j.ExampleMessageTestCaseFactory;
 import org.apache.james.mime4j.ExampleMessageTestSuiteBuilder;
@@ -38,7 +39,6 @@ import org.apache.james.mime4j.message.D
 import org.apache.james.mime4j.message.MessageImpl;
 import org.apache.james.mime4j.stream.Field;
 import org.apache.james.mime4j.stream.MimeConfig;
-import org.apache.james.mime4j.util.CharsetUtil;
 import org.junit.Assert;
 import org.junit.runner.RunWith;
 import org.junit.runners.AllTests;
@@ -87,7 +87,7 @@ public class MessageParserTest extends E
             String expected;
             InputStream contentstream = decodedFile.openStream();
             try {
-                expected = IOUtils.toString(contentstream, CharsetUtil.ISO_8859_1.name());
+                expected = IOUtils.toString(contentstream, Charsets.ISO_8859_1.name());
             } finally {
                 contentstream.close();
             }
@@ -97,7 +97,7 @@ public class MessageParserTest extends E
             File expectedFileTemplate = new File(getFilenameBase() + "_decoded.xml.expected");
             FileOutputStream templatestream = new FileOutputStream(expectedFileTemplate);
             try {
-                IOUtils.write(result, templatestream, CharsetUtil.ISO_8859_1.name());
+                IOUtils.write(result, templatestream, Charsets.ISO_8859_1.name());
             } finally {
                 templatestream.close();
             }
@@ -167,7 +167,7 @@ public class MessageParserTest extends E
             if (b instanceof TextBody) {
                 String charset = e.getCharset();
                 if (charset == null) {
-                    charset = CharsetUtil.ISO_8859_1.name();
+                    charset = Charsets.ISO_8859_1.name();
                 }
 
                 String result = IOUtils.toString(((TextBody) b).getReader());

Modified: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/message/StringInputStreamTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/message/StringInputStreamTest.java?rev=1482289&r1=1482288&r2=1482289&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/message/StringInputStreamTest.java (original)
+++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/message/StringInputStreamTest.java Tue May 14 10:43:35 2013
@@ -19,16 +19,18 @@
 
 package org.apache.james.mime4j.message;
 
-import org.apache.james.mime4j.util.CharsetUtil;
-import org.junit.Assert;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
-import org.junit.Test;
 
 import java.io.IOException;
 import java.io.InputStream;
 import java.security.SecureRandom;
 
+import org.apache.james.mime4j.Charsets;
+import org.apache.james.mime4j.util.ContentUtil;
+import org.junit.Assert;
+import org.junit.Test;
+
 public class StringInputStreamTest {
 
     private static final String SWISS_GERMAN_HELLO = "Gr\374ezi_z\344m\344";
@@ -45,8 +47,8 @@ public class StringInputStreamTest {
     }
 
     private static void singleByteReadTest(final String testString) throws IOException {
-        byte[] bytes = testString.getBytes(CharsetUtil.UTF_8.name());
-        InputStream in = new StringInputStream(testString, CharsetUtil.UTF_8);
+        byte[] bytes = ContentUtil.toByteArray(testString, Charsets.UTF_8);
+        InputStream in = new StringInputStream(testString, Charsets.UTF_8);
         for (byte b : bytes) {
             int read = in.read();
             assertTrue(read >= 0);
@@ -59,8 +61,8 @@ public class StringInputStreamTest {
 
     private static void bufferedReadTest(final String testString) throws IOException {
         SecureRandom rnd = new SecureRandom();
-        byte[] expected = testString.getBytes(CharsetUtil.UTF_8.name());
-        InputStream in = new StringInputStream(testString, CharsetUtil.UTF_8);
+        byte[] expected = ContentUtil.toByteArray(testString, Charsets.UTF_8);
+        InputStream in = new StringInputStream(testString, Charsets.UTF_8);
         byte[] buffer = new byte[128];
         int offset = 0;
         while (true) {
@@ -106,7 +108,7 @@ public class StringInputStreamTest {
 
     @Test
     public void testReadZero() throws Exception {
-        InputStream r = new StringInputStream("test", CharsetUtil.UTF_8);
+        InputStream r = new StringInputStream("test", Charsets.UTF_8);
         byte[] bytes = new byte[30];
         Assert.assertEquals(0, r.read(bytes, 0, 0));
         r.close();
@@ -114,7 +116,7 @@ public class StringInputStreamTest {
 
     @Test
     public void testSkip() throws Exception {
-        InputStream r = new StringInputStream("test", CharsetUtil.UTF_8);
+        InputStream r = new StringInputStream("test", Charsets.UTF_8);
         r.skip(1);
         r.skip(2);
         Assert.assertEquals('t', r.read());
@@ -125,7 +127,7 @@ public class StringInputStreamTest {
 
     @Test
     public void testMarkReset() throws Exception {
-        InputStream r = new StringInputStream("test", CharsetUtil.UTF_8);
+        InputStream r = new StringInputStream("test", Charsets.UTF_8);
         r.skip(2);
         r.mark(0);
         Assert.assertEquals('s', r.read());

Modified: james/mime4j/trunk/storage/src/main/java/org/apache/james/mime4j/storage/StorageBodyFactory.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/storage/src/main/java/org/apache/james/mime4j/storage/StorageBodyFactory.java?rev=1482289&r1=1482288&r2=1482289&view=diff
==============================================================================
--- james/mime4j/trunk/storage/src/main/java/org/apache/james/mime4j/storage/StorageBodyFactory.java (original)
+++ james/mime4j/trunk/storage/src/main/java/org/apache/james/mime4j/storage/StorageBodyFactory.java Tue May 14 10:43:35 2013
@@ -23,6 +23,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.nio.charset.Charset;
 
+import org.apache.james.mime4j.Charsets;
 import org.apache.james.mime4j.codec.DecodeMonitor;
 import org.apache.james.mime4j.dom.BinaryBody;
 import org.apache.james.mime4j.dom.Disposable;
@@ -36,7 +37,7 @@ import org.apache.james.mime4j.util.Char
  */
 public class StorageBodyFactory implements BodyFactory {
 
-    private static final Charset FALLBACK_CHARSET = CharsetUtil.DEFAULT_CHARSET;
+    private static final Charset FALLBACK_CHARSET = Charsets.DEFAULT_CHARSET;
 
     private final StorageProvider storageProvider;
     private final DecodeMonitor monitor;
@@ -136,8 +137,7 @@ public class StorageBodyFactory implemen
             throw new IllegalArgumentException();
 
         Storage storage = storageProvider.store(is);
-        return new StorageTextBody(new MultiReferenceStorage(storage),
-                CharsetUtil.DEFAULT_CHARSET);
+        return new StorageTextBody(new MultiReferenceStorage(storage), Charsets.DEFAULT_CHARSET);
     }
 
     /**
@@ -194,8 +194,7 @@ public class StorageBodyFactory implemen
         if (storage == null)
             throw new IllegalArgumentException();
 
-        return new StorageTextBody(new MultiReferenceStorage(storage),
-                CharsetUtil.DEFAULT_CHARSET);
+        return new StorageTextBody(new MultiReferenceStorage(storage), Charsets.DEFAULT_CHARSET);
     }
 
     /**
@@ -250,7 +249,7 @@ public class StorageBodyFactory implemen
         if (text == null)
             throw new IllegalArgumentException();
 
-        return new StringTextBody(text, CharsetUtil.DEFAULT_CHARSET);
+        return new StringTextBody(text, Charsets.DEFAULT_CHARSET);
     }
 
     /**

Modified: james/mime4j/trunk/storage/src/test/java/org/apache/james/mime4j/storage/SingleBodyCopyTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/storage/src/test/java/org/apache/james/mime4j/storage/SingleBodyCopyTest.java?rev=1482289&r1=1482288&r2=1482289&view=diff
==============================================================================
--- james/mime4j/trunk/storage/src/test/java/org/apache/james/mime4j/storage/SingleBodyCopyTest.java (original)
+++ james/mime4j/trunk/storage/src/test/java/org/apache/james/mime4j/storage/SingleBodyCopyTest.java Tue May 14 10:43:35 2013
@@ -19,15 +19,15 @@
 
 package org.apache.james.mime4j.storage;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+import org.apache.james.mime4j.Charsets;
 import org.apache.james.mime4j.dom.SingleBody;
 import org.apache.james.mime4j.message.MessageImpl;
-import org.apache.james.mime4j.util.CharsetUtil;
 import org.junit.Assert;
 import org.junit.Test;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-
 public class SingleBodyCopyTest {
 
     @Test
@@ -46,14 +46,13 @@ public class SingleBodyCopyTest {
                 .store(new ByteArrayInputStream("test".getBytes()));
         MultiReferenceStorage multiReferenceStorage = new MultiReferenceStorage(
                 storage);
-        SingleBody body = new StorageTextBody(multiReferenceStorage,
-                CharsetUtil.US_ASCII);
+        SingleBody body = new StorageTextBody(multiReferenceStorage, Charsets.US_ASCII);
         copyTest(body);
     }
 
     @Test
     public void testCopyStringTextBody() throws Exception {
-        SingleBody body = new StringTextBody("test", CharsetUtil.US_ASCII);
+        SingleBody body = new StringTextBody("test", Charsets.US_ASCII);
         copyTest(body);
     }
 
@@ -73,8 +72,7 @@ public class SingleBodyCopyTest {
                 .store(new ByteArrayInputStream("test".getBytes()));
         MultiReferenceStorage multiReferenceStorage = new MultiReferenceStorage(
                 storage);
-        SingleBody body = new StorageTextBody(multiReferenceStorage,
-                CharsetUtil.US_ASCII);
+        SingleBody body = new StorageTextBody(multiReferenceStorage, Charsets.US_ASCII);
         disposeTest(body, storage);
     }
 



Mime
View raw message