Return-Path: X-Original-To: apmail-hc-commits-archive@www.apache.org Delivered-To: apmail-hc-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id F3565172FB for ; Tue, 11 Nov 2014 20:28:59 +0000 (UTC) Received: (qmail 7470 invoked by uid 500); 11 Nov 2014 20:28:59 -0000 Delivered-To: apmail-hc-commits-archive@hc.apache.org Received: (qmail 7429 invoked by uid 500); 11 Nov 2014 20:28:59 -0000 Mailing-List: contact commits-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list commits@hc.apache.org Received: (qmail 7420 invoked by uid 99); 11 Nov 2014 20:28:59 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Nov 2014 20:28:59 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Nov 2014 20:28:58 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id F08222388A3B for ; Tue, 11 Nov 2014 20:28:06 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1638361 - in /httpcomponents/httpcore/trunk/httpcore/src: main/java/org/apache/http/entity/ContentType.java test/java/org/apache/http/entity/TestContentType.java Date: Tue, 11 Nov 2014 20:28:06 -0000 To: commits@hc.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20141111202806.F08222388A3B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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());