X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=src%2Fro%2Fieval%2Ffonbot%2FPollResultCallback.java;h=46e3eda83e39cc4ed15455ea0fc64f05f6c4f787;hb=1b6a04801bb78479f9d010cc1d5d8fcca089e013;hp=2517fce29f8e65d04f8cb3963ff05612af770416;hpb=2e5049c9c08b1989b4bfbbfbf479d83dbe2b75a9;p=fonbot.git diff --git a/src/ro/ieval/fonbot/PollResultCallback.java b/src/ro/ieval/fonbot/PollResultCallback.java index 2517fce..46e3eda 100644 --- a/src/ro/ieval/fonbot/PollResultCallback.java +++ b/src/ro/ieval/fonbot/PollResultCallback.java @@ -3,6 +3,7 @@ package ro.ieval.fonbot; import static ro.ieval.fonbot.Utils.toNonNull; import java.io.InputStream; +import org.eclipse.jdt.annotation.Nullable; import org.json.JSONArray; import org.json.JSONObject; @@ -53,19 +54,21 @@ final class PollResultCallback implements ResultCallback { } @Override - public void onResult(int responseCode, String responseMessage, - InputStream inputStream) { - if(responseCode!=200) + public void onResult(final int responseCode, final String responseMessage, final @Nullable InputStream inputStream) { + if(responseCode != 200 || inputStream==null){ + if(responseCode != 204) + throw new RuntimeException("Bad HTTP response code: "+responseCode); return; + } final Handler handler=new Handler(Looper.getMainLooper()); try{ final JSONArray array; { - final byte[] buf=new byte[4096*1024]; - inputStream.read(buf); - array=new JSONArray(new String(buf)); + final byte[] buf=new byte[2048*1024]; + final int length=inputStream.read(buf); + array=new JSONArray(new String(buf, 0, length)); } for(int i=0;i