- 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
- Generally: first open after close, then open first close
- 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
- 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:
- If the node stream is closed and then the processing stream is closed, an IO exception is thrown.
- 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