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
haoransd
Posts: 64
Registered: ‎08-07-2008
My Device: Not Specified

inputStream blocking problem

the read() method in inputStream class is blocking. I want to use available() method to provide an unblocked condition: ie. only call read() method when available() return a number greater than 0.

 

However, the method available() in InputStream  class is not implemented and always return 0.  it is useless. How to solve this problem?

 

thanks

Developer
marchywka
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: inputStream blocking problem

Generally the easiest thing to do is launch your own loader thread that can block without consequence.

You can subclass stream and implement available if you like. I haven't looked but there may be some buffered

stream classes you can use, I usually end up writing my own because I want to instrument them.

 

Developer
haoransd
Posts: 64
Registered: ‎08-07-2008
My Device: Not Specified

Re: inputStream blocking problem

Yes, Having multiple threads is one solution. But I wonder if anyone has override the available() method. Some sample code will be very useful.

Developer
marchywka
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: inputStream blocking problem

Well, you need something to override it with. Presumably there are some internal or native buffers and maybe you could

get hacked system dependent code to access these but more realistically in java you have to

create your own buffer and report available on that.

 

 I can't find a good example here but see if you can,

 

http://www.google.com/search?hl=en&q=site:sun.com+circular+buffer+example&start=10&sa=N

 

So far on the BB apps, it has made more sense to just buffer entire files and let the buffer worry about retry or messed up

connections rather than dribble pieces of data to the consumer. Unless you are doing some kind of streaming this may make

sense for you.

Developer
haoransd
Posts: 64
Registered: ‎08-07-2008
My Device: Not Specified

Re: inputStream blocking problem

Then how about override available() for socket inputStream? How could we access the socket buffer?