package yuku.alkitab.base.rpc;

import android.util.Log;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import yuku.alkitab.base.ac.FontManagerActivity;

public class SimpleHttpConnection {
	public static final String TAG = SimpleHttpConnection.class.getSimpleName(); 
	
	final URL url;
	HttpURLConnection conn = null;
	InputStream in = null;
	IOException ex = null;
	
	public SimpleHttpConnection(String url) {
		try {
			this.url = new URL(url);
		} catch (MalformedURLException e) {
			throw new RuntimeException(e);
		}
	}
	
	public InputStream load() {
		try {
			conn = (HttpURLConnection) url.openConnection();
			in = new BufferedInputStream(conn.getInputStream());
			return in;
		} catch (IOException e) {
			this.ex = e;
			return null;
		}
	}
	
	public boolean isSameHost() {
		String urlHost = url.getHost();
		String connHost = conn.getURL().getHost();
		Log.d(TAG, "isSameHost? urlHost=" + urlHost + " connHost=" + connHost); //$NON-NLS-1$ //$NON-NLS-2$
		return urlHost.equals(connHost);
	}
	
	public long getContentLength() {
		return conn.getContentLength();
	}
	
	public Exception getException() {
		return ex;
	}
	
	public void close() {
		try {
			if (in != null) in.close();
			if (conn != null) conn.disconnect();
		} catch (IOException e) {
			Log.d(FontManagerActivity.TAG, "close", e); //$NON-NLS-1$
		}
	}
}
@@ -54,44 +54,87 @@
 og;%0A
-%0A
 import 
-java.io.BufferedInputStream;
+yuku.alkitab.base.App;%0Aimport yuku.alkitab.base.ac.FontManagerActivity;%0A
 %0Aimp
@@ -286,58 +286,8 @@
 L;%0A%0A
-import yuku.alkitab.base.ac.FontManagerActivity;%0A%0A
 publ
@@ -708,82 +708,35 @@
 n = 
-(HttpURLConnection) url.openConnection();%0A%09%09%09in = new BufferedInputStream(
+App.openHttp(url);%0A%09%09%09in = 
 conn
@@ -752,17 +752,16 @@
 Stream()
-)
 ;%0A%09%09%09ret

Use okhttp on simplehttpconnection too