MD5 校验值:27cf44ec6e0720408f5ef017a90a3331
BaseHttpConnector.java 文件包含反编译后的源代码,请注意,该内容仅供学习和参考使用,不得用于非法用途。
package com.jiubang.commerce.statistics.adinfo.http; import android.content.Context; import com.gau.utils.net.HttpAdapter; import com.gau.utils.net.IConnectListener; import com.gau.utils.net.operator.IHttpOperator; import com.gau.utils.net.request.THttpRequest; import com.gau.utils.net.response.BasicResponse; import com.gau.utils.net.response.IResponse; import com.jb.ga0.commerce.util.LogUtils; import com.jb.ga0.commerce.util.NetUtil; import com.jb.ga0.commerce.util.http.AdvertJsonOperator; import com.jb.ga0.commerce.util.io.StringUtils; import com.jb.ga0.commerce.util.zip.ZipUtils; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.URISyntaxException; import java.util.HashMap; import org.apache.http.HttpResponse; public class BaseHttpConnector { private Context mContext; private String mHost; private HttpAdapter mHttpAdapter; public static String sGoogleAdId = ""; private static DefaultHttpOperator sDefaultHttpOperator = new DefaultHttpOperator(); public static class NetworkResultConstants { public static final int BUILD_REQUEST_ERROR = -3; public static final int NETWORK_PARSER_ERROR = -2; public static final int NETWORK_UNAVAIBLE = -1; } public BaseHttpConnector(Context context, String str) { HttpAdapter httpAdapter = new HttpAdapter(context); httpAdapter.setMaxConnectThreadNum(2); this.mHttpAdapter = httpAdapter; this.mContext = context.getApplicationContext(); this.mHost = str; } public BaseHttpConnector(Context context, String str, HttpAdapter httpAdapter) { this.mHttpAdapter = httpAdapter; this.mContext = context.getApplicationContext(); this.mHost = str; } public void connect(BaseHttpRequest baseHttpRequest, ConnectListener connectListener, IHttpOperator iHttpOperator) { if (!NetUtil.isNetWorkAvailable(this.mContext) && connectListener != null) { connectListener.onFail(-1); return; } if (iHttpOperator != null) { baseHttpRequest.setOperator(iHttpOperator); } this.mHttpAdapter.addTask(baseHttpRequest); } public void get(String str, ConnectListener connectListener) { get(this.mHost, str, connectListener, sDefaultHttpOperator); } public void get(String str, HashMap<String, String> hashMap, ConnectListener connectListener) { get(this.mHost, str, hashMap, connectListener, sDefaultHttpOperator); } public void get(String str, String str2, ConnectListener connectListener) { get(str, str2, connectListener, sDefaultHttpOperator); } public void get(String str, String str2, ConnectListener connectListener, IHttpOperator iHttpOperator) { get(str, str2, null, connectListener, iHttpOperator); } public void get(String str, String str2, HashMap<String, String> hashMap, ConnectListener connectListener, IHttpOperator iHttpOperator) { try { GetHttpRequest getHttpRequest = new GetHttpRequest(str + str2, str2, connectListener); if (hashMap != null) { getHttpRequest.setParamMap(hashMap); LogUtils.i("hzw", "paramMap--->" + hashMap.toString()); } LogUtils.i("hzw", "get url--->" + str + str2); connect(getHttpRequest, connectListener, iHttpOperator); } catch (URISyntaxException e) { e.printStackTrace(); if (connectListener != null) { connectListener.onFail(-3); } } } public void post(String str, String str2, ConnectListener connectListener) { post(this.mHost, str, str2, connectListener, sDefaultHttpOperator); } public void post(String str, String str2, HashMap<String, String> hashMap, ConnectListener connectListener) { post(this.mHost, str, str2, hashMap, connectListener, sDefaultHttpOperator); } public void post(String str, String str2, String str3, ConnectListener connectListener) { post(str, str2, str3, connectListener, sDefaultHttpOperator); } public void post(String str, String str2, String str3, ConnectListener connectListener, IHttpOperator iHttpOperator) { post(str, str2, str3, null, connectListener, iHttpOperator); } public void post(String str, String str2, String str3, HashMap<String, String> hashMap, ConnectListener connectListener, IHttpOperator iHttpOperator) { try { String str4 = str + str2; LogUtils.i("hzw", "post url--->" + str4); PostHttpRequest postHttpRequest = new PostHttpRequest(str3, str4, str2, connectListener); if (hashMap != null) { postHttpRequest.setParamMap(hashMap); LogUtils.i("hzw", "paramMap--->" + hashMap.toString()); } connect(postHttpRequest, connectListener, iHttpOperator); } catch (URISyntaxException e) { e.printStackTrace(); if (connectListener != null) { connectListener.onFail(-3); } } } public static abstract class ConnectListener implements IConnectListener { public abstract void onFail(int i); public abstract void onSuccess(String str); @Override public void onFinish(THttpRequest tHttpRequest, IResponse iResponse) { onSuccess(StringUtils.toString(iResponse.getResponse())); } @Override public void onStart(THttpRequest tHttpRequest) { } @Override public void onException(THttpRequest tHttpRequest, HttpResponse httpResponse, int i) { onFail(i); } @Override public void onException(THttpRequest tHttpRequest, int i) { onException(tHttpRequest, null, i); } } public static class GetHttpRequest extends BaseHttpRequest { public GetHttpRequest(String str, String str2, IConnectListener iConnectListener) throws IllegalArgumentException, URISyntaxException { super(str, iConnectListener); setProtocol(0); } } public static class PostHttpRequest extends BaseHttpRequest { public PostHttpRequest(String str, String str2, String str3, IConnectListener iConnectListener) throws IllegalArgumentException, URISyntaxException { super(str2, iConnectListener); setProtocol(1); if (str != null) { setPostData(str.getBytes()); } } } public static class BaseHttpRequest extends THttpRequest { public BaseHttpRequest(String str, IConnectListener iConnectListener) throws IllegalArgumentException, URISyntaxException { super(str, iConnectListener); setTimeoutValue(10000); setRequestPriority(10); setOperator(new AdvertJsonOperator(false, false)); setCurRetryTime(0); } } private static class DefaultHttpOperator implements IHttpOperator { private boolean mIsDecode; private boolean mIsZipData; public DefaultHttpOperator() { this.mIsZipData = false; this.mIsDecode = false; } public DefaultHttpOperator(boolean z) { this.mIsZipData = false; this.mIsDecode = false; this.mIsZipData = z; } public DefaultHttpOperator(boolean z, boolean z2) { this.mIsZipData = false; this.mIsDecode = false; this.mIsZipData = z; this.mIsDecode = z2; } @Override public IResponse operateHttpResponse(THttpRequest tHttpRequest, HttpResponse httpResponse) throws IllegalStateException, IOException { return new BasicResponse(4, parseData(httpResponse.getEntity().getContent(), this.mIsZipData, this.mIsDecode)); } public static String parseData(InputStream inputStream, boolean z, boolean z2) { String str; if (inputStream == null) { return null; } try { if (z) { str = ZipUtils.unzip(inputStream); } else { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); byte[] bArr = new byte[1024]; while (true) { try { int read = inputStream.read(bArr); if (read == -1) { break; } byteArrayOutputStream.write(bArr, 0, read); } catch (IOException e) { e.printStackTrace(); if (inputStream != null) { try { inputStream.close(); } catch (IOException e2) { e2.printStackTrace(); } } return null; } } str = new String(byteArrayOutputStream.toByteArray()); } if (str == null) { if (inputStream != null) { try { inputStream.close(); } catch (IOException e3) { e3.printStackTrace(); } } return null; } if (z2) { try { str = StringUtils.encode(str); } catch (Exception e4) { e4.printStackTrace(); } } if (inputStream == null) { return str; } try { inputStream.close(); return str; } catch (IOException e5) { e5.printStackTrace(); return str; } } catch (Throwable th) { if (inputStream != null) { try { inputStream.close(); } catch (IOException e6) { e6.printStackTrace(); } } throw th; } } } }