aspose file tools*
The moose likes I/O and Streams and the fly likes How InputStreamReader.read(char[] cbuf) determine the end of the stream Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "How InputStreamReader.read(char[] cbuf) determine the end of the stream" Watch "How InputStreamReader.read(char[] cbuf) determine the end of the stream" New topic
Author

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

Sky Loi
Ranch Hand

Joined: Oct 06, 2008
Posts: 65
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

Joined: Oct 27, 2005
Posts: 19762
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Sky Loi
Ranch Hand

Joined: Oct 06, 2008
Posts: 65
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How InputStreamReader.read(char[] cbuf) determine the end of the stream