• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How InputStreamReader.read(char[] cbuf) determine the end of the stream

 
Sky Loi
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, all,

About method public int read(char[] cbuf) in InputStreamReader, how will it determine the end of stream and return -1? By special chars or timeout?

Thanks
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The end of the stream is just that, the end of the stream. What that means determines on the source.

For local files, the end of the stream is reached when all characters (or bytes with an InputStream) have been read.
For files on a web server or FTP server, the end of the stream is reached when the server says that all characters / bytes have been read. For HTTP (web servers) that is mostly determined by the content-length header.
For sockets, the end of the stream is reached when the other side has closed the connection and everything that has been sent before is read.
For other sources you'll have to check it out.
 
Sky Loi
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Rob.

I am changing my application to initiate the socket close to the server by some EOF indicator chars. In the past, I think the socket was closed initiated by server side when it finished file sending. Now the server side is changed to wait for my application initiation. That is why I have this concern and the question.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic