F
failure_to
hello
Sorry for so many questions, but I think I/O is one topic that will
give me troubles for quite some time
1)
What makes read and write operations time consuming ( or at least more
time consuming than calls to ordinary, non IO methods? )?
a) The fact that underlying stream classes make calls to system
libraries?
b)
* Buffer classes are supposed to help us with that, since they buffer
data and thus don¡¦t necessarelly call underlying system for each byte.
But non the less, even if buffered stream doesn¡¦t immediately call
underlying system in order to write a byte, it still has to call
underlying system ( say it buffers 5 bytes of data and at some point
we call flush() ) once for each byte „³ just as non buffered stream
classes have to¡K so in the end, same amount of time was spent to write
those five bytes to a file as if we¡¦d write those 5 bytes with non
buffered stream ¡K only difference being that those 5 bytes were
written at once and not every time write() was called?!
* Or, can buffered streams somehow call underlying system¡¦s method
just once and with just that one call write all five bytes of data?
c)
Even if buffered byte streams can somehow write all 5 bytes with one
system call, that shouldn¡¦t be true for BufferedWriter streams?!
BufferedWriter stream doesn¡¦t directly talk to underlying byte
stream, so I assume it would still take 5 system calls to write those
five bytes of data? So no time was saved!
2)
FileInputStream FS = new FileInputStream ( ¡§A.txt¡¨ );
BufferedInputStream BS = new BufferedInputStream ( FS );
DataInputStream DS = new DataInputStream ( BS );
Of the three objects above, I assume only the byte stream objects keep
some sort of internal pointer which keeps track of which bytes in a
stream were already written/read and thus advances this pointer with
each read or write operation? Wrapper objects ( BS and DS in the above
example ) don¡¦t have such internal pointers?!
3)
If you use say Fileoutputstream method write( int buf[]¡K), does it act
like kind of buffer and reads all those bytes with one system call, or
does it make one system call for each byte read?
4)
BufferedReader in = new
BufferedReader( new FileReader("foo.in") );
Does even simple in.read() without any parameters specified causes
wrapped FileReader object to read more than just one character from
underlying byte stream?
5)
Next questions are about PrintStream class. Here is what Java docs and
my book have to say about this class:
¡§All characters printed by a PrintStream are converted into bytes
using the platform's default character encoding. ¡§
I assume the text is referring to cases where we don¡¦t specify type of
encoding in a constructor, since if we do specify which encoding to
use, then PrintStream converts characters into bytes using specified
encoding and not platform¡¦s default character encoding?!
¡§For real-world programs, the recommended method of
writing to the console when using Java is through a PrintWriter
stream. PrintWriter is one of the character-based classes. Using a
character-based class for console output makes it easier to
internationalize your program.¡¨
¡§The PrintWriter class should be used in situations that require
writing characters rather than bytes.¡¨
* Why should PrintWriter be used instead in situations that require
writing characters instead of bytes?
* How does PrintWriter make it easier to internationalize a program?
* When dealing with characters, when and why ( or why not ) would you
choose PrintWriter over some other character based stream ( like
OutputStreamWriter )?
thank you
cheers
Sorry for so many questions, but I think I/O is one topic that will
give me troubles for quite some time
1)
What makes read and write operations time consuming ( or at least more
time consuming than calls to ordinary, non IO methods? )?
a) The fact that underlying stream classes make calls to system
libraries?
b)
* Buffer classes are supposed to help us with that, since they buffer
data and thus don¡¦t necessarelly call underlying system for each byte.
But non the less, even if buffered stream doesn¡¦t immediately call
underlying system in order to write a byte, it still has to call
underlying system ( say it buffers 5 bytes of data and at some point
we call flush() ) once for each byte „³ just as non buffered stream
classes have to¡K so in the end, same amount of time was spent to write
those five bytes to a file as if we¡¦d write those 5 bytes with non
buffered stream ¡K only difference being that those 5 bytes were
written at once and not every time write() was called?!
* Or, can buffered streams somehow call underlying system¡¦s method
just once and with just that one call write all five bytes of data?
c)
Even if buffered byte streams can somehow write all 5 bytes with one
system call, that shouldn¡¦t be true for BufferedWriter streams?!
BufferedWriter stream doesn¡¦t directly talk to underlying byte
stream, so I assume it would still take 5 system calls to write those
five bytes of data? So no time was saved!
2)
FileInputStream FS = new FileInputStream ( ¡§A.txt¡¨ );
BufferedInputStream BS = new BufferedInputStream ( FS );
DataInputStream DS = new DataInputStream ( BS );
Of the three objects above, I assume only the byte stream objects keep
some sort of internal pointer which keeps track of which bytes in a
stream were already written/read and thus advances this pointer with
each read or write operation? Wrapper objects ( BS and DS in the above
example ) don¡¦t have such internal pointers?!
3)
If you use say Fileoutputstream method write( int buf[]¡K), does it act
like kind of buffer and reads all those bytes with one system call, or
does it make one system call for each byte read?
4)
BufferedReader in = new
BufferedReader( new FileReader("foo.in") );
Does even simple in.read() without any parameters specified causes
wrapped FileReader object to read more than just one character from
underlying byte stream?
5)
Next questions are about PrintStream class. Here is what Java docs and
my book have to say about this class:
¡§All characters printed by a PrintStream are converted into bytes
using the platform's default character encoding. ¡§
I assume the text is referring to cases where we don¡¦t specify type of
encoding in a constructor, since if we do specify which encoding to
use, then PrintStream converts characters into bytes using specified
encoding and not platform¡¦s default character encoding?!
¡§For real-world programs, the recommended method of
writing to the console when using Java is through a PrintWriter
stream. PrintWriter is one of the character-based classes. Using a
character-based class for console output makes it easier to
internationalize your program.¡¨
¡§The PrintWriter class should be used in situations that require
writing characters rather than bytes.¡¨
* Why should PrintWriter be used instead in situations that require
writing characters instead of bytes?
* How does PrintWriter make it easier to internationalize a program?
* When dealing with characters, when and why ( or why not ) would you
choose PrintWriter over some other character based stream ( like
OutputStreamWriter )?
thank you
cheers