05-04-2012 06:18 AM
hi friends,
i got a small problem how can i reduce the time to get the data from server.
means the taken was too much in between getting response code and converting stream data into string format.
some times it was fast and some times it takes too much time to convert the data so any one help me to find the solution for this will increase the performance of the app i think .
Thanks in advance.
05-04-2012 06:22 AM
if (httpConnection.getResponseCode() == 200) {
System.out.println("Response code reciving time:"
+ new Date(System.currentTimeMillis()));
byte[] resultData = IOUtilities.streamToBytes(inputStream);
String response = new String(resultData);
gotResponse = true;
// System.out.println("response is:" + response);
responseJsonObject = new JSONObject(response);
System.out.println("Response time"
+ new Date(System.currentTimeMillis()));
}this block takes too much time to excute some times it takes nearly 10-15 sec.
someone help me to find the solution for this.
05-06-2012 11:47 AM
Maybe your Server is different, but every JSON server I have used has sent the data using UTF-8, so I think this:
String response = new String(resultData);
should be something like this:
String response = null;
try {
response = new String(resultData,"UTF-8");
} catch (Exception e) {
// Will never happen - UTF-8 is supported....
}
Now getting back to your question:
"this block takes too much time to execute some times it takes nearly 10-15 sec"
I would expect this code to take some time, if there is a significant amount of data to transfer. It would be interesting to determine if the delay was in the read from the Network, which is the line
resultData = IOUtilities.streamToBytes(inputStream);
or the conversion to the JSON object:
responseJsonObject = new JSONObject(response);
Both will be influenced by the size of the data returned of course.
05-07-2012 02:55 AM
Thank you peter,