Support no-content (204) requests in BasicNetwork.

When we get an empty response for say, a 204, we create a 0 byte
response and pass it on to the NetworkResponse.  Implementers
of Request can then return appropriate Responses.  The behavior
before this change results in an NPE because we attempt to
getContentLength() bytes from a null entity..

Change-Id: Ia5f92ffd99b8f3e88cc92dc50ba43c4721d83e79
Signed-off-by: Ray Colline <rayc@google.com>
diff --git a/src/com/android/volley/toolbox/BasicNetwork.java b/src/com/android/volley/toolbox/BasicNetwork.java
index b3c7d45..3c1d5c7 100644
--- a/src/com/android/volley/toolbox/BasicNetwork.java
+++ b/src/com/android/volley/toolbox/BasicNetwork.java
@@ -101,7 +101,15 @@
                             request.getCacheEntry().data, responseHeaders, true);
                 }
 
-                responseContents = entityToBytes(httpResponse.getEntity());
+                // Some responses such as 204s do not have content.  We must check.
+                if (httpResponse.getEntity() != null) {
+                  responseContents = entityToBytes(httpResponse.getEntity());
+                } else {
+                  // Add 0 byte response as a way of honestly representing a
+                  // no-content request.
+                  responseContents = new byte[0];
+                }
+
                 // if the request is slow, log it.
                 long requestLifetime = SystemClock.elapsedRealtime() - requestStart;
                 logSlowRequests(requestLifetime, request, responseContents, statusLine);