Author: olegk
Date: Tue Nov 11 20:28:06 2014
New Revision: 1638361
URL: http://svn.apache.org/r1638361
Log:
Code cleanup in ContentType class
Modified:
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentType.java
httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestContentType.java
Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentType.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentType.java?rev=1638361&r1=1638360&r2=1638361&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentType.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentType.java
Tue Nov 11 20:28:06 2014
@@ -37,7 +37,6 @@ import org.apache.http.Header;
import org.apache.http.HeaderElement;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
-import org.apache.http.ParseException;
import org.apache.http.annotation.Immutable;
import org.apache.http.message.BasicHeaderValueFormatter;
import org.apache.http.message.BasicHeaderValueParser;
@@ -235,7 +234,6 @@ public final class ContentType implement
*
* @param s text
* @return content type
- * @throws ParseException if the given text does not represent a valid
* {@code Content-Type} value.
* @throws UnsupportedCharsetException Thrown when the named charset is not available
in
* this instance of the Java virtual machine
@@ -260,13 +258,11 @@ public final class ContentType implement
*
* @param entity HTTP entity
* @return content type
- * @throws ParseException if the given text does not represent a valid
* {@code Content-Type} value.
* @throws UnsupportedCharsetException Thrown when the named charset is not available
in
* this instance of the Java virtual machine
*/
- public static ContentType get(
- final HttpEntity entity) throws ParseException, UnsupportedCharsetException {
+ public static ContentType get(final HttpEntity entity) throws UnsupportedCharsetException
{
if (entity == null) {
return null;
}
@@ -296,13 +292,9 @@ public final class ContentType implement
}
final Header header = entity.getContentType();
if (header != null) {
- try {
- final HeaderElement[] elements = header.getElements();
- if (elements.length > 0) {
- return create(elements[0], false);
- }
- } catch (ParseException ex) {
- return null;
+ final HeaderElement[] elements = header.getElements();
+ if (elements.length > 0) {
+ return create(elements[0], false);
}
}
return null;
@@ -314,13 +306,11 @@ public final class ContentType implement
*
* @param entity HTTP entity
* @return content type
- * @throws ParseException if the given text does not represent a valid
* {@code Content-Type} value.
* @throws UnsupportedCharsetException Thrown when the named charset is not available
in
* this instance of the Java virtual machine
*/
- public static ContentType getOrDefault(
- final HttpEntity entity) throws ParseException, UnsupportedCharsetException {
+ public static ContentType getOrDefault(final HttpEntity entity) throws UnsupportedCharsetException
{
final ContentType contentType = get(entity);
return contentType != null ? contentType : DEFAULT_TEXT;
}
@@ -334,8 +324,7 @@ public final class ContentType implement
*
* @since 4.4
*/
- public static ContentType getLenientOrDefault(
- final HttpEntity entity) throws ParseException, UnsupportedCharsetException {
+ public static ContentType getLenientOrDefault(final HttpEntity entity) throws UnsupportedCharsetException
{
final ContentType contentType = get(entity);
return contentType != null ? contentType : DEFAULT_TEXT;
}
@@ -351,17 +340,4 @@ public final class ContentType implement
return create(this.getMimeType(), charset);
}
- /**
- * Creates a new instance with this MIME type and the given Charset name.
- *
- * @param charset name
- * @return a new instance with this MIME type and the given Charset name.
- * @throws UnsupportedCharsetException Thrown when the named charset is not available
in
- * this instance of the Java virtual machine
- * @since 4.3
- */
- public ContentType withCharset(final String charset) {
- return create(this.getMimeType(), charset);
- }
-
}
Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestContentType.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestContentType.java?rev=1638361&r1=1638360&r2=1638361&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestContentType.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestContentType.java
Tue Nov 11 20:28:06 2014
@@ -30,6 +30,7 @@ package org.apache.http.entity;
import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;
+import org.apache.http.Consts;
import org.apache.http.Header;
import org.apache.http.message.BasicHeader;
import org.junit.Assert;
@@ -67,7 +68,7 @@ public class TestContentType {
Assert.assertEquals("text/plain", contentType.getMimeType());
Assert.assertEquals("US-ASCII", contentType.getCharset().name());
Assert.assertEquals("text/plain; charset=US-ASCII", contentType.toString());
- contentType = contentType.withCharset("UTF-8");
+ contentType = contentType.withCharset(Consts.UTF_8);
Assert.assertEquals("text/plain", contentType.getMimeType());
Assert.assertEquals("UTF-8", contentType.getCharset().name());
Assert.assertEquals("text/plain; charset=UTF-8", contentType.toString());
|