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

New Developer
Posts: 1
Registered: ‎11-12-2008
My Device: Not Specified

RandomAccessFile does not exist?

[ Edited ]
I need to randomly access a binary file located in the SDCard. Class RandomAccessFile is not available so I'm using InputStream.skip.
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.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));
Message Edited by patricek on 11-12-2008 08:04 AM