BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 11-10-2008, 06:00 AM   #1 (permalink)
New Member
 
Join Date: Jul 2008
Model: pearl
PIN: N/A
Carrier: att
Posts: 5
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Random Access File is ridiculously SLOW!

Please Login to Remove!

I need to randomly access a binary file located in the SDCard. Execution time on the Simulator is fine but catastrophic on a Blackberry 8100 running OS4.2.1.103.
On a 1.5GB file, the first attempt (with InputStream) to read 1 byte at the end of the file takes about 40 seconds on the Blackberry 8100. Running the same code on the simulator is instant.

I also tried to use the SharedInputStream class (see 2nd attempt) but code crashes at internal SharedInputStreamSource.expandData (OutOfMemoryError) after 1 minute on simulator.

Any clue? Thanks...

// -- 1st attempt --
FileConnection filecon1 = (FileConnection) Connector.open("file://" + FileName, Connector.READ);
long size1 = filecon1.fileSize();
InputStream is = filecon1.openInputStream();
long ms1 = System.currentTimeMillis();
is.reset();
is.skip(size1 - 10); // set position
int r1 = is.read();
Dialog.alert("duration=" + (System.currentTimeMillis() - ms1));

// -- 2nd attempt --
FileConnection filecon2 = (FileConnection) Connector.open("file://" + FileName, Connector.READ);
long size2 = filecon2.fileSize();
SharedInputStream sis = SharedInputStream.getSharedInputStream(filecon2.op enInputStream());
long ms2 = System.currentTimeMillis();
sis.setCurrentPosition((int)size2 - 10); // set position
int r2 = sis.read();
Dialog.alert("duration=" + (System.currentTimeMillis() - ms2));

Last edited by patricek_97 : 11-10-2008 at 06:55 AM.
Offline  
Old 11-10-2008, 07:10 AM   #2 (permalink)
Thumbs Must Hurt
 
Join Date: Apr 2008
Model: 8130
PIN: N/A
Carrier: US Cellular
Posts: 82
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Is the file inside a ZIP file? If so, you can't actually random seek within individual files in the zip. Each seek requires starting at the beginning of the file and decompressing all the way up to the seek destination, which is very slow.
Offline  
Old 11-10-2008, 07:27 AM   #3 (permalink)
New Member
 
Join Date: Jul 2008
Model: pearl
PIN: N/A
Carrier: att
Posts: 5
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

It's not a zip file. It's propriatary binary data file.
Offline  
Old 11-10-2008, 09:45 AM   #4 (permalink)
New Member
 
Join Date: Jul 2008
Model: pearl
PIN: N/A
Carrier: att
Posts: 5
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

how come RandomAccessFile class does not exist?
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.