java - Why is EOFException used mainly by data input streams? -


from java api

public class eofexception extends ioexception

signals end of file or end of stream has been reached unexpectedly during input.

this exception mainly used data input streams signal end of stream. note many other input operations return special value on end of stream rather throwing exception.

so why data input streams different other input operations? why doesn't return special value other input operations signal end of stream? because think exception should used on exceptional cases.

an out-of-band return value required signal eos. in-band values used when returning primitives, there no out-of-band values available, has exception.

same applies objectinput.readobject(). null in-band value, can't used signal eos.

this different inputstream.read(), returns either -1 or byte value -128..127. in case -1 out of band.

one assumes readutf() throws eofexception symmetry other methods, although have returned null @ eos.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -