Streams
An Introduction
Prof. David Bernstein
James Madison University
Computer Science Department
bernstdh@jmu.edu
Overview
Definitions and Analogies
Conceptual Models
Some Observations
Benefits of Streams
What Are Streams?
Definition:
A sequence of data with indeterminate length
UNIX streams end with
Ctrl
-
D
and Windows streams end with
Ctrl
-
Z
Analogies:
A river
A "waiting line" of people
One Conceptual Model of a Stream
UML Diagram:
Interpretation:
A stream carries data
Another Conceptual Model of a Stream
UML Diagram:
Interpretation:
A stream carries data from a source to a sink
A Third Conceptual Model of a Stream
UML Diagram:
Interpretation:
A communications channel connects an output stream to an input stream
Forms of the Connection:
Network connection, memory buffer between threads, I/O devices
Observations
Streams are first-in-first-out (FIFO)
Streams provide sequential access (though random access can be simulated)
Output Streams are "write only" and Input Streams are "read only"
The Benefits of the Stream Concept
Streams provide a uniform data interface that is independent of the channel
Streams can be used to buffer data, allowing the source and sink to operate at different speeds
Filters can be used to modify streams. Each filter can be simple but they can be used in combination if necessary.
Streams and Streaming Protocols
What Is a Communications Protocol?
An agreement that governs the procedures used to exchange information between cooperating entities
What is a Streaming Protocol:
A protocol in which the receiver does not wait for all of the data to be received before starting to process it
Are All Protocols that use Streams "Streaming Protocols"?
No, a protocol can use a stream for communication and still wait for all of the data before starting to process it