Java node-stream and processing flow

Source: Internet
Author: User

    • Node Flow: You can read and write data from or to a specific place (node). such as FileReader.
    • Processing Flow : Is the connection and encapsulation of an existing stream, which implements the data read and write through the functional invocation of the encapsulated stream. such as BufferedReader. The construction method of the processing stream always takes an additional stream object to do the argument. A Stream object passes through multiple wrappers of other streams, called links to streams.

Common Java node streams:  

    • File FileInputStream fileoutputstrean filereader FileWriter file to process the node stream.
    • The string StringReader stringwriter the node stream that handles the string.
    • The array bytearrayinputstream bytearrayoutputstream CharArrayReader chararraywriter The node stream that is processed by the arrays (the corresponding is no longer a file, but an array in memory).
    • The pipeline PipedInputStream PipedOutputStream pipedreaderpipedwriter the node stream that handles the pipeline.

Common processing flow (closing the process stream using the node stream inside the shutdown)

    • Buffered stream: Bufferedinputstrean bufferedoutputstream bufferedreader bufferedwriter---increased buffering to avoid frequent reads and writes of hard drives.
    • Convert stream: InputStreamReader Outputstreamreader implements a conversion between a byte stream and a character stream.
    • Data Flow DataInputStream DataOutputStream, etc.-provides for writing the underlying data type to a file, or reading it.
The closing order of the stream
    1. Generally: first open after close, then open first close
    2. Another scenario: depending on the dependency, if flow a relies on flow B, you should close stream A and then close stream B. For example, to process flow a relies on node flow B, you should close process flow A and then close node stream b
    3. You can only close the processing stream without shutting down the node stream. When the processing stream is closed, it calls the closing method of the node stream it handles.

Attention:

    1. If the node stream is closed and then the processing stream is closed, an IO exception is thrown.
    2. If the processing stream is closed, an IO exception may also occur when the node stream associated with it is closed. (Hadoop programming file stream operation was encountered.) )

Summary: Typically in an IO inheritance tree, the stream or conversion flow that inherits from the beginning of the filter is the process flow, and the rest is the node stream.

Java node-stream and processing flow

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.