03JavaIO detailed _io stream and filter flow in flow classification

Source: Internet
Author: User

Our last article spoke of InputStream (input stream). There are two kinds of flows in the input stream: node flow and filter stream. Let's talk about this in this article.

Review what is node flow: The node flow is directly interacting with the target.

Filter Flow: It is directly interacting with the node stream.

The InputStream node streams and filters are as follows:

Explain the above picture: there are so many subcategories for Inutstream. Where FilterInputStream (his sub-class datainputstream,bufferedinputstream .... are filtered streams) are filter streams, others are node streams.

Let's talk about the output stream (OutputStream), let's look at his level:

The same filteroutputstream (and his sub-class Dataoutstream,buffereoutstream is the filter stream) is the filter stream. The others are node streams,

The following two images complement the filter flow:

Let's talk about the Bufferedoutputstream filter flow in OutputStream:

This is for buffering. He is a filter stream that cannot be dealt directly with the IO device, he is the wrapper node stream. That is, the class is content from the program to the file. Without buffering, we have to enter this byte into a file whenever we have a byte, so the consequence is that we will be dealing with the IO device very often, which is very inefficient. So we use buffers, only when a certain number, such as 50 bytes to deal with the IO device, so as to avoid frequent contact with the IO device, improve efficiency.

Let's take a look at its constructor:

See no, it inside the constructor directly with OutputStream, not with what file deal with, that he is filtering flow, play the role of packaging.

The cases are as follows:

 public  class   Filetest { static  void  main (string[] args) throws   IOException { /*   * with the function of the cache and the function of the output *  */  OutputS Tream os  =new  FileOutputStream ("1.txt" )    ; Bufferedoutputstream bufferedoutputstream  =new      Bufferedoutputstream (OS);    Bufferedoutputstream.write ( "aaaaaaaa" .getbytes ()); Bufferedoutputstream.close ();}}  

03JavaIO detailed _io stream and filter flow in flow classification

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.