|Streams in Java|
Streams in Java:
These devices look very different at the hardware level but they share certain common characteristics such as:
- Unidirectional flow of data
- Treating of data as a sequence of bytes or characters.
- Support to the sequential access of data.
IO devices works as below:
Java uses the concept of Streams to represent the ordered sequence of data,a common characteristics shared by all input/output devices.A Stream presents an uniform ,easy to use ,object oriented interface between the program and input/output devices.
A Stream in java is a path along which data flows(like pipeline of a water supply).It has a source of data and a destination of the same data.The source and destination may be physical devices or code or other streams in the program.
The data flow via Streams:
Basic Classification of Streams:
Java streams are classified into two basic types:
- InputStreams-reads the data from a source and send it to program for processing
- OutputStreams-write processed data to a Stream and send it over other devices.
Ways to read from Stream in Java:
- Random access
- Line y line
- by words
- by tokens
Further Classification of Stream classes:
- ByteStream- These classes helps to handle I/O operation on bytes
- CharacterStream- These classes helps to handle I/O operations on Characters.
|Java Stream class||Classification||Classes||Destination|
|CharacterStream Classes||Reader Classes||Reader Classes||Memory
|CharacterStream Classes||Writer Classes||BufferedWriter
Classification of ByteStream:
- Reading bytes
- Closing Streams
- Marking position in Stream
- Shipping ahead in a Stream
- Finding the number of bytes in Stream
Class DataInputStream extends to FilterInputStream and implements the interface DataInput. Hence the DataInputStream class implements the methods described in the DataInput apart from its own methods.
- Writing bytes
- Closing streams
- Flushing streams