• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

"java.io.OutputStream" hierarchy : Cant understand the SUN docs

 
Rahul Sudip Bose
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any book/link that answers such questions :

From oracle api :

OutputStream
An output stream accepts output bytes and sends them to some sink.

What is this sink ?

Applications that need to define a subclass of OutputStream must always provide at least a method that writes one byte of output

Why ?

FilterOutputStream
This class is the superclass of all classes that filter output streams....(continued below)

What kind of filtration is this and why is it needed ?


These streams sit on top of an already existing output stream (the underlying output stream) which it uses as its basic sink of data, but possibly transforming the data along the way or providing additional functionality.


What is meant by the "sit on top" part ?

PS : Is an understanding of these things needed for becoming a "good" developer or it can be skipped ?

 
Rob Spoor
Sheriff
Pie
Posts: 20661
65
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rahul Sudip Bose wrote:Is there any book/link that answers such questions :

From oracle api :

OutputStream
An output stream accepts output bytes and sends them to some sink.

What is this sink ?

With streams there are two lowest-level entities: sources and sinks. A source provides the actual data, a sink is the end point. This can be a hard drive (FileOutputStream), memory (ByteArrayOutputStream), the network (using Socket's getOutputStream()) and many more.

Applications that need to define a subclass of OutputStream must always provide at least a method that writes one byte of output

Why ?

Because writing single bytes is the most atomic operation required to write data. Writing a byte[] can be done by writing each element one by one, but you can't go smaller than one single byte. And because the different sink types all handle bytes differently, this cannot be implemented in OutputStream itself but must be implemented in subclasses.

FilterOutputStream
This class is the superclass of all classes that filter output streams....(continued below)

What kind of filtration is this and why is it needed ?

Check the Javadocs for known subclasses of FilterOutputStream. These are OutputStreams that wrap another OutputStream, and when data is written to the FilterOutputStream it modifies the data, then writes the modified data to the underlying OutputStream. For instance, GZIPOutputStream compresses data before actually writing it.


These streams sit on top of an already existing output stream (the underlying output stream) which it uses as its basic sink of data, but possibly transforming the data along the way or providing additional functionality.


What is meant by the "sit on top" part ?

It's wrapping. You wrap one output stream (the sink, like FileOutputStream) within another. You can go many levels deep, each level adding another modification. For instance:
This wraps a sink (FileOutputStream) inside a BufferedOutputStream) for buffering, and that one in turn is wrapped inside a GZIPOutputStream.

PS : Is an understanding of these things needed for becoming a "good" developer or it can be skipped ?

No, you really need to grasp at least the basics of the InputStream / OutputStream / Reader / Writer chaining, because it's used quite often.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic