Welcome!

Welcome to the Official BlackBerry Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Super Contributor
bh1r1th
Posts: 273
Registered: ‎11-23-2010
My Carrier: Software Programmer

How to reduce the downloading time of data from server.

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.

Please use plain text.
Super Contributor
bh1r1th
Posts: 273
Registered: ‎11-23-2010
My Carrier: Software Programmer

Re: How to reduce the downloading time of data from server.

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.

Please use plain text.
Developer
peter_strange
Posts: 17,719
Registered: ‎07-14-2008

Re: How to reduce the downloading time of data from server.

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. 

Please use plain text.
Super Contributor
bh1r1th
Posts: 273
Registered: ‎11-23-2010
My Carrier: Software Programmer

Re: How to reduce the downloading time of data from server.

Thank you peter,

Please use plain text.