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
Doctor
Posts: 73
Registered: ‎07-15-2008
My Device: Not Specified

Behavior of InputStream.read() differs from OS 4.2 to 4.3. Strange!

Hello Everyone,

 

There is something which I have noticed while testing my application on different versions of OS. My application was simply downloading a file from the server. It works fine with all the devices and simulator whith OS 4.2 but with the OS 4.3 it gave me strange results. The file being downloaded was larger than the actual file size. So, I debugged and noticed the data being read by InputStream.read() method in my app.

 

In OS 4.2 I noticed that InputStream.read() is reset with every iteration but in OS 4.3 the size of the InputStream.read() is added cumulatively. Thus, I end up with a larger filesize in OS 4.3 and the file gets downloaded perfectly fine in 4.2 OS!

 

Has anyone noticed such issue? Please guide me to the proper solution of this problem I am facing.

 

 

 

Thanks,

- Rohan

 

 

Please use plain text.
Developer
marchywka
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: Behavior of InputStream.read() differs from OS 4.2 to 4.3. Strange!

What? Can you post code? Network IO is not likely to be consistent from OS to OS or from connection to connection.

In this case I would suspect your code howerver.

 

Please use plain text.
Developer
Doctor
Posts: 73
Registered: ‎07-15-2008
My Device: Not Specified

Re: Behavior of InputStream.read() differs from OS 4.2 to 4.3. Strange!

Yeah sure.

 

Following is the code snippet of my app:

 

 

inputStream = httpConn.openInputStream(); byte[] buffer = new byte[(int) fileSize]; int bytesRead = 0; fileConnection = (FileConnection) Connector.open(filePath, Connector.READ_WRITE); if (fileConnection != null) { if (fileConnection.exists()) { fileConnection.delete(); } fileConnection.create(); outputStream = fileConnection.openOutputStream(); while ((bytesRead = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, bytesRead); } }

 

 

Thanks,

- Rohan

 

 

Please use plain text.
Developer
marchywka
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: Behavior of InputStream.read() differs from OS 4.2 to 4.3. Strange!

You are saying that bytesRead actually appears to be a pointer into the total amount already read from

the input stream, rather than the amount returned on the subject read?

Sounds like a big bug. I'm only using read with no params and I can't use local files because they don't exist on 4.0.2.

How did you determine this and set "filesize?" I guess there could be changes in buffering and timing between

versions but that obviously shouldn't effect the meaning of bytesRead.

 

Please use plain text.