11-10-2008, 05: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
| 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 05:55 AM.
|
| Offline
| |