java api design q: Reader/Writer vs InputStream/OutputStream

E

emrefan

I am curious as to whether my understanding of the design philosophy
behind the design of this part of the java API is correct. I think the
Reader/Writer clan is for handling Characters (or just chars?) and the
Input/OutputStream clan is for handling bytes or bytes that make up
Objects. Is this right? Once I thought I always needed a Reader/Writer
to read/write things from/to streams, but obvious enough now that's
just not true.
 
L

Lew

emrefan said:
I am curious as to whether my understanding of the design philosophy
behind the design of this part of the java API is correct. I think the
Reader/Writer clan is for handling Characters (or just chars?) and the
Input/OutputStream clan is for handling bytes or bytes that make up
Objects. Is this right? Once I thought I always needed a Reader/Writer
to read/write things from/to streams, but obvious enough now that's
just not true.

You're nearly correct.

Readers and Writers manipulate chars under an encoding (UTF-8, ISO8859-2,
etc.), also called "text". Streams manipulate bytes, not necessarily bytes
that make up an arbitrary object. (Most just manipulate byte arrays.) These
data are also called "binary data".

Readers and Writers are wrappers for streams. They apply an encoding to the
data to turn them from text into binary data (in the case of Writers) and from
binary back to text (in the case of Readers). The binary data in turn are run
through the underlying streams.

Character is a Java class. The concept of a class no longer has any meaning
once data are on the stream.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,142
Latest member
arinsharma
Top