• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22644
123
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Yes, of course, and I accept that blame. In fact, i covet that blame. As does this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic