diff --git a/module-httpmime/src/main/java/org/apache/http/entity/mime/content/AbstractContentBody.java b/module-httpmime/src/main/java/org/apache/http/entity/mime/content/AbstractContentBody.java
new file mode 100644
index 000000000..0d552e379
--- /dev/null
+++ b/module-httpmime/src/main/java/org/apache/http/entity/mime/content/AbstractContentBody.java
@@ -0,0 +1,77 @@
+/*
+ * $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
+ * .
+ *
+ */
+
+package org.apache.http.entity.mime.content;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.apache.james.mime4j.message.AbstractBody;
+
+public abstract class AbstractContentBody extends AbstractBody implements ContentBody {
+
+ private final String mimeType;
+ private final String mediaType;
+ private final String subType;
+
+ public AbstractContentBody(final String mimeType) {
+ super();
+ if (mimeType == null) {
+ throw new IllegalArgumentException("MIME type may not be null");
+ }
+ this.mimeType = mimeType;
+ int i = mimeType.indexOf('/');
+ if (i != -1) {
+ this.mediaType = mimeType.substring(0, i);
+ this.subType = mimeType.substring(i + 1);
+ } else {
+ this.mediaType = mimeType;
+ this.subType = null;
+ }
+ }
+
+ public String getMimeType() {
+ return this.mimeType;
+ }
+
+ public String getMediaType() {
+ return this.mediaType;
+ }
+
+ public String getSubType() {
+ return this.subType;
+ }
+
+ public Map, ?> getContentTypeParameters() {
+ return Collections.EMPTY_MAP;
+ }
+
+}
diff --git a/module-httpmime/src/main/java/org/apache/http/entity/mime/content/FileBody.java b/module-httpmime/src/main/java/org/apache/http/entity/mime/content/FileBody.java
index 3aedbe801..f8ff5d3ca 100644
--- a/module-httpmime/src/main/java/org/apache/http/entity/mime/content/FileBody.java
+++ b/module-httpmime/src/main/java/org/apache/http/entity/mime/content/FileBody.java
@@ -36,25 +36,26 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.util.Collections;
-import java.util.Map;
import org.apache.http.entity.mime.MIME;
-import org.apache.james.mime4j.message.AbstractBody;
import org.apache.james.mime4j.message.BinaryBody;
-public class FileBody extends AbstractBody implements BinaryBody, ContentBody {
+public class FileBody extends AbstractContentBody implements BinaryBody {
private final File file;
- public FileBody(final File file) {
- super();
+ public FileBody(final File file, final String mimeType) {
+ super(mimeType);
if (file == null) {
throw new IllegalArgumentException("File may not be null");
}
this.file = file;
}
+ public FileBody(final File file) {
+ this(file, "application/octet-stream");
+ }
+
public InputStream getInputStream() throws IOException {
return new FileInputStream(this.file);
}
@@ -84,22 +85,6 @@ public class FileBody extends AbstractBody implements BinaryBody, ContentBody {
return null;
}
- public String getMimeType() {
- return "application/octet-stream";
- }
-
- public Map, ?> getContentTypeParameters() {
- return Collections.EMPTY_MAP;
- }
-
- public String getMediaType() {
- return "application";
- }
-
- public String getSubType() {
- return "octet-stream";
- }
-
public long getContentLength() {
return this.file.length();
}
diff --git a/module-httpmime/src/main/java/org/apache/http/entity/mime/content/InputStreamBody.java b/module-httpmime/src/main/java/org/apache/http/entity/mime/content/InputStreamBody.java
index b241c3cd5..4d36416c3 100644
--- a/module-httpmime/src/main/java/org/apache/http/entity/mime/content/InputStreamBody.java
+++ b/module-httpmime/src/main/java/org/apache/http/entity/mime/content/InputStreamBody.java
@@ -34,20 +34,17 @@ package org.apache.http.entity.mime.content;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.util.Collections;
-import java.util.Map;
import org.apache.http.entity.mime.MIME;
-import org.apache.james.mime4j.message.AbstractBody;
import org.apache.james.mime4j.message.BinaryBody;
-public class InputStreamBody extends AbstractBody implements BinaryBody, ContentBody {
+public class InputStreamBody extends AbstractContentBody implements BinaryBody {
private final InputStream in;
private final String filename;
- public InputStreamBody(final InputStream in, final String filename) {
- super();
+ public InputStreamBody(final InputStream in, final String mimeType, final String filename) {
+ super(mimeType);
if (in == null) {
throw new IllegalArgumentException("Input stream may not be null");
}
@@ -55,6 +52,10 @@ public class InputStreamBody extends AbstractBody implements BinaryBody, Content
this.filename = filename;
}
+ public InputStreamBody(final InputStream in, final String filename) {
+ this(in, "application/octet-stream", filename);
+ }
+
public InputStream getInputStream() throws IOException {
return this.in;
}
@@ -83,22 +84,6 @@ public class InputStreamBody extends AbstractBody implements BinaryBody, Content
return null;
}
- public String getMimeType() {
- return "application/octet-stream";
- }
-
- public Map, ?> getContentTypeParameters() {
- return Collections.EMPTY_MAP;
- }
-
- public String getMediaType() {
- return "application";
- }
-
- public String getSubType() {
- return "octet-stream";
- }
-
public long getContentLength() {
return -1;
}
diff --git a/module-httpmime/src/main/java/org/apache/http/entity/mime/content/StringBody.java b/module-httpmime/src/main/java/org/apache/http/entity/mime/content/StringBody.java
index bf4d79bab..32ae77ed8 100644
--- a/module-httpmime/src/main/java/org/apache/http/entity/mime/content/StringBody.java
+++ b/module-httpmime/src/main/java/org/apache/http/entity/mime/content/StringBody.java
@@ -43,16 +43,18 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.http.entity.mime.MIME;
-import org.apache.james.mime4j.message.AbstractBody;
import org.apache.james.mime4j.message.TextBody;
-public class StringBody extends AbstractBody implements TextBody, ContentBody {
+public class StringBody extends AbstractContentBody implements TextBody {
private final byte[] content;
private final Charset charset;
- public StringBody(final String text, Charset charset) throws UnsupportedEncodingException {
- super();
+ public StringBody(
+ final String text,
+ final String mimeType,
+ Charset charset) throws UnsupportedEncodingException {
+ super(mimeType);
if (text == null) {
throw new IllegalArgumentException("Text may not be null");
}
@@ -63,8 +65,12 @@ public class StringBody extends AbstractBody implements TextBody, ContentBody {
this.charset = charset;
}
+ public StringBody(final String text, Charset charset) throws UnsupportedEncodingException {
+ this(text, "text/plain", charset);
+ }
+
public StringBody(final String text) throws UnsupportedEncodingException {
- this(text, null);
+ this(text, "text/plain", null);
}
public Reader getReader() throws IOException {
@@ -94,18 +100,7 @@ public class StringBody extends AbstractBody implements TextBody, ContentBody {
return this.charset.name();
}
- public String getMimeType() {
- return "text/plain";
- }
-
- public String getMediaType() {
- return "text";
- }
-
- public String getSubType() {
- return "plain";
- }
-
+ @Override
public Map, ?> getContentTypeParameters() {
Map