I am trying to get response from XBMC:

try {
        Socket socket = new Socket("",9090);

        DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
        dos.writeBytes("{\"jsonrpc\": \"2.0\", \"method\": \"JSONRPC.Introspect\", \"id\": 1}");

        DataInputStream is = new DataInputStream(socket.getInputStream());
        byte ab[] = new byte[1024];
        is.read(ab, 0, ab.length);
        String abc = new String(ab);
} catch (Exception e) {         

But the response string is too long, I change 1024 to 60000 and this byte array still can not contain the whole response string. How to solve this?


This question does not belong to Raspberry Pi, it's more a common Java programming question. To be able to read large streams, use loop:

StringBuilder sb = new StringBuilder();
byte[] buffer = new byte[100];
int numberRead = 0;
do {
    numberRead = is.read(buffer);
    if (numberRead != -1){
       // do work here
} while (numberRead == buffer.length);
| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.