Quick charts of I/O
classes
READER
INPUT CLASSES
Arrows correspond to the
stream direction which is implicit in combined constructor statements.
i.e. ← right to left for input, and left to right→ for output.
The arrows below indicate where other chained streams are likely to be attached. Check out the combined constructors.
chained sink stream ← BufferedInputStream ← chained
source stream
DataInputStream dis = new DataInputStream( new BufferedInputStream( new FileInputStream( “myfile”)));
|
It sends
to |
CHARACTER STREAM |
It gets
from |
Primary Function |
Does it
provide any unique methods beyond those in Reader? |
|
CHAINABLE SINK: If not chained, its methods can
be used return the characters. You may also want to use its readLine( )
method. |
← BufferedReader ← |
CHAINABLE SOURCE: Its
source can be any Reader stream. |
Provides buffered reading. It is usually chained to a FileReader as its source stream. |
It adds the handy readLine( ) method. readLine( ) reads until encountering a \n, \r, or \r\n and then stops, returning the
whole line in a String. |
|
CHAINABLE SINK: If not chained, its methods can
be used to return the chars from the source array. |
SOURCE NOT CHAINABLE: |
Creates a Reader stream
by reading from a char array |
Use the 9 methods from Reader. Adds nothing. |
|
|
CHAINABLE SINK: If not chained, its read(..) methods
can be used to simply return the characters.
|
SOURCE NOT CHAINABLE: |
Reads a file. |
Use the 9 methods from Reader. Adds nothing. |
|
|
CHAINABLE SINK: If not chained, its methods can be used to return
values. You may simply want to use
its read(..) methods. |
CHAINABLE SOURCE: Its
source can be an InputStream stream consisting of bytes or of various
other Charsets, including Unicode. It does not take a Reader stream. |
Converts InputStream
source bytes into a Reader stream of characters. |
Use the 9 methods from Reader.
|
|
|
USUALLY NOT CHAINED: Because you will probably want to use its own getLineNumber(..)
method. |
CHAINABLE SOURCE: Its
source can be any Reader stream |
Keeps track of line numbers in a
Reader stream when reading lines with readLine( ). |
Use the 9 methods from Reader
and especially use readLine( )
from its immediate parent BufferedReader.
|
|
|
CHAINABLE SINK: If not chained, its methods
return the characters from the source PipedWriter stream. |
SOURCE NOT CHAINABLE: |
Reads from a PipedWriter
stream which has been previously written to. |
Use the 9 methods from Reader.
|
|
|
USUALLY NOT CHAINED: Because you
will probably want to use its unread(..)
pushback methods. |
CHAINABLE SOURCE: Its
source can be any Reader stream |
Reads from a Reader
stream with the ability to put one or more chars back as if they had
not been read. |
Use the 9 methods from Reader.
|
|
|
CHAINABLE SINK: If chained to a sink stream, it
provides a Reader stream of characters from the String named in
its constructor. If not chained, its methods
return values from the source String. |
SOURCE NOT CHAINABLE: Its source is a String specified
in its constructor |
Lets you apply Reader I/O
stream methods to a String. |
Use the 9 methods from Reader. Adds nothing. |
|
It gets
from |
CHARACTER STREAM |
It sends
to |
Primary Function |
Does it
provide any unique methods beyond those in Writer? |
|
CHAINABLE SOURCE: Its
source can be any Writer stream. If not chained, its methods
must be supplied with values to write. |
→ BufferedWriter → |
CHAINABLE SINK: Its Writer output stream
can go into any other output Writer stream. |
Provides buffered writing.
It is usually chained to a FileWriter stream which acts as a
sink. |
Use the 7 methods from Writer. It adds a newLine( )
method which writes a line separator. |
|
CHAINABLE SOURCE: Its
source can be any Writer output stream. If not chained, its methods must be supplied values to write. |
SINK NOT CHAINABLE: The CharArrayWriter is a
sink itself. Its contents are
converted to a char array or String, or they can be written to
another stream using writeTo( ), or, after creation, the now-filled stream object handle can be
passed to a subsequent stream declaration constructor. |
Allows I/O methods to be used to
write an internal buffer which can later be retrieved as a char array
or as a String. |
Use the 7 methods from Writer. It adds five methods: size( ),
writeTo( ), and reset( ), plus toCharArray( ) and toString(
) for converting the stream contents. |
|
|
CHAINABLE SOURCE: Its
source can be any Writer output stream. If not chained, its methods
must be supplied values to write. |
SINK NOT CHAINABLE: Its sink is always a file in the
file system. |
Writes to a file in the file
system. |
Use the 7 methods from Writer. Adds nothing. |
|
|
CHAINABLE SOURCE: Its
source can be any Writer output stream. If not chained, its methods must be supplied values to write. |
→ FilterWriter → |
CHAINABLE SINK: Its Writer output stream
can go into any other output Writer stream sink. |
Provides a convenience class to
override if you want to write your own filtering. |
Adds nothing to Writer's
7 methods. |
|
CHAINABLE SOURCE: Its
source can be any Writer output stream. If not chained, its methods
must be supplied values to write. |
CHAINABLE SINK: However
its sink is always an OutputStream, for instance a FileOutputStream. |
Can produce bytes as well as
characters. |
Use the 7 methods from Writer.
|
|
|
CHAINABLE SOURCE: Its
source can be characters written to any Writer output stream. If not chained, its methods must be
supplied values to write. |
SINK NOT CHAINABLE: The PipedWriter is a sink itself. Its contents are transferred automatically
into the PipedReader to which it is connected. |
Creates a Writer stream which
is a source input to a PipedReader. |
|
|
|
USUALLY NOT CHAINED: Because you
will want to use its print(..)
or println(..) methods. |
CHAINABLE SINK: Its sink is always a character output stream such as a FileWriter.
Or it can also go to a
byte OutputStream such as a FileOutputStream. |
Writes or displays Java
primitives and objects as character text. |
It adds 21 print( ..) and
println(..) methods to the 7
methods in Writer. |
|
|
CHAINABLE SOURCE: Its
source can be characters from any Writer output stream. If not chained, its methods must be
supplied values. |
SINK NOT CHAINABLE: The StringWriter is a sink itself. Its contents are converted to a String or StringBuffer or its
object handle can be passed to a subsequent stream declaration constructor. |
Allows I/O methods to be used on
Strings. |
Use the 7 methods from Writer. It adds two methods - getBuffer(
) plus toString( ) for converting the stream contents. |