The usage of FilterInputStream and Filteroutputstream in Java is detailed _java

Source: Internet
Author: User

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 ();
  }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.