Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Hello,
I am using the httpUrlConnection to retrieve a json string from a webservice. Then I get the inputStream from the connection
jsonString = readJSONInputStream(mHttpUrlconnection.getInputStream());
I then use the following function to read the inputstream to get the JSON.
private String readJSONInputStream(final InputStream inputStream) {
    log.log(Level.INFO, "readJSONInputStream()");
    Reader reader = null;
    try {
        final int SIZE = 16092;
        char[] buffer = new char[SIZE];
        int bytesRead = 0;
        int read = 0;
        reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), SIZE);
        bytesRead = reader.read(buffer);
        String jsonString = new String(buffer, 0, bytesRead);
        log.log(Level.INFO, "bytesRead: " + bytesRead + " [ " + jsonString + " ]");
        /* Success */
        return jsonString;
    }
    catch(IndexOutOfBoundsException ex) {
        log.log(Level.SEVERE, "UnsupportedEncodingexception: " + ex.getMessage());
    }
    catch(IOException ex) {
        log.log(Level.SEVERE, "IOException: " + ex.getMessage());
    }
    finally {
        /* close resources */
        try {
            reader.close();
            inputStream.close();
        }
        catch(IOException ex) {
            log.log(Level.SEVERE, "IOException: " + ex.getMessage());
        }
    }
    return null;
}
However, if the json is small say 600 bytes then everything is ok (so the code above does work for smaller data). But I have some JSON that is about 15000 bytes in size so I set the maximum size to 16092.
However, the JSON it only reads about about 6511 and just cuts off.
I don't understand that if the JSON is small there is no problem. But for the larger JSON it just cuts off at the same size each time.
Am I doing anything wrong here. Anything I should check.
Many thanks for any suggestions,
 
     
     
     
    