[Last Call] Learn how to a build a cloud-first strategyRegister Now


unable to create I/O buffered from SocketChannel

Posted on 2002-05-29
Medium Priority
Last Modified: 2009-07-29
I open socketChannels to listen incoming
datagrams. However, It seems to me that
I can't create such as

BufferedReader rd = new BufferedReader(new InputStreamReader(Channels.newInputStream(socketChannel));

'cause... it will be a exception error when i
try to call "rd.readLine ()"

So, it is prohibit to do this, or did i do something
wrong ??
Question by:mrvithan
  • 4
  • 3
LVL 35

Expert Comment

ID: 7041271
 What is the exception you are getting? Can you post the whole stack trace?

Author Comment

ID: 7041294
Exception in thread "main" java.nio.channels.IllegalBlockingModeException
        at sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:39)
        at sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:92)
        at sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:86)
        at java.io.InputStream.read(InputStream.java:88)
        at sun.nio.cs.StreamDecoder$ConverterSD.implRead(StreamDecoder.java:282)

        at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:179)
        at java.io.InputStreamReader.read(InputStreamReader.java:167)
        at java.io.BufferedReader.fill(BufferedReader.java:136)
        at java.io.BufferedReader.readLine(BufferedReader.java:299)
        at java.io.BufferedReader.readLine(BufferedReader.java:362)
        at MSNClient$Session.getLine(MSNClient.java:153)
        at MSNClient$MSN.connect(MSNClient.java:85)
        at MSNClient.main(MSNClient.java:216)
Press any key to continue...
LVL 35

Expert Comment

ID: 7041298
 What is the exception you are getting? Can you post the whole stack trace?
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 7041313
LVL 35

Accepted Solution

girionis earned 300 total points
ID: 7041316
 Sorry pressed refresh accidentally.

  From the jdk1.4 documentation for the newInputStream method:

  "The read methods of the resulting stream will throw an IllegalBlockingModeException if invoked while the underlying channel is in non- blocking mode. The stream will not be buffered, and it will not support the mark or reset methods. The stream will be safe for access by multiple concurrent threads. Closing the stream will in turn cause the channel to be closed."

  I am not very familiar with the new I/O classes but from the documentation I assume that the channel you are trying to read from is in the incorrect blocking mode.

  Maybe someone else with more experience can help you.

Expert Comment

ID: 7041342
try to create your SocketChannel in this manner:

sc = SocketChannel.open();
sc.configureBlocking(true); // that is what you must have

Author Comment

ID: 7041351
well, i tried it also... and i got

Exception in thread "main" java.nio.channels.IllegalBlockingModeException
        at java.nio.channels.spi.AbstractSelectableChannel.register(AbstractSele
        at java.nio.channels.SelectableChannel.register(SelectableChannel.java:2
        at MSNClient$MSN.connect(MSNClient.java:41)
        at MSNClient.main(MSNClient.java:216)

... Opps !!! any comment

acutally, i read this http://javaalmanac.com/egs/java.nio/NbClient.html.
LVL 35

Expert Comment

ID: 7054983
 Thank you for the points. I am glad I helped :-)

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month17 days, 23 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question