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.

inside custom component

Java Development

Reply
Developer
Posts: 253
Registered: ‎08-14-2010
My Device: Not Specified
Accepted Solution

Download strategy help

Hi ,

 

I need a help to get an strategy to make the device happy.

 

I have a gallery with 170 images (thumblines and large views).

 

I need to store on DB and view them.

 

What I did,

 

  1. parse the feed(here I have two links to thumbline and the large view per item)
  2. call the links and get byte []
  3. store in the table as BLOBs

this take long time to work in simulator .

 

But device does not seems to be happy , it does not the job as in simulator.

 

can anyone propose me a strategy for this.

 

Cheers

 

 

Developer
Posts: 17,019
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Download strategy help

use a separate thread for all blocking operations
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 253
Registered: ‎08-14-2010
My Device: Not Specified

Re: Download strategy help

hi simon,

 

all above steps are run in a seperate thread already

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Download strategy help

"this take long time to work in simulator "

 

Have you analyzed where the time is being taken and investigated what you do about the parts that are taking a long time.  It would seem sensible to start there rather than working on the device.

 

"But device does not seems to be happy , it does not the job as in simulator"

 

I think something a little more descriptive of the problem (s) you are seeing would be appreciated - 'not happy' is not a very accurate term to apply to a piece of electronic equipment is it? 

Developer
Posts: 253
Registered: ‎08-14-2010
My Device: Not Specified

Re: Download strategy help

[ Edited ]

Hi peter,

 

 

public void endDocument() throws SAXException {
		// TODO Auto-generated method stub

		int size = this.key.size();
		SQLManager m =SQLManager.getInstance();

		for (int i = 0; i < size; i += 2) {

			GalleryBean p = new GalleryBean();

			String text = (String) this.key.elementAt(i);

			if (text.equalsIgnoreCase("photoSMALL")) {
				

				p.photoSMALL = (String) this.string.elementAt(i);
				p.photoBIG= (String) this.string.elementAt(i + 1);
				
				
				try {
					HttpConnection conn = (HttpConnection) Connector.open(p.photoSMALL);
					InputStream is = conn.openDataInputStream();
					
					byte b [] = new byte [10000];
					is.read(b);
					
					p.photosSByteArray=b;
					
					is.close();
					conn.close();
					
					HttpConnection conn2 = (HttpConnection) Connector.open(p.photoBIG);
					InputStream is2 = conn2.openDataInputStream();
					
					byte b2 [] = new byte [10000];
					is2.read(b2);
					
					p.photosByteArray=b2;
					
					is2.close();
					conn2.close();
					
					
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
				m.addGalleryItem(_tableName, p);
				
			}

 this is the code I am using

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Download strategy help

What do you expect us to do with this code?

 

And which questions from my previous post have you answered?

Developer
Posts: 253
Registered: ‎08-14-2010
My Device: Not Specified

Re: Download strategy help

Hi,

 

Please let me know the way I have written is correct , I mean where I used the two network calls.

 

My whole purpose is to parse the links from feed then get byte [] relevant to those links and store them in the DB.

Then I will retrive those byte [] (BLOBS) from DB to use in next screen.

 

There are almost 170 small and 170 big images.

 

I thought to use DB than using a Vector and pass it to next screen because feel like this can slow down the device.

 

Am I in correct thinking or there is any better strategy.

 

Please help.

 

Thank you

 

 

Developer
Posts: 253
Registered: ‎08-14-2010
My Device: Not Specified

Re: Download strategy help

hI,

doubt is I am always getting null byte[]

 

HttpConnection conn2 = (HttpConnection) Connector.open(p.photoBIG);
					InputStream is2 = conn2.openDataInputStream();
					
					byte b2 [] = new byte [10000];
					is2.read(b2);
					
					p.photosByteArray=b2;
					
					is2.close();
					conn2.close();

 for big image. (I checked using browser it is fine there)

 

Please help

Developer
Posts: 17,019
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Download strategy help

i suggest to use
http://www.blackberry.com/developers/docs/6.0.0api/net/rim/device/api/io/IOUtilities.html#streamToBy...
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 253
Registered: ‎08-14-2010
My Device: Not Specified

Re: Download strategy help

Hi Simon,

 

Many thanks , that is great , so I can use  something like below.

	byte[] buffer2 =  IOUtilities.streamToBytes(is2);

 Any  other improvemnts can determine?

 

Great help

 

cheers