Stream definition

落花浮王杯 提交于 2019-12-20 11:55:18

问题


I'm reading on Java I/O streams and I'm confused on the correct definition associated with them.

  • Some say that a stream is a sort of conveyor belt in which data are transmitted...
  • other say that a stream is a flow or a sequence of a data...
  • other say that a stream is a connection to an input or an output source...

So what's the correct definition?


回答1:


A stream is a concept, but it's not that strict, that just only one description would be correct.

An I/O Stream represents an input source or an output destination. A stream can represent many different kinds of sources and destinations, including disk files, devices, other programs, and memory arrays. Streams support many 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.

From: http://download.oracle.com/javase/tutorial/essential/io/streams.html

Also a stream is either an input stream or output stream. If it is an input stream, in Java it will adhere to the InputStream interface, the latter to the Outputstream.

(Side note: In crypto, there's e.g. a difference between stream and block ciphers, where a stream cipher is something that does not know (in a very general sense) anything about the future, while a block cipher knows its (maximum) size in advance and the sizes of all coming blocks.)




回答2:


Java programs perform I/O through streams. A stream is an abstraction that either produces or consumes information. A stream is linked to a physical device by the Java I/O system. All streams behave in the same manner, even if the actual physical devices to which they are linked differ. Thus, the same I/O classes and methods can be applied to any type of device. This means that an input stream can abstract many different kinds of input: from a disk file, a keyboard, or a network socket. Likewise, an output stream may refer to the console, a disk file, or a network connection. Streams are a clean way to deal with input/output without having every part of your code understand the difference between a keyboard and a network, for example. Java implements streams within class hierarchies defined in the java.io package.

From: Java The Complete Reference




回答3:


I would say a Stream is like all of these, but not exactly any of these.

I would say its an ordered sequence of 8-bit bytes.




回答4:


Java performs I/O throw streams. A stream is an abstraction that either produces or consumes information. A stream is linked to a physical device by the java I/O stream. Streams are a cleaned way to deal with input or output without having every part of code understand. Java defines two types of stream: byte and character




回答5:


In my view point stream is actually a conveyor belt as you mention in the first point.Actually there are two types of stream,input and output.An input stream is used to read the data from the input device like keywords and write that data to the files and output stream is used to read data from the disks,files etc and write that data to the ouput device like console,monitor etc. In simple way,it is the bridge that helps to transport things from one point to another.




回答6:


Just think it this way: Streams are objects that you can ask for pieces of data or send pieces of data to.



来源:https://stackoverflow.com/questions/6327904/stream-definition

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!