Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > InputStream vs. ByteChannel as most basic source of bytes

Reply
Thread Tools

InputStream vs. ByteChannel as most basic source of bytes

 
 
Harald Kirsch
Guest
Posts: n/a
 
      08-28-2003
The class I am designing currently processes bytes in
the sequence they can be read from a source. Now I am
looking for the most basic byte source provided by
the Java library.

Before nio was introduced, InputStream was the most basic
general source of bytes (apart from byte[]). Now there is
also ReadableByteChannel, which seems to be even more
basic, mainly because it has fewer methods.

But then there is non-blocking behaviour...

Given that I choose ReadableByteChannel as the input source
for my new class, what is the best way for it to handle
non-blocking I/O, in particular the case where a read() returns
nothing although EOF is not yet reached. I could:

1) Write in the docs that my new class does not work with
non-blocking I/O. (Hmmpf)

2) Idle waiting like:
while( channel.read()==0 ) Thread.sleep(bbrrrzzzzz);
This is double Hmmpf.

3) Cooperative waiting:
while( channel.read()==0 ) Thread.yield();
This seems to me to be a useful option.

4) Read all the documentation about Selector and let
my new class stick a selector on top of the channel.

Since the class is not intended to multiplex different input
sources itself, (4) is probably an overkill resulting internally
exactly in (3). But this is only a guess.

Any ideas whether (4) could prove beneficial in the future or why
(3) may be all wrong anyway?

Thanks,
Harald.
 
Reply With Quote
 
 
 
Reply

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I know how many bytes had been received from an InputStream? maurora Java 2 11-26-2006 03:23 PM
Ratio of Bytes Delayed to Bytes Sent netproj Cisco 0 12-21-2005 08:08 PM
confused: Socket InputStream != ServerSocker InputStream R Java 5 03-13-2005 07:26 AM
making a ByteChannel from a ByteBuffer? bugbear Java 1 11-12-2004 09:13 PM
Private Bytes vs. # Bytes in all Heaps in Perfmon Jason Collins ASP .Net 3 02-18-2004 03:59 PM



Advertisments