This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark ""java.io.OutputStream" hierarchy : Cant understand the SUN docs" Watch ""java.io.OutputStream" hierarchy : Cant understand the SUN docs" New topic
Author

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

Rahul Sudip Bose
Ranch Hand

Joined: Jan 21, 2011
Posts: 637

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 ?


SCJP 6. Learning more now.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: "java.io.OutputStream" hierarchy : Cant understand the SUN docs
 
Similar Threads
Applets & Streams
gunzipping the file more than once at the same time
write to f file
image display quary: need help
What is stream in java?