Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Java Platform, Standard Edition
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==== Streams ==== The stream classes follow the [[decorator pattern]] by extending the base subclass to add features to the stream classes. Subclasses of the base stream classes are typically named for one of the following attributes: * the source/destination of the stream data * the type of data written to/read from the stream * additional processing or filtering performed on the stream data The stream subclasses are named using the naming [[pattern]] <code>''XxxStreamType''</code> where <code>''Xxx''</code> is the name describing the feature and <code>''StreamType''</code> is one of <code>InputStream</code>, <code>OutputStream</code>, <code>Reader</code>, or <code>Writer</code>. The following table shows the sources/destinations supported directly by the <code>java.io</code> package: {| class="wikitable" |- ! Source/Destination !! Name !! Stream types !! In/out !! Classes |- | <code>[[byte]]</code> [[Array (data type)|array]] (<code>byte[]</code>) || <code>ByteArray</code> || <code>byte</code> || in, out | {{Javadoc:SE|java/io|ByteArrayInputStream}}, {{Javadoc:SE|java/io|ByteArrayOutputStream}} |- | <code>char</code> array (<code>char[]</code>) || <code>CharArray</code> || <code>char</code> || in, out | {{Javadoc:SE|java/io|CharArrayReader}}, {{Javadoc:SE|java/io|CharArrayWriter}} |- | [[Computer file|file]] || <code>File</code> || <code>byte</code>, <code>char</code> || in, out | {{Javadoc:SE|java/io|FileInputStream}}, {{Javadoc:SE|java/io|FileOutputStream}}, {{Javadoc:SE|java/io|FileReader}}, {{Javadoc:SE|java/io|FileWriter}} |- | [[string (computer science)|string]] (<code>[[StringBuffer and StringBuilder|StringBuffer]]</code>) || <code>String</code> || <code>char</code> || in, out | {{Javadoc:SE|java/io|StringReader}}, {{Javadoc:SE|java/io|StringWriter}} |- | [[thread (computing)|thread]] (<code>Thread</code>) || <code>Piped</code> || <code>byte</code>, <code>char</code> || in, out | {{Javadoc:SE|java/io|PipedInputStream}}, {{Javadoc:SE|java/io|PipedOutputStream}}, {{Javadoc:SE|java/io|PipedReader}}, {{Javadoc:SE|java/io|PipedWriter}} |} Other standard library packages provide stream implementations for other destinations, such as the <code>InputStream</code> returned by the {{Javadoc:SE|package=java.net|java/net|Socket|getInputStream()}} method or the Java EE {{Javadoc:EE|package=javax.servlet|javax/servlet|ServletOutputStream}} class. Data type handling and processing or filtering of stream data is accomplished through stream [[filter (software)|filters]]. The filter classes all accept another compatible stream object as a parameter to the constructor and ''decorate'' the enclosed stream with additional features. Filters are created by extending one of the base filter classes {{Javadoc:SE|java/io|FilterInputStream}}, {{Javadoc:SE|java/io|FilterOutputStream}}, {{Javadoc:SE|java/io|FilterReader}}, or {{Javadoc:SE|java/io|FilterWriter}}. The <code>Reader</code> and <code>Writer</code> classes are really just byte streams with additional processing performed on the data stream to convert the bytes to characters. They use the default [[character encoding]] for the platform, which as of J2SE 5.0 is represented by the {{Javadoc:SE|java/nio/charset|Charset}} returned by the {{Javadoc:SE|package=java.nio.charset|java/nio/charset|Charset|defaultCharset()}} static method. The {{Javadoc:SE|java/io|InputStreamReader}} class converts an <code>InputStream</code> to a <code>Reader</code> and the {{Javadoc:SE|java/io|OutputStreamWriter}} class converts an <code>OutputStream</code> to a <code>Writer</code>. Both these classes have constructors that support specifying the character encoding to use. If no encoding is specified, the program uses the default encoding for the platform. The following table shows the other processes and filters that the <code>java.io</code> package directly supports. All these classes extend the corresponding <code>Filter</code> class. {| class="wikitable" |- ! Operation !! Name !! Stream types !! In/out !! Classes |- | [[buffer (computer science)|buffering]] || <code>Buffered</code> || <code>byte</code>, <code>char</code> || in, out | {{Javadoc:SE|java/io|BufferedInputStream}}, {{Javadoc:SE|java/io|BufferedOutputStream}}, {{Javadoc:SE|java/io|BufferedReader}}, {{Javadoc:SE|java/io|BufferedWriter}} |- | "push back" last value read || <code>Pushback</code> || <code>byte</code>, <code>char</code> || in | {{Javadoc:SE|java/io|PushbackInputStream}}, {{Javadoc:SE|java/io|PushbackReader}} |- | read/write [[primitive type]]s || <code>Data</code> || <code>byte</code> || in, out | {{Javadoc:SE|java/io|DataInputStream}}, {{Javadoc:SE|java/io|DataOutputStream}} |- | [[object serialization]] (read/write objects) || <code>Object</code> || byte || in, out | {{Javadoc:SE|java/io|ObjectInputStream}}, {{Javadoc:SE|java/io|ObjectOutputStream}} |}
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)