Filter Streams   «Prev 

Filtering Java Streams using pipe and faucet Analogy

A water filter sits between the pipe and faucet

A water filter sits between the pipe and faucet, pulling out impurities. A stream filter sits between the source of the data and its eventual destination, and modifies that data according to a specific algorithm.
As drops of water are passed through the water filter and modified, so too are bytes of data passed through the stream filter and modified. Do not try to stretch this analogy too far or you will break it, but I do want you to see where the idea of filters comes from.
Of course, there are some big differences, namely a stream filter can add data or some other kind of annotation to the stream, in addition to removing things you do not want; it may even produce a stream that is completely different from its original input (for example, by compressing the original data).

public class DataInputStream extends FilterInputStream implements DataInput

A data input stream lets an application read primitive Java data types from an underlying input stream in a machine-independent way.
An application uses a data output stream to write data that can later be read by a data input stream.
DataInputStream is not necessarily safe for multithreaded access. Thread safety is optional and is the responsibility of users of methods in this class.