Introduction to the concept and purpose of Java streaming, and introduction to java streaming

Source: Internet
Author: User

Introduction to the concept and purpose of Java streaming, and introduction to java streaming

All Java I/O mechanisms are input and output based on data streams, which represent the flow sequence of character or byte data. Java I/O Stream provides a standard method for reading and writing data. Any object in Java that represents a data source can read and write data in the form of data streams.

Standard input and output, file operations, data streams on the network, string streams, object streams, zip file streams, etc. In java, the input and output are abstracted as streams, just like water pipes, connect the two containers. The input stream that reads data from the external store to the memory (for use by Java programs) and writes data from the memory to the external store.

Stream is a very visual concept. When the program needs to read data, it will open a stream to the data source, which can be a file, memory, or network connection. Similarly, when the program needs to write data, it will open a stream to the destination.

A stream is a set of sequential bytes with a starting point and an ending point. It is a general term or abstraction for data transmission. That is to say, the transmission of data between two devices is called a stream. The essence of a stream is data transmission. Based on the data transmission characteristics, the stream is abstracted into various types to facilitate more intuitive data operations.

 

Stream classification:

Stream classification: Java's stream classification is rich. People who are new to it will feel dizzy after reading it. There are many stream classification methods:

1. According to the input direction, the input stream and the output stream. The reference object of the input and output is a Java program.

2. The unit of data processing is different: byte stream and byte stream. The minimum unit of byte stream reading is one byte (1 byte = 8 bit ), the primary stream can read one character at a time (1 char = 2 byte = 16bit ).

3. Based on different functions, node streams are divided into node streams and processing streams. node streams read and write data directly from a source stream (this stream is not packaged or modified ), stream processing is a type of stream encapsulated on the node stream. FileInputStream is a node stream that can directly read data from the file. However, BufferedInputStream can wrap FileInputStream to provide a buffer function.

Flow class structure:

 

Introduction to the concept of "stream" in Java

Byte stream and byte stream:

The origin of the character stream: because of the different data encoding, there is a stream object for efficient character operations. In essence, when reading data based on byte streams, the specified code table is checked. Differences between byte stream and byte stream:

Different read/write units: byte streams are measured in 8 bits and byte streams are measured in characters. Based on the ing characters in the code table, multiple bytes may be read at a time.

Different Processing objects: byte streams can process all types of data (such as slice and avi), while character streams can only process data of character types.

Conclusion: as long as the plain text data is processed, the use of the plain stream is preferred. In addition, byte streams are used.

The length of an English character is 1 byte, and the length of a Chinese character is 2 byte. if we process English-Chinese and English documents in a single byte stream, there will be chaotic segmentation and garbled characters. This is what we need to use the response stream for processing. This is why inputstream should be put into FileReader when processing documents.

Directionality:

Streams are divided into input streams and output streams. But this is relative. Especially in Hadoop serialization, it is always unknown whether to use the input stream or the output stream. Here, we can make a distinction:

Serialization means processing the data in byte streams. Byte streams are only a storage type. It will not be recognized by the program. It can be recognized by the java program only after the byte stream is deserialized into an object recognized by java. Therefore, serialization is byte streaming, that is, output from java code or memory to external storage. Deserialization is an object that converts byte stream data from external storage to an object recognized by a program.


Join the study exchange group 569772982 to learn and exchange.

Related Article

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.