From b184aa9370635a43b60f93763fed49bf46a2a2d6 Mon Sep 17 00:00:00 2001 From: Edwin Wu Date: Tue, 18 Jul 2017 15:54:34 +0800 Subject: [PATCH] =?UTF-8?q?JSONObject=20BOM=20=E5=A4=84=E7=90=86=20\uFEFF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/github/why168/http/FileCallback.java | 2 +- .../src/main/java/com/github/why168/http/HttpDispatcher.java | 4 ++-- .../src/main/java/com/github/why168/http/JsonCallback.java | 5 ++++- .../java/com/github/why168/http/code/HandlerExecutor.java | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/http-library/src/main/java/com/github/why168/http/FileCallback.java b/http-library/src/main/java/com/github/why168/http/FileCallback.java index 29faa9d..a7523ce 100644 --- a/http-library/src/main/java/com/github/why168/http/FileCallback.java +++ b/http-library/src/main/java/com/github/why168/http/FileCallback.java @@ -25,7 +25,7 @@ public abstract class FileCallback extends Callback { */ private String destFileName; - public FileCallback(String destFilePath, String destFileName) { + protected FileCallback(String destFilePath, String destFileName) { this.destFilePath = destFilePath; this.destFileName = destFileName; } diff --git a/http-library/src/main/java/com/github/why168/http/HttpDispatcher.java b/http-library/src/main/java/com/github/why168/http/HttpDispatcher.java index c4ea9ae..5cf9523 100644 --- a/http-library/src/main/java/com/github/why168/http/HttpDispatcher.java +++ b/http-library/src/main/java/com/github/why168/http/HttpDispatcher.java @@ -21,12 +21,12 @@ */ public class HttpDispatcher { private int maxRequests = 64; - private ExecutorService executorService; + private ThreadPoolExecutor executorService; private final Deque runningAsyncCalls = new ArrayDeque<>(); private final Deque readyAsyncCalls = new ArrayDeque<>(); - public HttpDispatcher(ExecutorService executorService) { + public HttpDispatcher(ThreadPoolExecutor executorService) { this.executorService = executorService; } diff --git a/http-library/src/main/java/com/github/why168/http/JsonCallback.java b/http-library/src/main/java/com/github/why168/http/JsonCallback.java index 437649e..21c3228 100644 --- a/http-library/src/main/java/com/github/why168/http/JsonCallback.java +++ b/http-library/src/main/java/com/github/why168/http/JsonCallback.java @@ -32,6 +32,9 @@ public JSONObject parseNetworkResponse(Response response, AtomicBoolean isCancel out.flush(); is.close(); out.close(); - return new JSONObject(new String(out.toByteArray())); + String str = new String(out.toByteArray()); + int i = str.indexOf("{"); + String results = str.substring(i); + return new JSONObject(results); } } diff --git a/http-library/src/main/java/com/github/why168/http/code/HandlerExecutor.java b/http-library/src/main/java/com/github/why168/http/code/HandlerExecutor.java index 76a81e4..a3ff9a1 100644 --- a/http-library/src/main/java/com/github/why168/http/code/HandlerExecutor.java +++ b/http-library/src/main/java/com/github/why168/http/code/HandlerExecutor.java @@ -22,7 +22,7 @@ public synchronized static HandlerExecutor getInstance() { return instance; } - private final Handler handler = new Handler(Looper.getMainLooper()); + private final Handler handler = new Handler(Looper.getMainLooper()); @Override public void execute(Runnable command) {