• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

IO Streams..

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can we pass an object of PushBackInputStream or an object of ObjectInputStream into a DataInputStream...
Actually, i am very confused about these IO streams.
can any one give detailed information as which objects can be passed into which streams like

which of the following Stream objects can be passed in to DataInputStream:
a) FileInputStream
b) BufferedInputStream
c) ByteArrayInputStream
d) PushBackInputStream
e) ObjectInputStream
f) PipedInputStream
which of the following Stream objects can be passed in to ObjectInputStream:
a) FileInputStream
b) BufferedInputStream
c) ByteArrayInputStream
d) PushBackInputStream
e) PipedInputStream
f) DataInputStream
which of the following Stream objects can be passed in to PipedInputStream:
a) FileInputStream
b) BufferedInputStream
c) ByteArrayInputStream
d) PushBackInputStream
e) ObjectInputStream
f) DataInputStream
etc etc..
Thank U
Mary.
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mary,
Yes it can be very complicated. To add to your confusion the answer to your question is that any of them can. All classes that extend InputStream can be passed into any class constructor for any InputStream subclass! That is the beauty of it.
Depending on what circumstance or feature you want one of the InputStream classes probably does it for you.
It might be easier to think of them as low-level and high-level.
Low level first subclass of InputStream
High level subclass of FilterInputStream (i.e., DataInputStream)
Regards,
Manfred.
 
Mary Robert
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi! Manfred,
Thanks for the reply. But , is it true with the output streams
and also with the character streams ???
thank u
mary
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mary,
There are so many I/O classes they can be intimidating at first I found it helped to remember them as paired sets.
byte streams = input streams and output streams; they can't handle characters
If the class is named somethingInputStream; it extends InputStream. Nearly always has a matching somethingOutputStream which extends OutputStream.
character streams = readers and writers
If the class is named somethingReader; it extends Reader. Nearly always has a matching somethingWriter which extends Writer.
Anything requiring an InputStream (or OutputStream) can take one of its subclasses.
Anything requiring a Reader (or Writer) can take one of its subclasses.
The exceptions to the above are:
FilexxxStreams - they require a File, FileDescriptor or String containing a file name
RandomAccessFile which implements both the DataInput and DataOutput interfaces and only takes a File or the String name of a file.
The Sun tutorial on I/O Streams has some diagrams that make the relationships easier to see.
Hope that helps.
------------------
Jane Griscti
Sun Certified Java 2 Programmer
reply
    Bookmark Topic Watch Topic
  • New Topic