package com.ectrip.trips.net; import java.lang.reflect.Array; import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import com.ectrip.cyt.callback.HttpCallback; /** * @author jigo 网络访问核心类 */ public class HttpHelperCore { // 引入线程池来管理多线程 public ExecutorService executorService = Executors.newFixedThreadPool(3); /** * Post 网络请求 * * @param * @param * * @param url * 域名 * @param method * 方法 * @param errorData * 这个参数是判断fastJson 解析的数据是否正确,如果数据为空的情况下,返回失败 * @param map * 参数 */ public void executeHttpPost(String url,String method, HashMap map,HttpCallback resultListener, String errorData,Class cls) { // 用于子线程与主线程通信的Handler final HttpPostHandler mHandler = new HttpPostHandler( resultListener); executorService.submit(new HttpPostRunnable(resultListener, url, method, map, mHandler,errorData,cls)); } /** * 判断对象或对象数组中每一个对象是否为空: 对象为null,字符序列长度为0,集合类、Map为empty * * @param obj * @return */ public static boolean isNullOrEmpty(Object obj) { if (obj == null) return true; if (obj instanceof CharSequence) return ((CharSequence) obj).length() == 0; if (obj instanceof Collection) return ((Collection) obj).isEmpty(); if (obj instanceof Map) return ((Map) obj).isEmpty(); if (obj.getClass().isArray()) { return Array.getLength(obj) == 0; } if (obj instanceof Object[]) { Object[] object = (Object[]) obj; if (object.length == 0) { return true; } boolean empty = true; for (int i = 0; i < object.length; i++) { if (!isNullOrEmpty(object[i])) { empty = false; break; } } return empty; } return false; } }