hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r997906 - in /httpcomponents/httpcore/trunk/httpcore/src: main/java/org/apache/http/util/EntityUtils.java test/java/org/apache/http/util/TestEntityUtils.java
Date Thu, 16 Sep 2010 20:11:27 GMT
Author: olegk
Date: Thu Sep 16 20:11:26 2010
New Revision: 997906

URL: http://svn.apache.org/viewvc?rev=997906&view=rev
Log:
HTTPCORE-233: EntityUtils#toString() and EntityUtils#toByteArray() to return null if HttpEntity#getContent()
is null

Modified:
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/EntityUtils.java
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/util/TestEntityUtils.java

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/EntityUtils.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/EntityUtils.java?rev=997906&r1=997905&r2=997906&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/EntityUtils.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/EntityUtils.java
Thu Sep 16 20:11:26 2010
@@ -73,7 +73,8 @@ public final class EntityUtils {
      * Read the contents of an entity and return it as a byte array.
      *
      * @param entity
-     * @return byte array containing the entity content. May be empty; never null.
+     * @return byte array containing the entity content. May be null if
+     *   {@link HttpEntity#getContent()} is null.
      * @throws IOException if an error occurs reading the input stream
      * @throws IllegalArgumentException if entity is null or if content length > Integer.MAX_VALUE
      */
@@ -83,7 +84,7 @@ public final class EntityUtils {
         }
         InputStream instream = entity.getContent();
         if (instream == null) {
-            return new byte[] {};
+            return null;
         }
         if (entity.getContentLength() > Integer.MAX_VALUE) {
             throw new IllegalArgumentException("HTTP entity too large to be buffered in memory");
@@ -161,7 +162,8 @@ public final class EntityUtils {
      *
      * @param entity must not be null
      * @param defaultCharset character set to be applied if none found in the entity
-     * @return the entity content as a String
+     * @return the entity content as a String. May be null if
+     *   {@link HttpEntity#getContent()} is null.
      * @throws ParseException if header elements cannot be parsed
      * @throws IllegalArgumentException if entity is null or if content length > Integer.MAX_VALUE
      * @throws IOException if an error occurs reading the input stream
@@ -173,7 +175,7 @@ public final class EntityUtils {
         }
         InputStream instream = entity.getContent();
         if (instream == null) {
-            return "";
+            return null;
         }
         if (entity.getContentLength() > Integer.MAX_VALUE) {
             throw new IllegalArgumentException("HTTP entity too large to be buffered in memory");

Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/util/TestEntityUtils.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/util/TestEntityUtils.java?rev=997906&r1=997905&r2=997906&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/util/TestEntityUtils.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/util/TestEntityUtils.java
Thu Sep 16 20:11:26 2010
@@ -58,8 +58,7 @@ public class TestEntityUtils extends Tes
     public void testEmptyContentToByteArray() throws Exception {
         NullHttpEntity httpentity = new NullHttpEntity();
         byte[] bytes = EntityUtils.toByteArray(httpentity);
-        assertNotNull(bytes);
-        assertEquals(0, bytes.length);
+        assertNull(bytes);
     }
 
     public void testMaxIntContentToByteArray() throws Exception {
@@ -162,8 +161,7 @@ public class TestEntityUtils extends Tes
     public void testEmptyContentToString() throws Exception {
         NullHttpEntity httpentity = new NullHttpEntity();
         String s = EntityUtils.toString(httpentity);
-        assertNotNull(s);
-        assertEquals("", s);
+        assertNull(s);
     }
 
     public void testMaxIntContentToString() throws Exception {



Mime
View raw message