package org.ccci.gto.android.common.util;

import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;

public final class IOUtils {
    private static final int DEFAULT_BUFFER_SIZE = 4096;
    private static final int EOF = -1;

    public static final void closeQuietly(final Closeable handle) {
        if (handle != null) {
            try {
                handle.close();
            } catch (final IOException e) {
                // suppress the error
            }
        }
    }

    public static final void closeQuietly(final HttpURLConnection conn) {
        if (conn != null) {
            conn.disconnect();
        }
    }

    public static final long copy(final InputStream in, OutputStream out) throws IOException {
        byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
        long count = 0;
        int n = 0;
        while (EOF != (n = in.read(buffer))) {
            out.write(buffer, 0, n);
            count += n;
        }
        return count;
    }

    public static final String readString(final InputStream in) throws IOException {
        final BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"), DEFAULT_BUFFER_SIZE);
        final StringBuilder out = new StringBuilder();
        final char[] buffer = new char[DEFAULT_BUFFER_SIZE];
        int n;
        while (EOF != (n = reader.read(buffer, 0, buffer.length))) {
            out.append(buffer, 0, n);
        }
        return out.toString();
    }
}

@@ -277,16 +277,114 @@
 Utils %7B%0A
+    // 640K should be enough for anybody -Bill Gates%0A    // (Bill Gates never actually said this)%0A
     priv
@@ -430,12 +430,18 @@
 E = 
+6
 40
-96
+ * 1024
 ;%0A  
@@ -488,38 +488,32 @@
   public static 
-final 
 void closeQuietl
@@ -751,22 +751,16 @@
  static 
-final 
 void clo
@@ -895,22 +895,16 @@
  static 
-final 
 long cop
@@ -1229,22 +1229,16 @@
  static 
-final 
 String r

raise the default buffer size