The
filterinputstream
FilterInputStream is used to "encapsulate other input streams and provide them with additional functionality". Its commonly used subclasses are Bufferedinputstream and DataInputStream. The
Bufferedinputstream function is to provide buffering for the input stream, as well as Mark () and Reset () features. The
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 (data output streams) to write data that is read by the DataInputStream (data input stream).
FilterInputStream Source (based on jdk1.7.40):
package java.io; public class FilterInputStream extends the inputstream {protected Volati
Le 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 out, 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 (); }
}
The
filteroutputstream
filteroutputstream is used to "encapsulate other output streams and provide them with additional functionality." It mainly includes Bufferedoutputstream, DataOutputStream and PrintStream. The role of the
(Bufferedoutputstream) is to provide buffering for the output stream. The
(DataOutputStream) is used to decorate other output streams and to work with 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 ”。 The
(PrintStream) is used to decorate other output streams. It adds functionality to other output streams, enabling them to easily print various data-value representations.
Filteroutputstream Source (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 out, 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 ();
}