@@ -0,0 +1,2850 @@
+package com.antew.redditinpictures.library.network;%0A%0Aimport java.io.BufferedInputStream;%0Aimport java.io.BufferedOutputStream;%0Aimport java.io.BufferedReader;%0Aimport java.io.IOException;%0Aimport java.io.InputStreamReader;%0Aimport java.net.HttpURLConnection;%0Aimport java.net.URL;%0A%0Aimport android.os.Build;%0A%0Aimport com.antew.redditinpictures.library.logging.Log;%0A%0Apublic class SynchronousNetworkApi %7B%0A    private static final int IO_BUFFER_SIZE = 8 * 1024;%0A    public static final String TAG = SynchronousNetworkApi.class.getSimpleName();%0A%0A    /**%0A     * Download the input URL and return the output as a String%0A     * %0A     * @param urlString%0A     *            The URL to download%0A     * @return A String with the downloaded contents%0A     * @throws IOException%0A     */%0A    public static String downloadUrl(String urlString) %7B%0A        disableConnectionReuseIfNecessary();%0A        HttpURLConnection urlConnection = null;%0A        BufferedOutputStream out = null;%0A        BufferedInputStream in = null;%0A%0A        try %7B%0A            final URL url = new URL(urlString);%0A            urlConnection = (HttpURLConnection) url.openConnection();%0A            urlConnection.setReadTimeout(10000);%0A            urlConnection.setConnectTimeout(15000);%0A            urlConnection.setRequestMethod(%22GET%22);%0A            urlConnection.connect();%0A            if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK) %7B%0A%0A                in = new BufferedInputStream(urlConnection.getInputStream(), IO_BUFFER_SIZE);%0A%0A                BufferedReader reader = new BufferedReader(new InputStreamReader(in, %22UTF-8%22));%0A                StringBuilder builder = new StringBuilder(in.available());%0A                String line;%0A                while ((line = reader.readLine()) != null)%0A                    builder.append(line);%0A%0A                Log.i(%22Url = %22 + urlString, %22 result = %22 + builder.toString());%0A                return builder.toString();%0A            %7D%0A        %7D catch (final IOException e) %7B%0A            Log.e(TAG, %22Error in downloadUrl - %22 + e);%0A        %7D finally %7B%0A            if (urlConnection != null) %7B%0A                urlConnection.disconnect();%0A            %7D%0A            try %7B%0A                if (out != null) %7B%0A                    out.close();%0A                %7D%0A                if (in != null) %7B%0A                    in.close();%0A                %7D%0A            %7D catch (final IOException e) %7B%0A            %7D%0A        %7D%0A        return null;%0A    %7D%0A%0A    /**%0A     * Workaround for bug pre-Froyo, see here for more info:%0A     * http://android-developers.blogspot.com/2011/09/androids-http-clients.html%0A     */%0A    public static void disableConnectionReuseIfNecessary() %7B%0A        // HTTP connection reuse which was buggy pre-froyo%0A        if (Build.VERSION.SDK_INT %3C Build.VERSION_CODES.FROYO) %7B%0A            System.setProperty(%22http.keepAlive%22, %22false%22);%0A        %7D%0A    %7D%0A%0A%7D%0A

Create a central class for synchronous network calls.