Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Does readInt() in DataInputStream class block?  RSS feed

 
Susan Smith
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the readFully() method in DataInputStream class, I know the method will block until a certain criteria occurs like below

This method blocks until one of the following conditions occurs:
b.length bytes of input data are available, in which case a normal return is made.
End of file is detected, in which case an EOFException is thrown.
An I/O error occurs, in which case an IOException other than EOFException is thrown


What I want to know is whether readInt() will do the same thing or not. Will it also block? It doesn't say anything about blocking in the API.

I'm developing a JAVA program that waits for data to come in. I ask the question above just to be sure that I'm doing the right thing in my code below. I'm hoping that the readInt() will block until the next streams of data coming in.

 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, readInt() will block until all four bytes are read. Or throw an EOFException if the stream ends before that. It's unfortunate that the API doesn't specifically say that it blocks, but it also doesn't allow for any way to return immediately without reading all four bytes, other than the EOFException. If the end of the stream has not been reached, the only option is to wait for the remaining bytes. You can also check out the source code in src.zip to verify what the method does.
 
Susan Smith
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see.

Thanks for your reply.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!