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

Discussion in 'Java' started by emrefan, Dec 7, 2007.

  1. emrefan

    emrefan Guest

    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.
    emrefan, Dec 7, 2007
    1. Advertisements

  2. emrefan

    Lew Guest

    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.
    Lew, Dec 7, 2007
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.