0

I am trying to get response from XBMC:

try {
        Socket socket = new Socket("192.168.1.2",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);
        System.out.println(abc);
} catch (Exception e) {         
    e.printStackTrace();
}

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?

closed as off-topic by lenik, nc4pk, Krzysztof Adamski, Piotr Kula, Impulss Jul 5 '13 at 8:31

This question appears to be off-topic. The users who voted to close gave these specific reasons:

  • "Questions on Linux use unrelated to the RaspberryPi are off-topic here, but can be asked on Unix & Linux Stack Exchange." – Piotr Kula, Impulss
  • "This question does not appear to be specific to the Raspberry Pi within the scope defined in the help center." – lenik, nc4pk, Krzysztof Adamski
If this question can be reworded to fit the rules in the help center, please edit the question.

0

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
       sb.append(buffer);
    }
} while (numberRead == buffer.length);

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