We can say that streams are like pipes that connect two points:įrom one side we pour data in and from the other data leaks out. Closing the stream is very important and must not be left out, because you risk losing data, damaging the file, to which the stream is opened, and so on – all of these are very troublesome scenarios, which must not happen in our programs. Streams are opened before we can begin working with them and are closed after they have served their purpose. The vast variety of streams can help us in different situations, but can also trouble us, because we need to be familiar with every type of stream, before we can use it in our application. For network communication, you have to use a specific type of stream. Some streams are used with text files, others-with binary files and then there are those that work with strings. You can think of streams as of a linked list that contains bytes, in which they have a strict order.ĭifferent situations require different types of streams. Streams do not allow random access to their data, only sequential. You cannot take the first, than the eight, third, thirteenth byte and so on. This is closely related to the previous feature. You can manipulate the data only in the order in which it arrives from the stream. Again, it is important to understand the meaning of the word sequential. If a byte is sent to a stream earlier than another byte, it will arrive earlier at the other end of the stream, which is guaranteed by the abstraction "stream". In no way must you influence the order of the information flow, because it will render it unusable. The word “order” is intentionally left stressed, because it is of great importance to remember that streams are highly ordered and organized. Because of streams, communication between program and file, program and remote computer, is made easy. Many devices use streams for reading and writing data. Streams and media streaming are different concepts but both use sequences of data.īasic Things You Need to Know about Streams Streaming audio and video allows files to be played before they are downloaded locally, making the site more interactive. Today’s modern web sites cannot do without the so-called streaming, which represents stream access to bulky multimedia files coming from the Internet. Sometimes, for convenience, a sequence of bytes can be treated as text (in a predefined encoding) and is referred to as a text stream. There are two types of streams – text streams and binary streams but this separation has to do with the interpretation of the sent and received bytes. This way, you can work with any peripheral device (camera, mouse, keyboard, USB stick, soundcard, printer, scanner etc.).Įvery time when you read or write from or to a file, you have to open a stream to the corresponding file, do the reading or writing, and then close the stream. The scanning of documents from a scanner can be done by sending commands to the scanner (an output stream) and then reading the scanned image (an input stream). Recreating sounds from the computer’s sound card can be done by sending some commands, followed by the sample sound, which is actually a sequence of bytes. For example, printing is a process of sending a sequence of bytes to a stream, associated with the corresponding port, to which is the printer connected. In the world of computers, many operations can be interpreted as reading and writing to a stream. Because of streams, different applications are able to access files on the computer and are able to establish network communication between remote computers. Streams are the primary means of exchanging information in the computer world. Streams are an abstraction of a data communication channel that connects two devices or applications. These bytes are written and read one after the other and always arrive in the same order as they were sent. It is important to say that the term input is associated with reading data, whereas the term output is associated with writing data.Ī stream is an ordered sequence of bytes, which is send from one application or input device to another application or output device. You can use streams when your program needs to "read" or "write" data to an external data source such as files, other PCs, servers etc. Streams are an essential part of any input-output library.
0 Comments
Leave a Reply. |