More reckless refactoring and code style tweaks -- mostly adding braces around condit...
[zxing.git] / android / src / com / google / zxing / client / android / AndroidHttpClient.java
index e32503d..b136879 100644 (file)
@@ -20,7 +20,6 @@ import android.util.Log;
 import org.apache.http.Header;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpEntityEnclosingRequest;
-import org.apache.http.HttpException;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpMessage;
 import org.apache.http.HttpRequest;
@@ -71,7 +70,7 @@ import java.util.zip.GZIPOutputStream;
 public final class AndroidHttpClient implements HttpClient {
 
   // Gzip of data shorter than this probably won't be worthwhile
-  public static final long DEFAULT_SYNC_MIN_GZIP_BYTES = 256;
+  private static final long DEFAULT_SYNC_MIN_GZIP_BYTES = 256;
 
   private static final String TAG = "AndroidHttpClient";
 
@@ -212,7 +211,9 @@ public final class AndroidHttpClient implements HttpClient {
     if (contentEncoding == null) {
       return responseStream;
     }
-    if (contentEncoding.contains("gzip")) responseStream = new GZIPInputStream(responseStream);
+    if (contentEncoding.contains("gzip")) {
+      responseStream = new GZIPInputStream(responseStream);
+    }
     return responseStream;
   }
 
@@ -281,15 +282,18 @@ public final class AndroidHttpClient implements HttpClient {
    * @param data The bytes to compress
    * @return Entity holding the data
    */
-  public static AbstractHttpEntity getCompressedEntity(byte data[]) throws IOException {
+  public static AbstractHttpEntity getCompressedEntity(byte[] data) throws IOException {
     AbstractHttpEntity entity;
     if (data.length < getMinGzipSize()) {
       entity = new ByteArrayEntity(data);
     } else {
       ByteArrayOutputStream arr = new ByteArrayOutputStream();
       OutputStream zipper = new GZIPOutputStream(arr);
-      zipper.write(data);
-      zipper.close();
+      try {
+        zipper.write(data);
+      } finally {
+        zipper.close();
+      }
       entity = new ByteArrayEntity(arr.toByteArray());
       entity.setContentEncoding("gzip");
     }
@@ -300,7 +304,7 @@ public final class AndroidHttpClient implements HttpClient {
    * Retrieves the minimum size for compressing data.
    * Shorter data will not be compressed.
    */
-  public static long getMinGzipSize() {
+  private static long getMinGzipSize() {
     return DEFAULT_SYNC_MIN_GZIP_BYTES;
   }
 
@@ -309,7 +313,7 @@ public final class AndroidHttpClient implements HttpClient {
   /**
    * Logging tag and level.
    */
-  private static class LoggingConfiguration {
+  private static final class LoggingConfiguration {
 
     private final String tag;
     private final int level;
@@ -367,9 +371,9 @@ public final class AndroidHttpClient implements HttpClient {
   /**
    * Logs cURL commands equivalent to requests.
    */
-  private class CurlLogger implements HttpRequestInterceptor {
+  private final class CurlLogger implements HttpRequestInterceptor {
     public void process(HttpRequest request, HttpContext context)
-        throws HttpException, IOException {
+        throws IOException {
       LoggingConfiguration configuration = curlConfiguration;
       if (configuration != null
           && configuration.isLoggable()
@@ -414,7 +418,7 @@ public final class AndroidHttpClient implements HttpClient {
         HttpEntity entity = entityRequest.getEntity();
         if (entity != null && entity.isRepeatable()) {
           if (entity.getContentLength() < 1024) {
-            ByteArrayOutputStream stream = new ByteArrayOutputStream();
+            OutputStream stream = new ByteArrayOutputStream();
             entity.writeTo(stream);
             String entityString = stream.toString();
             // TODO: Check the content type, too.