FilterInputStream
The function of FilterInputStream is to "encapsulate other input streams and provide them with additional functionality". Its commonly used subclasses are BufferedInputStream and DataInputStream.
The function of BufferedInputStream is to provide "buffering function for input streams, as well as mark() and reset() functions".
DataInputStream is used to decorate other input streams, which "allows applications to read basic Java data types from the underlying input stream in a machine-independent manner." Applications can use DataOutputStream to write data read by DataInputStream.
FilterInputStream source code (based on jdk1.7.40):
package java.io;public class FilterInputStream extends InputStream { protected volatile InputStream in; protected FilterInputStream(InputStream in) { this.in = in; } public int read() throws IOException { return in.read(); } public int read(byte b[]) throws IOException { return read(b, 0, b.length); } public int read(byte b[], int off, int len) throws IOException { return in.read(b, off, len); } public long skip(long n) throws IOException { return in.skip(n); } public int available() throws IOException { return in.available(); } public void close() throws IOException { in.close(); } public synchronized void mark(int readlimit) { in.mark(readlimit); } public synchronized void reset() throws IOException { in.reset(); } public boolean markSupported() { return in.markSupported(); }} FilterOutputStream
The function of FilterOutputStream is to "encapsulate other output streams and provide them with additional functionality". It mainly includes BufferedOutputStream, DataOutputStream and PrintStream.
(01) The function of BufferedOutputStream is to provide "buffering function for the output stream".
(02) DataOutputStream is used to decorate other output streams, using DataOutputStream and DataInputStream input streams, "allowing applications to read and write basic Java data types from the underlying input stream in a machine-independent manner."
(03) PrintStream is used to decorate other output streams. It adds functionality to other output streams, allowing them to easily print various data value representations.
FilterOutputStream source code (based on jdk1.7.40):
package java.io;public class FilterOutputStream extends OutputStream { protected OutputStream out; public FilterOutputStream(OutputStream out) { this.out = out; } public void write(int b) throws IOException { out.write(b); } public void write(byte b[]) throws IOException { write(b, 0, b.length); } public void write(byte b[], int off, int len) throws IOException { if ((off | len | (b.length - (len + off)) | (off + len)) < 0) throw new IndexOutOfBoundsException(); for (int i = 0 ; i < len ; i++) { write(b[off + i]); } } public void flush() throws IOException { out.flush(); } public void close() throws IOException { try { flush(); } catch (IOException ignored) { } out.close(); }}