Java stream Concept

Source: Internet
Author: User

The concept of stream in Java has been confusing for a long time. The following is an excerpt from the Internet:

 

 

At the beginning, I was confused about the concept of stream. After a long time, I finally understood it. After a long time, I was confused. Now I will make a summary and share it with you.

1. Java streams include inputstream and outputstream;

2. The concept of stream originates from the concept of pipe in UNIX. In UNIX, a media transcoding queue is an uninterrupted byte stream.ProgramOr inter-process communication, or reading and writing peripheral devices and external files;

3. the stream in Java is simply a byte. It can be seen as something formed by the convergence of many bytes. It is called a stream, just like water drops forming a river, huh, huh, my personal explanation;

4. A stream must have two parts: Data and byte. data can be some areas of computer memory, it can also be a disk file or even a URL on the Internet; bytes do not need to be bytes;

5. the source and destination ends of a stream can be viewed as producers and consumers of bytes. The data is changed from data to bytes, which are production bytes and production streams. The data is restored from bytes to Data, is to read byte, consumption stream;

6. The stream direction is very important. Based on the stream direction, the stream can be divided into two types: input stream and output stream. Stream direction is the most difficult to understand and the easiest to confuse

Source:Http://www.blogjava.net/myfly/archive/2008/08/28/225275.html

 

 

The following are official documents from Oracle:

I/O streams

AnI/O StreamRepresents an input source or an output destination. A stream can represent specify different kinds of sources and destinations, including disk files, devices, other programs, and memory arrays.

Streams support parse different kinds of data, including simple bytes, primitive data types, localized characters, and objects. Some streams simply pass on data; others manipulate and transform the data in useful ways.

No matter how they work internally, all streams present the same simple model to programs that use them: a stream is a sequence of data. A program usesInput streamTo read data from a source, one item at a time:

 

Reading information into a program.

A program usesOutput streamTo write data to a destination, one item at time:

 

Writing information from a program.

In this lesson, we'll see streams that can handle all kinds of data, from primitive values to advanced objects.

The data source and data destination pictured above can be anything that holds, generates, or consumes data. obviusly this has des disk files, but a source or destination can also be another program, a peripheral device, a network socket, or an array.

From:Http://docs.oracle.com/javase/tutorial/essential/io/streams.html

 

 

The following is a popular explanation on a forum:

A stream is data that you access in sequence. you coshould think of it like a train that you watch from a tunnel entrance so that you can just see one car at a time. or a stream of widgets coming into ss a conveyor belt requiring you to tighten a screw on each one before it passes by to the next person down the assembly line who has to pound it with a hammer, and so on. or Sticks floating down a river while you watch from a bridge.

Inputstream and outputstream are the basic stream classes in Java, one letting us bring data in from somewhere, the other letting us put data out to somewhere. all the other streams just add capabilities to the basics, like the ability to read a whole chunk of data at once for performance reasons (bufferedinputstream) or convert from one kind of character set to Java's native Unicode (Reader), or say where the data is coming from (fileinputstream, servletinputstream, socketinputstream, bytearrayinputstream, etc .)

The varous classes are meant to wrap each other, so we can build, for example, a bufferedinputstream that reads from a file:

Inputstream in = new bufferedinputstream (New fileinputstream (myfile ));

Then if you decide you want to read data from a network socket instead, you can just change fileinputstream () to socketinputstream () (and add a bit of code to establish the network connection of course) and you won't have to change anything else in your program.

From:Http://www.coderanch.com/t/527192//java/stream-java

 

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.