james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r895034 - in /james/mime4j/branches/cycleclean/core/src: main/java/org/apache/james/mime4j/field/ main/java/org/apache/james/mime4j/field/impl/ main/java/org/apache/james/mime4j/message/impl/ test/java/org/apache/james/mime4j/field/ test/ja...
Date Fri, 01 Jan 2010 16:57:40 GMT
Author: bago
Date: Fri Jan  1 16:57:39 2010
New Revision: 895034

URL: http://svn.apache.org/viewvc?rev=895034&view=rev
Log:
Changed Field "ByteSequence getRaw" to a more conservative "writeTo(OutputStream)". This remove
ByteSequence from mime4j-DOM dependencies. Moved FieldParser interface to field.impl (this
will need more care, later, while refactoring the parser package) (MIME4J-156)

Added:
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/FieldParser.java
  (contents, props changed)
      - copied, changed from r894746, james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/FieldParser.java
Removed:
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/FieldParser.java
Modified:
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/Field.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/AbstractField.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/AddressListFieldImpl.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/ContentDispositionFieldImpl.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/ContentTransferEncodingFieldImpl.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/ContentTypeFieldImpl.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/DateTimeFieldImpl.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/DefaultFieldParser.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/DelegatingFieldParser.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/Fields.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/MailboxFieldImpl.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/MailboxListFieldImpl.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/UnstructuredFieldImpl.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/MessageWriter.java
    james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/field/FieldsTest.java
    james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MessageParserTest.java

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/Field.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/Field.java?rev=895034&r1=895033&r2=895034&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/Field.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/Field.java
Fri Jan  1 16:57:39 2010
@@ -19,7 +19,8 @@
 
 package org.apache.james.mime4j.field;
 
-import org.apache.james.mime4j.util.ByteSequence;
+import java.io.IOException;
+import java.io.OutputStream;
 
 /**
  * Abstract MIME field.
@@ -41,10 +42,10 @@
     String getBody();
 
     /**
-     * Gets the original raw field bytes.
-     * 
-     * @return the original raw field bytes.
+     * Writes the original raw field bytes to an output stream.
+     * The output is folded, the last CRLF is not included.
+     * @throws IOException
      */
-    ByteSequence getRaw();
+    void writeTo(OutputStream out) throws IOException;
     
 }

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/AbstractField.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/AbstractField.java?rev=895034&r1=895033&r2=895034&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/AbstractField.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/AbstractField.java
Fri Jan  1 16:57:39 2010
@@ -19,6 +19,9 @@
 
 package org.apache.james.mime4j.field.impl;
 
+import java.io.IOException;
+import java.io.OutputStream;
+
 import org.apache.james.mime4j.field.ParseException;
 import org.apache.james.mime4j.field.ParsedField;
 import org.apache.james.mime4j.util.ByteSequence;
@@ -49,12 +52,10 @@
     }
     
     /**
-     * Gets the original raw field string.
-     * 
-     * @return the original raw field string.
+     * @see org.apache.james.mime4j.field.Field#writeTo(java.io.OutputStream)
      */
-    public ByteSequence getRaw() {
-        return raw;
+    public void writeTo(OutputStream out) throws IOException {
+        out.write(raw.toByteArray());
     }
     
     /**

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/AddressListFieldImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/AddressListFieldImpl.java?rev=895034&r1=895033&r2=895034&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/AddressListFieldImpl.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/AddressListFieldImpl.java
Fri Jan  1 16:57:39 2010
@@ -21,7 +21,6 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.james.mime4j.field.FieldParser;
 import org.apache.james.mime4j.field.address.AddressList;
 import org.apache.james.mime4j.field.address.parser.AddressBuilder;
 import org.apache.james.mime4j.field.address.parser.ParseException;

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/ContentDispositionFieldImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/ContentDispositionFieldImpl.java?rev=895034&r1=895033&r2=895034&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/ContentDispositionFieldImpl.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/ContentDispositionFieldImpl.java
Fri Jan  1 16:57:39 2010
@@ -29,7 +29,6 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.james.mime4j.field.FieldParser;
 import org.apache.james.mime4j.field.contentdisposition.parser.ContentDispositionParser;
 import org.apache.james.mime4j.field.contentdisposition.parser.ParseException;
 import org.apache.james.mime4j.field.contentdisposition.parser.TokenMgrError;

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/ContentTransferEncodingFieldImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/ContentTransferEncodingFieldImpl.java?rev=895034&r1=895033&r2=895034&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/ContentTransferEncodingFieldImpl.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/ContentTransferEncodingFieldImpl.java
Fri Jan  1 16:57:39 2010
@@ -20,7 +20,6 @@
 package org.apache.james.mime4j.field.impl;
 
 import org.apache.james.mime4j.field.ContentTransferEncodingField;
-import org.apache.james.mime4j.field.FieldParser;
 import org.apache.james.mime4j.util.ByteSequence;
 import org.apache.james.mime4j.util.MimeUtil;
 

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/ContentTypeFieldImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/ContentTypeFieldImpl.java?rev=895034&r1=895033&r2=895034&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/ContentTypeFieldImpl.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/ContentTypeFieldImpl.java
Fri Jan  1 16:57:39 2010
@@ -28,7 +28,6 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.james.mime4j.field.ContentTypeField;
-import org.apache.james.mime4j.field.FieldParser;
 import org.apache.james.mime4j.field.contenttype.parser.ContentTypeParser;
 import org.apache.james.mime4j.field.contenttype.parser.ParseException;
 import org.apache.james.mime4j.field.contenttype.parser.TokenMgrError;

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/DateTimeFieldImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/DateTimeFieldImpl.java?rev=895034&r1=895033&r2=895034&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/DateTimeFieldImpl.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/DateTimeFieldImpl.java
Fri Jan  1 16:57:39 2010
@@ -24,7 +24,6 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.james.mime4j.field.FieldParser;
 import org.apache.james.mime4j.field.datetime.parser.DateTimeParser;
 import org.apache.james.mime4j.field.datetime.parser.ParseException;
 import org.apache.james.mime4j.field.datetime.parser.TokenMgrError;

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/DefaultFieldParser.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/DefaultFieldParser.java?rev=895034&r1=895033&r2=895034&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/DefaultFieldParser.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/DefaultFieldParser.java
Fri Jan  1 16:57:39 2010
@@ -26,7 +26,6 @@
 import org.apache.james.mime4j.field.impl.ContentTypeFieldImpl;
 import org.apache.james.mime4j.field.impl.DateTimeFieldImpl;
 import org.apache.james.mime4j.field.FieldName;
-import org.apache.james.mime4j.field.FieldParser;
 import org.apache.james.mime4j.field.impl.MailboxFieldImpl;
 import org.apache.james.mime4j.field.impl.MailboxListFieldImpl;
 import org.apache.james.mime4j.field.ParsedField;

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/DelegatingFieldParser.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/DelegatingFieldParser.java?rev=895034&r1=895033&r2=895034&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/DelegatingFieldParser.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/DelegatingFieldParser.java
Fri Jan  1 16:57:39 2010
@@ -22,7 +22,6 @@
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.james.mime4j.field.FieldParser;
 import org.apache.james.mime4j.field.ParsedField;
 import org.apache.james.mime4j.field.impl.UnstructuredFieldImpl;
 import org.apache.james.mime4j.util.ByteSequence;

Copied: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/FieldParser.java
(from r894746, james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/FieldParser.java)
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/FieldParser.java?p2=james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/FieldParser.java&p1=james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/FieldParser.java&r1=894746&r2=895034&rev=895034&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/FieldParser.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/FieldParser.java
Fri Jan  1 16:57:39 2010
@@ -17,8 +17,9 @@
  * under the License.                                           *
  ****************************************************************/
 
-package org.apache.james.mime4j.field;
+package org.apache.james.mime4j.field.impl;
 
+import org.apache.james.mime4j.field.ParsedField;
 import org.apache.james.mime4j.util.ByteSequence;
 
 public interface FieldParser<T extends ParsedField> {

Propchange: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/FieldParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/Fields.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/Fields.java?rev=895034&r1=895033&r2=895034&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/Fields.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/Fields.java
Fri Jan  1 16:57:39 2010
@@ -35,7 +35,6 @@
 import org.apache.james.mime4j.field.impl.DateTimeFieldImpl;
 import org.apache.james.mime4j.field.Field;
 import org.apache.james.mime4j.field.FieldName;
-import org.apache.james.mime4j.field.FieldParser;
 import org.apache.james.mime4j.field.impl.MailboxFieldImpl;
 import org.apache.james.mime4j.field.impl.MailboxListFieldImpl;
 import org.apache.james.mime4j.field.ParsedField;

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/MailboxFieldImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/MailboxFieldImpl.java?rev=895034&r1=895033&r2=895034&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/MailboxFieldImpl.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/MailboxFieldImpl.java
Fri Jan  1 16:57:39 2010
@@ -21,7 +21,6 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.james.mime4j.field.FieldParser;
 import org.apache.james.mime4j.field.address.Mailbox;
 import org.apache.james.mime4j.field.address.MailboxList;
 import org.apache.james.mime4j.field.address.parser.AddressBuilder;

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/MailboxListFieldImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/MailboxListFieldImpl.java?rev=895034&r1=895033&r2=895034&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/MailboxListFieldImpl.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/MailboxListFieldImpl.java
Fri Jan  1 16:57:39 2010
@@ -21,7 +21,6 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.james.mime4j.field.FieldParser;
 import org.apache.james.mime4j.field.address.MailboxList;
 import org.apache.james.mime4j.field.address.parser.AddressBuilder;
 import org.apache.james.mime4j.field.address.parser.ParseException;

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/UnstructuredFieldImpl.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/UnstructuredFieldImpl.java?rev=895034&r1=895033&r2=895034&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/UnstructuredFieldImpl.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/impl/UnstructuredFieldImpl.java
Fri Jan  1 16:57:39 2010
@@ -20,7 +20,6 @@
 package org.apache.james.mime4j.field.impl;
 
 import org.apache.james.mime4j.codec.DecoderUtil;
-import org.apache.james.mime4j.field.FieldParser;
 import org.apache.james.mime4j.util.ByteSequence;
 
 /**

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/MessageWriter.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/MessageWriter.java?rev=895034&r1=895033&r2=895034&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/MessageWriter.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/MessageWriter.java
Fri Jan  1 16:57:39 2010
@@ -177,7 +177,7 @@
      */
     public void writeHeader(Header header, OutputStream out) throws IOException {
         for (Field field : header) {
-            writeBytes(field.getRaw(), out);
+            field.writeTo(out);
             out.write(CRLF);
         }
 

Modified: james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/field/FieldsTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/field/FieldsTest.java?rev=895034&r1=895033&r2=895034&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/field/FieldsTest.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/field/FieldsTest.java
Fri Jan  1 16:57:39 2010
@@ -19,6 +19,8 @@
 
 package org.apache.james.mime4j.field;
 
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.util.Arrays;
 import java.util.Date;
 import java.util.HashMap;
@@ -32,7 +34,7 @@
 import org.apache.james.mime4j.field.address.parser.AddressBuilder;
 import org.apache.james.mime4j.field.address.parser.GroupImpl;
 import org.apache.james.mime4j.field.impl.Fields;
-import org.apache.james.mime4j.util.ByteSequence;
+import org.apache.james.mime4j.util.ByteArrayBuffer;
 import org.apache.james.mime4j.util.ContentUtil;
 import org.apache.james.mime4j.util.MimeUtil;
 
@@ -47,7 +49,7 @@
         String expectedRaw = "Content-Type: multipart/mixed;\r\n "
                 + "boundary=\"-=Part.0.37877968dd4f6595.11eccf0271c"
                 + ".2dce5678cbc933d5=-\"";
-        assertEquals(expectedRaw, decode(field.getRaw()));
+        assertEquals(expectedRaw, decode(field));
     }
 
     public void testContentTypeStringParameters() throws Exception {
@@ -61,7 +63,7 @@
         String expectedRaw = "Content-Type: multipart/mixed;\r\n "
                 + "boundary=\"-=Part.0.37877968dd4f6595.11eccf0271c"
                 + ".2dce5678cbc933d5=-\"";
-        assertEquals(expectedRaw, decode(field.getRaw()));
+        assertEquals(expectedRaw, decode(field));
     }
 
     public void testContentTypeStringParametersWithSpaces() throws Exception {
@@ -73,7 +75,7 @@
 
         String expectedRaw = "Content-Type: multipart/mixed; "
                 + "param=\"value with space chars\"";
-        assertEquals(expectedRaw, decode(field.getRaw()));
+        assertEquals(expectedRaw, decode(field));
     }
 
     public void testContentTypeStringNullParameters() throws Exception {
@@ -81,7 +83,7 @@
         assertTrue(field.isValidField());
 
         String expectedRaw = "Content-Type: text/plain";
-        assertEquals(expectedRaw, decode(field.getRaw()));
+        assertEquals(expectedRaw, decode(field));
     }
 
     public void testInvalidContentType() throws Exception {
@@ -99,7 +101,7 @@
         assertTrue(field.isValidField());
 
         assertEquals("Content-Transfer-Encoding: base64",
-                decode(field.getRaw()));
+                decode(field));
     }
 
     public void testContentDispositionString() throws Exception {
@@ -111,7 +113,7 @@
         String expectedRaw = "Content-Disposition: inline; filename="
                 + "\"testing 1 2.dat\"; size=12345;\r\n creation-date="
                 + "\"Thu, 1 Jan 1970 00:00:00 +0000\"";
-        assertEquals(expectedRaw, decode(field.getRaw()));
+        assertEquals(expectedRaw, decode(field));
     }
 
     public void testContentDispositionStringParameters() throws Exception {
@@ -124,7 +126,7 @@
 
         String expectedRaw = "Content-Disposition: attachment; "
                 + "creation-date=\"Thu, 1 Jan 1970 00:00:00\r\n +0000\"";
-        assertEquals(expectedRaw, decode(field.getRaw()));
+        assertEquals(expectedRaw, decode(field));
 
         assertEquals(new Date(0), field.getCreationDate());
     }
@@ -135,7 +137,7 @@
         assertTrue(field.isValidField());
 
         String expectedRaw = "Content-Disposition: inline";
-        assertEquals(expectedRaw, decode(field.getRaw()));
+        assertEquals(expectedRaw, decode(field));
     }
 
     public void testContentDispositionFilename() throws Exception {
@@ -185,7 +187,7 @@
         assertTrue(field.isValidField());
 
         assertEquals("Date: Thu, 1 Jan 1970 00:00:00 +0000", decode(field
-                .getRaw()));
+                ));
         assertEquals(new Date(0), field.getDate());
 
         field = Fields.date("Resent-Date", new Date(0), TimeZone
@@ -193,7 +195,7 @@
         assertTrue(field.isValidField());
 
         assertEquals("Resent-Date: Thu, 1 Jan 1970 01:00:00 +0100",
-                decode(field.getRaw()));
+                decode(field));
         assertEquals(new Date(0), field.getDate());
     }
 
@@ -204,38 +206,38 @@
         assertTrue(field.isValidField());
 
         assertEquals("Date: Wed, 16 Jul 2008 17:12:33 +0200", decode(field
-                .getRaw()));
+                ));
         assertEquals(new Date(millis), field.getDate());
     }
 
     public void testMessageId() throws Exception {
         Field messageId = Fields.messageId("acme.org");
 
-        String raw = ContentUtil.decode(messageId.getRaw());
+        String raw = decode(messageId);
         assertTrue(raw.startsWith("Message-ID: <Mime4j."));
         assertTrue(raw.endsWith("@acme.org>"));
     }
 
     public void testSubject() throws Exception {
-        assertEquals("Subject: ", decode(Fields.subject("").getRaw()));
-        assertEquals("Subject: test", decode(Fields.subject("test").getRaw()));
+        assertEquals("Subject: ", decode(Fields.subject("")));
+        assertEquals("Subject: test", decode(Fields.subject("test")));
         assertEquals("Subject: =?ISO-8859-1?Q?Sm=F8rebr=F8d?=", decode(Fields
-                .subject("Sm\370rebr\370d").getRaw()));
+                .subject("Sm\370rebr\370d")));
 
         String seventyEight = "12345678901234567890123456789012345678901234567890123456789012345678";
         assertEquals("Subject:\r\n " + seventyEight, decode(Fields.subject(
-                seventyEight).getRaw()));
+                seventyEight)));
 
         String seventyNine = seventyEight + "9";
         String expected = "Subject: =?US-ASCII?Q?1234567890123456789012345678901234?="
                 + "\r\n =?US-ASCII?Q?56789012345678901234567890123456789?=";
-        assertEquals(expected, decode(Fields.subject(seventyNine).getRaw()));
+        assertEquals(expected, decode(Fields.subject(seventyNine)));
     }
 
     public void testSender() throws Exception {
         MailboxField field = Fields.sender(AddressBuilder
                 .parseMailbox("JD <john.doe@acme.org>"));
-        assertEquals("Sender: JD <john.doe@acme.org>", decode(field.getRaw()));
+        assertEquals("Sender: JD <john.doe@acme.org>", decode(field));
     }
 
     public void testFrom() throws Exception {
@@ -243,15 +245,15 @@
         Mailbox mailbox2 = AddressBuilder.parseMailbox("Mary Smith <mary@example.net>");
 
         MailboxListField field = Fields.from(mailbox1);
-        assertEquals("From: JD <john.doe@acme.org>", decode(field.getRaw()));
+        assertEquals("From: JD <john.doe@acme.org>", decode(field));
 
         field = Fields.from(mailbox1, mailbox2);
         assertEquals("From: JD <john.doe@acme.org>, "
-                + "Mary Smith <mary@example.net>", decode(field.getRaw()));
+                + "Mary Smith <mary@example.net>", decode(field));
 
         field = Fields.from(Arrays.asList(mailbox1, mailbox2));
         assertEquals("From: JD <john.doe@acme.org>, "
-                + "Mary Smith <mary@example.net>", decode(field.getRaw()));
+                + "Mary Smith <mary@example.net>", decode(field));
     }
 
     public void testTo() throws Exception {
@@ -262,17 +264,17 @@
 
         AddressListField field = Fields.to(group);
         assertEquals("To: The Does: JD <john.doe@acme.org>, "
-                + "jane.doe@example.org;", decode(field.getRaw()));
+                + "jane.doe@example.org;", decode(field));
 
         field = Fields.to(group, mailbox3);
         assertEquals("To: The Does: JD <john.doe@acme.org>, "
                 + "jane.doe@example.org;, Mary Smith\r\n <mary@example.net>",
-                decode(field.getRaw()));
+                decode(field));
 
         field = Fields.to(Arrays.asList(group, mailbox3));
         assertEquals("To: The Does: JD <john.doe@acme.org>, "
                 + "jane.doe@example.org;, Mary Smith\r\n <mary@example.net>",
-                decode(field.getRaw()));
+                decode(field));
     }
 
     public void testCc() throws Exception {
@@ -283,17 +285,17 @@
 
         AddressListField field = Fields.cc(group);
         assertEquals("Cc: The Does: JD <john.doe@acme.org>, "
-                + "jane.doe@example.org;", decode(field.getRaw()));
+                + "jane.doe@example.org;", decode(field));
 
         field = Fields.cc(group, mailbox3);
         assertEquals("Cc: The Does: JD <john.doe@acme.org>, "
                 + "jane.doe@example.org;, Mary Smith\r\n <mary@example.net>",
-                decode(field.getRaw()));
+                decode(field));
 
         field = Fields.cc(Arrays.asList(group, mailbox3));
         assertEquals("Cc: The Does: JD <john.doe@acme.org>, "
                 + "jane.doe@example.org;, Mary Smith\r\n <mary@example.net>",
-                decode(field.getRaw()));
+                decode(field));
     }
 
     public void testBcc() throws Exception {
@@ -304,17 +306,17 @@
 
         AddressListField field = Fields.bcc(group);
         assertEquals("Bcc: The Does: JD <john.doe@acme.org>, "
-                + "jane.doe@example.org;", decode(field.getRaw()));
+                + "jane.doe@example.org;", decode(field));
 
         field = Fields.bcc(group, mailbox3);
         assertEquals("Bcc: The Does: JD <john.doe@acme.org>, "
                 + "jane.doe@example.org;, Mary Smith\r\n <mary@example.net>",
-                decode(field.getRaw()));
+                decode(field));
 
         field = Fields.bcc(Arrays.asList(group, mailbox3));
         assertEquals("Bcc: The Does: JD <john.doe@acme.org>, "
                 + "jane.doe@example.org;, Mary Smith\r\n <mary@example.net>",
-                decode(field.getRaw()));
+                decode(field));
     }
 
     public void testReplyTo() throws Exception {
@@ -325,24 +327,24 @@
 
         AddressListField field = Fields.replyTo(group);
         assertEquals("Reply-To: The Does: JD <john.doe@acme.org>, "
-                + "jane.doe@example.org;", decode(field.getRaw()));
+                + "jane.doe@example.org;", decode(field));
 
         field = Fields.replyTo(group, mailbox3);
         assertEquals("Reply-To: The Does: JD <john.doe@acme.org>, "
                 + "jane.doe@example.org;, Mary\r\n Smith <mary@example.net>",
-                decode(field.getRaw()));
+                decode(field));
 
         field = Fields.replyTo(Arrays.asList(group, mailbox3));
         assertEquals("Reply-To: The Does: JD <john.doe@acme.org>, "
                 + "jane.doe@example.org;, Mary\r\n Smith <mary@example.net>",
-                decode(field.getRaw()));
+                decode(field));
     }
 
     public void testMailbox() throws Exception {
         MailboxField field = Fields.mailbox("Resent-Sender", AddressBuilder
                 .parseMailbox("JD <john.doe@acme.org>"));
         assertEquals("Resent-Sender: JD <john.doe@acme.org>", decode(field
-                .getRaw()));
+                ));
     }
 
     public void testMailboxList() throws Exception {
@@ -352,7 +354,7 @@
         MailboxListField field = Fields.mailboxList("Resent-From", Arrays
                 .asList(mailbox1, mailbox2));
         assertEquals("Resent-From: JD <john.doe@acme.org>, "
-                + "Mary Smith <mary@example.net>", decode(field.getRaw()));
+                + "Mary Smith <mary@example.net>", decode(field));
     }
 
     public void testAddressList() throws Exception {
@@ -365,7 +367,7 @@
                 group, mailbox3));
         assertEquals("Resent-To: The Does: JD <john.doe@acme.org>, "
                 + "jane.doe@example.org;, Mary\r\n Smith <mary@example.net>",
-                decode(field.getRaw()));
+                decode(field));
     }
 
     public void testInvalidFieldName() throws Exception {
@@ -376,8 +378,15 @@
         }
     }
 
-    private String decode(ByteSequence byteSequence) {
-        return ContentUtil.decode(byteSequence);
+    public static String decode(Field f) {
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        try {
+            f.writeTo(bos);
+        } catch (IOException e) {
+            throw new RuntimeException("bytearrayoutputstream doens't throw this exception");
+        }
+        ByteArrayBuffer bab = new ByteArrayBuffer(bos.toByteArray(), true);
+        return ContentUtil.decode(bab);
     }
 
 }

Modified: james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MessageParserTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MessageParserTest.java?rev=895034&r1=895033&r2=895034&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MessageParserTest.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/test/java/org/apache/james/mime4j/message/MessageParserTest.java
Fri Jan  1 16:57:39 2010
@@ -19,14 +19,6 @@
 
 package org.apache.james.mime4j.message;
 
-import org.apache.commons.io.IOUtils;
-import org.apache.james.mime4j.field.Field;
-import org.apache.james.mime4j.message.impl.MessageImpl;
-import org.apache.james.mime4j.parser.MimeEntityConfig;
-import org.apache.james.mime4j.util.ContentUtil;
-import org.apache.james.mime4j.util.CharsetUtil;
-import org.apache.log4j.BasicConfigurator;
-
 import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.FileInputStream;
@@ -44,6 +36,14 @@
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
+import org.apache.commons.io.IOUtils;
+import org.apache.james.mime4j.field.Field;
+import org.apache.james.mime4j.field.FieldsTest;
+import org.apache.james.mime4j.message.impl.MessageImpl;
+import org.apache.james.mime4j.parser.MimeEntityConfig;
+import org.apache.james.mime4j.util.CharsetUtil;
+import org.apache.log4j.BasicConfigurator;
+
 public class MessageParserTest extends TestCase {
     private File file = null;
 
@@ -154,7 +154,7 @@
         sb.append("<header>\r\n");
         for (Field field : e.getHeader().getFields()) {
             sb.append("<field>\r\n"
-                    + escape(ContentUtil.decode(field.getRaw()))
+                    + escape(FieldsTest.decode(field))
                     + "</field>\r\n");
         }
         sb.append("</header>\r\n");



Mime
View raw message