hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r750894 - in /httpcomponents/httpclient/trunk: ./ httpmime/src/main/java/org/apache/http/entity/mime/ httpmime/src/main/java/org/apache/http/entity/mime/content/ httpmime/src/test/java/org/apache/http/entity/mime/
Date Fri, 06 Mar 2009 13:50:51 GMT
Author: olegk
Date: Fri Mar  6 13:50:50 2009
New Revision: 750894

URL: http://svn.apache.org/viewvc?rev=750894&view=rev
Log:
Upgraded mime4j to version 0.6

Added:
    httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/MinimalField.java
  (with props)
Modified:
    httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/FormBodyPart.java
    httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/HttpMultipart.java
    httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/MIME.java
    httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/MultipartEntity.java
    httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/UnexpectedMimeException.java
    httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/content/AbstractContentBody.java
    httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/content/FileBody.java
    httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/content/InputStreamBody.java
    httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/content/StringBody.java
    httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartForm.java
    httpcomponents/httpclient/trunk/pom.xml

Modified: httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/FormBodyPart.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/FormBodyPart.java?rev=750894&r1=750893&r2=750894&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/FormBodyPart.java
(original)
+++ httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/FormBodyPart.java
Fri Mar  6 13:50:50 2009
@@ -32,9 +32,7 @@
 package org.apache.http.entity.mime;
 
 import org.apache.http.entity.mime.content.ContentBody;
-import org.apache.james.mime4j.MimeException;
 import org.apache.james.mime4j.descriptor.ContentDescriptor;
-import org.apache.james.mime4j.field.Field;
 import org.apache.james.mime4j.message.BodyPart;
 import org.apache.james.mime4j.message.Header;
 
@@ -75,8 +73,7 @@
     
     protected void generateContentDisp(final ContentBody body) {
         StringBuilder buffer = new StringBuilder();
-        buffer.append(MIME.CONTENT_DISPOSITION);
-        buffer.append(": form-data; name=\"");
+        buffer.append("form-data; name=\"");
         buffer.append(getName());
         buffer.append("\"");
         if (body.getFilename() != null) {
@@ -84,40 +81,29 @@
             buffer.append(body.getFilename());
             buffer.append("\"");
         }
-        addField(buffer.toString());
+        addField(MIME.CONTENT_DISPOSITION, buffer.toString());
     }
     
     protected void generateContentType(final ContentDescriptor desc) {
         if (desc.getMimeType() != null) {
             StringBuilder buffer = new StringBuilder();
-            buffer.append(MIME.CONTENT_TYPE);
-            buffer.append(": ");
             buffer.append(desc.getMimeType());
             if (desc.getCharset() != null) {
                 buffer.append("; charset=");
                 buffer.append(desc.getCharset());
             }
-            addField(buffer.toString());
+            addField(MIME.CONTENT_TYPE, buffer.toString());
         }
     }
     
     protected void generateTransferEncoding(final ContentDescriptor desc) {
         if (desc.getTransferEncoding() != null) {
-            StringBuilder buffer = new StringBuilder();
-            buffer.append(MIME.CONTENT_TRANSFER_ENC);
-            buffer.append(": ");
-            buffer.append(desc.getTransferEncoding());
-            addField(buffer.toString());
+            addField(MIME.CONTENT_TRANSFER_ENC, desc.getTransferEncoding());
         }
     }
 
-    private void addField(final String s) {
-        try {
-            getHeader().addField(Field.parse(s));
-        } catch (MimeException ex) {
-            // Should never happen
-            throw new UnexpectedMimeException(ex);
-        }
+    private void addField(final String name, final String value) {
+        getHeader().addField(new MinimalField(name, value));
     }
     
 }

Modified: httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/HttpMultipart.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/HttpMultipart.java?rev=750894&r1=750893&r2=750894&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/HttpMultipart.java
(original)
+++ httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/HttpMultipart.java
Fri Mar  6 13:50:50 2009
@@ -31,25 +31,28 @@
 
 package org.apache.http.entity.mime;
 
-import java.io.BufferedWriter;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
-import java.io.OutputStreamWriter;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
 import java.nio.charset.Charset;
 import java.util.List;
 
 import org.apache.http.entity.mime.content.ContentBody;
 import org.apache.http.protocol.HTTP;
-import org.apache.james.mime4j.MimeException;
 import org.apache.james.mime4j.field.ContentTypeField;
-import org.apache.james.mime4j.field.Field;
+import org.apache.james.mime4j.field.FieldName;
 import org.apache.james.mime4j.message.Body;
 import org.apache.james.mime4j.message.BodyPart;
 import org.apache.james.mime4j.message.Entity;
+import org.apache.james.mime4j.message.Header;
+import org.apache.james.mime4j.message.MessageWriter;
 import org.apache.james.mime4j.message.Multipart;
+import org.apache.james.mime4j.parser.Field;
+import org.apache.james.mime4j.util.ByteArrayBuffer;
+import org.apache.james.mime4j.util.ByteSequence;
 import org.apache.james.mime4j.util.CharsetUtil;
-import org.apache.james.mime4j.util.MessageUtils;
 
 /**
  * An extension of the mime4j standard {@link Multipart} class, which is
@@ -61,6 +64,28 @@
  */
 public class HttpMultipart extends Multipart {
 
+    private static ByteArrayBuffer encode(Charset charset, String string) {
+        ByteBuffer encoded = charset.encode(CharBuffer.wrap(string));
+        ByteArrayBuffer bab = new ByteArrayBuffer(encoded.remaining());
+        bab.append(encoded.array(), encoded.position(), encoded.remaining());
+        return bab;
+    }
+    
+    private static void writeBytes(ByteArrayBuffer b, OutputStream out) throws IOException
{
+        out.write(b.buffer(), 0, b.length());
+    }
+    
+    private static void writeBytes(ByteSequence b, OutputStream out) throws IOException {
+        if (b instanceof ByteArrayBuffer) {
+            writeBytes((ByteArrayBuffer) b, out);
+        } else {
+            out.write(b.toByteArray());
+        }
+    }
+    
+    private static final ByteArrayBuffer CR_LF = encode(MIME.DEFAULT_CHARSET, "\r\n");
+    private static final ByteArrayBuffer TWO_DASHES = encode(MIME.DEFAULT_CHARSET, "--");
+    
     private HttpMultipartMode mode;
     
     public HttpMultipart(final String subType) {
@@ -79,7 +104,7 @@
     protected Charset getCharset() {
         Entity e = getParent();
         ContentTypeField cField = (ContentTypeField) e.getHeader().getField(
-                Field.CONTENT_TYPE);
+                FieldName.CONTENT_TYPE);
         Charset charset = null;
         
         switch (this.mode) {
@@ -100,7 +125,7 @@
     protected String getBoundary() {
         Entity e = getParent();
         ContentTypeField cField = (ContentTypeField) e.getHeader().getField(
-                Field.CONTENT_TYPE);
+                FieldName.CONTENT_TYPE);
         return cField.getBoundary();
     }
 
@@ -109,44 +134,49 @@
         final OutputStream out, 
         boolean writeContent) throws IOException {
         
-        List<?> bodyParts = getBodyParts();
+        List<BodyPart> bodyParts = getBodyParts();
         Charset charset = getCharset();
-        String boundary = getBoundary();
 
-        BufferedWriter writer = new BufferedWriter(
-                new OutputStreamWriter(out, charset),
-                8192);
+        ByteArrayBuffer boundary = encode(charset, getBoundary());
         
         switch (mode) {
         case STRICT:
             String preamble = getPreamble();
             if (preamble != null && preamble.length() != 0) {
-                writer.write(preamble);
-                writer.write("\r\n");
+                ByteArrayBuffer b = encode(charset, preamble);
+                writeBytes(b, out);
+                writeBytes(CR_LF, out);
             }
 
             for (int i = 0; i < bodyParts.size(); i++) {
-                writer.write("--");
-                writer.write(boundary);
-                writer.write("\r\n");
-                writer.flush();
-                BodyPart part = (BodyPart) bodyParts.get(i);
-                part.getHeader().writeTo(out, MessageUtils.STRICT_IGNORE);
+                writeBytes(TWO_DASHES, out);
+                writeBytes(boundary, out);
+                writeBytes(CR_LF, out);
+
+                BodyPart part = bodyParts.get(i);
+                Header header = part.getHeader();
+                
+                List<Field> fields = header.getFields();
+                for (Field field: fields) {
+                    writeBytes(field.getRaw(), out);
+                    writeBytes(CR_LF, out);
+                }
+                writeBytes(CR_LF, out);
                 if (writeContent) {
-                    part.getBody().writeTo(out, MessageUtils.STRICT_IGNORE);
+                    MessageWriter.DEFAULT.writeBody(part.getBody(), out);
                 }
-                writer.write("\r\n");
+                writeBytes(CR_LF, out);
             }
-
-            writer.write("--");
-            writer.write(boundary);
-            writer.write("--\r\n");
+            writeBytes(TWO_DASHES, out);
+            writeBytes(boundary, out);
+            writeBytes(TWO_DASHES, out);
+            writeBytes(CR_LF, out);
             String epilogue = getEpilogue();
             if (epilogue != null && epilogue.length() != 0) {
-                writer.write(epilogue);
-                writer.write("\r\n");
+                ByteArrayBuffer b = encode(charset, epilogue);
+                writeBytes(b, out);
+                writeBytes(CR_LF, out);
             }
-            writer.flush();
             break;
         case BROWSER_COMPATIBLE:
 
@@ -155,28 +185,30 @@
             // (3) Use content charset
             
             for (int i = 0; i < bodyParts.size(); i++) {
-                writer.write("--");
-                writer.write(boundary);
-                writer.write("\r\n");
-                writer.flush();
+                writeBytes(TWO_DASHES, out);
+                writeBytes(boundary, out);
+                writeBytes(CR_LF, out);
                 BodyPart part = (BodyPart) bodyParts.get(i);
                 
                 Field cd = part.getHeader().getField(MIME.CONTENT_DISPOSITION);
-                writer.write(cd.toString());
-                writer.write("\r\n");
-                writer.write("\r\n");
-                writer.flush();
+                
+                StringBuilder s = new StringBuilder();
+                s.append(cd.getName());
+                s.append(": ");
+                s.append(cd.getBody());
+                writeBytes(encode(charset, s.toString()), out);
+                writeBytes(CR_LF, out);
+                writeBytes(CR_LF, out);
                 if (writeContent) {
-                    part.getBody().writeTo(out, MessageUtils.LENIENT);
+                    MessageWriter.DEFAULT.writeBody(part.getBody(), out);
                 }
-                
-                writer.write("\r\n");
+                writeBytes(CR_LF, out);
             }
 
-            writer.write("--");
-            writer.write(boundary);
-            writer.write("--\r\n");
-            writer.flush();
+            writeBytes(TWO_DASHES, out);
+            writeBytes(boundary, out);
+            writeBytes(TWO_DASHES, out);
+            writeBytes(CR_LF, out);
             break;
         }
     }
@@ -192,15 +224,6 @@
         doWriteTo(this.mode, out, true);
     }
 
-    @Override
-    public void writeTo(final OutputStream out, int mode) throws IOException, MimeException
{
-        if (mode == MessageUtils.LENIENT) {
-            doWriteTo(HttpMultipartMode.BROWSER_COMPATIBLE, out, true);
-        } else {
-            doWriteTo(HttpMultipartMode.STRICT, out, true);
-        }
-    }
-
     /**
      * Determines the total length of the multipart content (content length of 
      * individual parts plus that of extra elements required to delimit the parts 

Modified: httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/MIME.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/MIME.java?rev=750894&r1=750893&r2=750894&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/MIME.java
(original)
+++ httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/MIME.java
Fri Mar  6 13:50:50 2009
@@ -33,7 +33,7 @@
 
 import java.nio.charset.Charset;
 
-import org.apache.james.mime4j.field.Field;
+import org.apache.james.mime4j.field.FieldName;
 import org.apache.james.mime4j.util.CharsetUtil;
 
 /**
@@ -42,8 +42,8 @@
  */
 public final class MIME {
 
-    public static final String CONTENT_TYPE          = Field.CONTENT_TYPE;
-    public static final String CONTENT_TRANSFER_ENC  = Field.CONTENT_TRANSFER_ENCODING;
+    public static final String CONTENT_TYPE          = FieldName.CONTENT_TYPE;
+    public static final String CONTENT_TRANSFER_ENC  = FieldName.CONTENT_TRANSFER_ENCODING;
     public static final String CONTENT_DISPOSITION   = "Content-Disposition";
  
     public static final String ENC_8BIT              = "8bit";

Added: httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/MinimalField.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/MinimalField.java?rev=750894&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/MinimalField.java
(added)
+++ httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/MinimalField.java
Fri Mar  6 13:50:50 2009
@@ -0,0 +1,81 @@
+/*
+ * $HeadURL:$
+ * $Revision:$
+ * $Date:$
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.entity.mime;
+
+import org.apache.james.mime4j.parser.Field;
+import org.apache.james.mime4j.util.ByteSequence;
+import org.apache.james.mime4j.util.ContentUtil;
+
+/**
+ * Minimal implementation of {@link Field}.
+ *
+ * @since 4.0
+ */
+public class MinimalField implements Field {
+
+    private final String name;
+    private final String value;
+
+    private ByteSequence raw;
+    
+    MinimalField(final String name, final String value) {
+        super();
+        this.name = name;
+        this.value = value;
+        this.raw = null;
+    }
+    
+    public String getName() {
+        return this.name;
+    }
+
+    public String getBody() {
+        return this.value;
+    }
+
+    public ByteSequence getRaw() {
+        if (this.raw == null) {
+            this.raw = ContentUtil.encode(toString());
+        }
+        return this.raw;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder buffer = new StringBuilder();
+        buffer.append(this.name);
+        buffer.append(": ");
+        buffer.append(this.value);
+        return buffer.toString();
+    }
+    
+}

Propchange: httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/MinimalField.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/MultipartEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/MultipartEntity.java?rev=750894&r1=750893&r2=750894&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/MultipartEntity.java
(original)
+++ httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/MultipartEntity.java
Fri Mar  6 13:50:50 2009
@@ -44,8 +44,7 @@
 import org.apache.http.entity.mime.content.ContentBody;
 import org.apache.http.message.BasicHeader;
 import org.apache.http.protocol.HTTP;
-import org.apache.james.mime4j.MimeException;
-import org.apache.james.mime4j.field.Field;
+import org.apache.james.mime4j.field.Fields;
 import org.apache.james.mime4j.message.Message;
 
 /**
@@ -91,7 +90,7 @@
             mode = HttpMultipartMode.STRICT;
         }
         this.multipart.setMode(mode);
-        addField("Content-Type: " + this.contentType.getValue());
+        this.message.getHeader().addField(Fields.contentType(this.contentType.getValue()));
     }
 
     public MultipartEntity(final HttpMultipartMode mode) {
@@ -181,13 +180,4 @@
         this.multipart.writeTo(outstream);
     }
 
-    private void addField(final String s) {
-        try {
-            this.message.getHeader().addField(Field.parse(s));
-        } catch (MimeException ex) {
-            // Should never happen
-            throw new UnexpectedMimeException(ex);
-        }
-    }
-    
 }

Modified: httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/UnexpectedMimeException.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/UnexpectedMimeException.java?rev=750894&r1=750893&r2=750894&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/UnexpectedMimeException.java
(original)
+++ httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/UnexpectedMimeException.java
Fri Mar  6 13:50:50 2009
@@ -33,9 +33,11 @@
 import org.apache.james.mime4j.MimeException;
 
 /**
+ * @deprecated no longer used.
  *
  * @since 4.0
  */
+@Deprecated
 public class UnexpectedMimeException extends RuntimeException {
 
     private static final long serialVersionUID = 1316818299528463579L;

Modified: httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/content/AbstractContentBody.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/content/AbstractContentBody.java?rev=750894&r1=750893&r2=750894&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/content/AbstractContentBody.java
(original)
+++ httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/content/AbstractContentBody.java
Fri Mar  6 13:50:50 2009
@@ -34,18 +34,21 @@
 import java.util.Collections;
 import java.util.Map;
 
-import org.apache.james.mime4j.message.AbstractBody;
+import org.apache.james.mime4j.message.Entity;
+import org.apache.james.mime4j.message.SingleBody;
 
 /**
  *
  * @since 4.0
  */
-public abstract class AbstractContentBody extends AbstractBody implements ContentBody {
+public abstract class AbstractContentBody extends SingleBody implements ContentBody {
 
     private final String mimeType;
     private final String mediaType;
     private final String subType;
     
+    private Entity parent = null;
+
     public AbstractContentBody(final String mimeType) {
         super();
         if (mimeType == null) {
@@ -61,7 +64,15 @@
             this.subType = null;
         }
     }
-    
+
+    public Entity getParent() {
+        return this.parent;
+    }
+
+    public void setParent(final Entity parent) {
+        this.parent = parent;
+    }
+
     public String getMimeType() {
         return this.mimeType;
     }
@@ -74,8 +85,11 @@
         return this.subType;
     }
 
-    public Map<?, ?> getContentTypeParameters() {
-        return Collections.EMPTY_MAP;
+    public Map<String, String> getContentTypeParameters() {
+        return Collections.emptyMap();
     }
 
+    public void dispose() {
+    }
+    
 }

Modified: httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/content/FileBody.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/content/FileBody.java?rev=750894&r1=750893&r2=750894&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/content/FileBody.java
(original)
+++ httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/content/FileBody.java
Fri Mar  6 13:50:50 2009
@@ -38,13 +38,12 @@
 import java.io.OutputStream;
 
 import org.apache.http.entity.mime.MIME;
-import org.apache.james.mime4j.message.BinaryBody;
 
 /**
  *
  * @since 4.0
  */
-public class FileBody extends AbstractContentBody implements BinaryBody {
+public class FileBody extends AbstractContentBody {
 
     private final File file;
     
@@ -64,7 +63,15 @@
         return new FileInputStream(this.file);
     }
 
+    /**
+     * @deprecated use {@link #writeTo(OutputStream)}
+     */
+    @Deprecated
     public void writeTo(final OutputStream out, int mode) throws IOException {
+        writeTo(out);
+    }
+
+    public void writeTo(final OutputStream out) throws IOException {
         if (out == null) {
             throw new IllegalArgumentException("Output stream may not be null");
         }
@@ -100,5 +107,5 @@
     public File getFile() {
         return this.file;
     }
-    
+
 }

Modified: httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/content/InputStreamBody.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/content/InputStreamBody.java?rev=750894&r1=750893&r2=750894&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/content/InputStreamBody.java
(original)
+++ httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/content/InputStreamBody.java
Fri Mar  6 13:50:50 2009
@@ -36,13 +36,12 @@
 import java.io.OutputStream;
 
 import org.apache.http.entity.mime.MIME;
-import org.apache.james.mime4j.message.BinaryBody;
 
 /**
  *
  * @since 4.0
  */
-public class InputStreamBody extends AbstractContentBody implements BinaryBody {
+public class InputStreamBody extends AbstractContentBody {
 
     private final InputStream in;
     private final String filename;
@@ -64,7 +63,15 @@
         return this.in;
     }
 
+    /**
+     * @deprecated use {@link #writeTo(OutputStream)}
+     */
+    @Deprecated
     public void writeTo(final OutputStream out, int mode) throws IOException {
+        writeTo(out);
+    }
+
+    public void writeTo(final OutputStream out) throws IOException {
         if (out == null) {
             throw new IllegalArgumentException("Output stream may not be null");
         }

Modified: httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/content/StringBody.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/content/StringBody.java?rev=750894&r1=750893&r2=750894&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/content/StringBody.java
(original)
+++ httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/content/StringBody.java
Fri Mar  6 13:50:50 2009
@@ -43,13 +43,12 @@
 import java.util.Map;
 
 import org.apache.http.entity.mime.MIME;
-import org.apache.james.mime4j.message.TextBody;
 
 /**
  *
  * @since 4.0
  */
-public class StringBody extends AbstractContentBody implements TextBody {
+public class StringBody extends AbstractContentBody {
 
     private final byte[] content;
     private final Charset charset;
@@ -83,7 +82,15 @@
                 this.charset);
     }
 
+    /**
+     * @deprecated use {@link #writeTo(OutputStream)}
+     */
+    @Deprecated
     public void writeTo(final OutputStream out, int mode) throws IOException {
+        writeTo(out);
+    }
+
+    public void writeTo(final OutputStream out) throws IOException {
         if (out == null) {
             throw new IllegalArgumentException("Output stream may not be null");
         }
@@ -105,8 +112,8 @@
     }
 
     @Override
-    public Map<?, ?> getContentTypeParameters() {
-        Map<Object, Object> map = new HashMap<Object, Object>();
+    public Map<String, String> getContentTypeParameters() {
+        Map<String, String> map = new HashMap<String, String>();
         map.put("charset", this.charset.name());
         return map;
     }

Modified: httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartForm.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartForm.java?rev=750894&r1=750893&r2=750894&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartForm.java
(original)
+++ httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartForm.java
Fri Mar  6 13:50:50 2009
@@ -48,7 +48,7 @@
 import org.apache.http.entity.mime.content.FileBody;
 import org.apache.http.entity.mime.content.InputStreamBody;
 import org.apache.http.entity.mime.content.StringBody;
-import org.apache.james.mime4j.field.Field;
+import org.apache.james.mime4j.field.Fields;
 import org.apache.james.mime4j.message.BodyPart;
 import org.apache.james.mime4j.message.Header;
 import org.apache.james.mime4j.message.Message;
@@ -75,25 +75,24 @@
     public void testMultipartFormLowLevel() throws Exception {
         Message message = new Message();
         Header header = new Header();
-        header.addField(
-                Field.parse("Content-Type: multipart/form-data; boundary=foo"));
+        header.addField(Fields.contentType("multipart/form-data; boundary=foo"));
         message.setHeader(header);
         
         HttpMultipart multipart = new HttpMultipart("form-data");
         multipart.setParent(message);
         BodyPart p1 = new BodyPart();
         Header h1 = new Header();
-        h1.addField(Field.parse("Content-Type: text/plain"));
+        h1.addField(Fields.contentType("text/plain"));
         p1.setHeader(h1);
         p1.setBody(new StringBody("this stuff"));
         BodyPart p2 = new BodyPart();
         Header h2 = new Header();
-        h2.addField(Field.parse("Content-Type: text/plain"));
+        h2.addField(Fields.contentType("text/plain"));
         p2.setHeader(h2);
         p2.setBody(new StringBody("that stuff"));
         BodyPart p3 = new BodyPart();
         Header h3 = new Header();
-        h3.addField(Field.parse("Content-Type: text/plain"));
+        h3.addField(Fields.contentType("text/plain"));
         p3.setHeader(h3);
         p3.setBody(new StringBody("all kind of stuff"));
 
@@ -127,8 +126,7 @@
     public void testMultipartFormStringParts() throws Exception {
         Message message = new Message();
         Header header = new Header();
-        header.addField(
-                Field.parse("Content-Type: multipart/form-data; boundary=foo"));
+        header.addField(Fields.contentType("multipart/form-data; boundary=foo"));
         message.setHeader(header);
         
         HttpMultipart multipart = new HttpMultipart("form-data");
@@ -181,8 +179,7 @@
     public void testMultipartFormBinaryParts() throws Exception {
         Message message = new Message();
         Header header = new Header();
-        header.addField(
-                Field.parse("Content-Type: multipart/form-data; boundary=foo"));
+        header.addField(Fields.contentType("multipart/form-data; boundary=foo"));
         message.setHeader(header);
 
         File tmpfile = File.createTempFile("tmp", ".bin");
@@ -236,8 +233,7 @@
     public void testMultipartFormBrowserCompatible() throws Exception {
         Message message = new Message();
         Header header = new Header();
-        header.addField(
-                Field.parse("Content-Type: multipart/form-data; boundary=foo"));
+        header.addField(Fields.contentType("multipart/form-data; boundary=foo"));
         message.setHeader(header);
 
         File tmpfile = File.createTempFile("tmp", ".bin");
@@ -311,8 +307,7 @@
 
         Message message = new Message();
         Header header = new Header();
-        header.addField(
-                Field.parse("Content-Type: multipart/form-data; charset=UTF-8; boundary=foo"));
+        header.addField(Fields.contentType("multipart/form-data; charset=UTF-8; boundary=foo"));
         message.setHeader(header);
 
         File tmpfile = File.createTempFile("tmp", ".bin");
@@ -367,8 +362,7 @@
         
         Message message = new Message();
         Header header = new Header();
-        header.addField(
-                Field.parse("Content-Type: multipart/form-data; boundary=foo"));
+        header.addField(Fields.contentType("multipart/form-data; boundary=foo"));
         message.setHeader(header);
         
         HttpMultipart multipart = new HttpMultipart("form-data");

Modified: httpcomponents/httpclient/trunk/pom.xml
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/pom.xml?rev=750894&r1=750893&r2=750894&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/pom.xml (original)
+++ httpcomponents/httpclient/trunk/pom.xml Fri Mar  6 13:50:50 2009
@@ -75,7 +75,7 @@
     <httpcore.version>4.0</httpcore.version>
     <commons-logging.version>1.1.1</commons-logging.version>
     <commons-codec.version>1.3</commons-codec.version>
-    <mime4j.version>0.5</mime4j.version>
+    <mime4j.version>0.6</mime4j.version>
     <junit.version>3.8.2</junit.version>
   </properties>
 



Mime
View raw message