Re: What is the purpose of all these Streams?

From: Anthony Borla (ajborla_at_bigpond.com)
Date: 11/27/03

  • Next message: SPG: "Re: program execution depends on java/javaw/debug"
    Date: Thu, 27 Nov 2003 13:21:59 GMT
    
    

    "Alligator" <pandelis@postmaster.co.uk> wrote in message
    news:ee8940b4.0311270042.3e282b80@posting.google.com...
    >
    > And more specifically what is the difference between an
    > InputStream and a BufferedInputStream?
    >

    An 'InputStream' is both a class, and a placeholder when used as a method
    parameter, which means that you can pass any object created from a class
    derived from this class.

    A 'BufferedInputStream' is a class that extends the capabilities of of the
    'InputStream' class to implement, among other things, I/O buffering.

    >
    > When should I use one and when should I use the other?
    >

    When you also want an input stream to be buffered wrap it up in a
    'BufferedInputStream' object.

    >
    > And why is there besides a BufferedInputStream also
    > a Buffered Reader?
    >

    'InputStream'-based classes read 8 bit bytes, while 'Reader'-based classes
    read 16 bit characters.

    > *** (1) ***
    > Should one use ?? :
    > InputStreamReader r =
    > new InputStreamReader( blabla.getInputStream());
    >
    > or
    >

    > *** (2) ***
    >
    > InputStreamReader r =
    > new InputStreamReader(
    > new BufferedInputStream(blabla.getInputStream()));
    >
    > or
    >
    > *** (3) ***
    >
    > BufferedReader br =
    > new BufferedReader(
    > new InputStreamReader(blabla.getInputStream()));
    >
    > or
    >

    > *** (4) ***
    >
    > BufferedReader br =
    > new BufferedReader(
    > new InputStreamReader(
    > new BufferedInputStream( blabla.getInputStream())));
    >

    Number *** (3) *** if buffering is required, and number *** (1) *** if it is
    not required. In general, a stream is buffered by wrapping it up inside an
    object that performs this task.

    >
    > Does the BufferedInputStream offer some advantage
    > over a simple InputStream?
    >

    It buffers it, meaning that it uses an internal storage area to hold more
    data that is requested, so helping to reduce the number of low-level I/O
    operations performed. The end result is faster, more efficient I/O.

    >
    > Any enlightment upon these subjects would be
    > very welcome ...
    >

    I strongly urge you to check out the Sun tutorials on streams, located at:

        http://java.sun.com/docs/books/tutorial/essential/io/index.html

    This describes the streams concept is some depth, as well as discussing all
    the Java stream classes in detail, together with much sample code.

    I hope this helps.

    Anthony Borla

    P.S.

    I apologise for the brevity of my answers - I realise they are not enough to
    adequately convey the ideas behind streams and stream use. I believe,
    though, that you can obtain this understanding by completing the recommended
    tutorial.


  • Next message: SPG: "Re: program execution depends on java/javaw/debug"

    Relevant Pages

    • Re: BufferedInputStream vs. InputStream
      ... A BufferedInputStream adds functionality to another input ... InputStream, meanwhile, is an abstract class is the ... superclass of all classes representing an input stream of bytes. ... first sentence of the JavaDocs for InputStream. ...
      (comp.lang.java.programmer)
    • Re: How can I get unbuffered InputStream from Process?
      ... The main problem is to obtain the InputStream on which this ... BufferedInputStream is based on. ... be able to deal with NIO stream (java 1.4), ...
      (comp.lang.java)
    • Re: InputStream markSupported/mark/reset
      ... die man dann in so einem Fall um den zu puffernden ... InputStream packt, z.B. BufferedInputStream. ... Ist es also notwendig, Deinen InputStream pufferfaehig zu machen, ... BufferedInputStream bis = new BufferedInputStream); ...
      (de.comp.lang.java)
    • Re: InputStream markSupported/mark/reset
      ... die man dann in so einem Fall um den zu puffernden ... InputStream packt, z.B. BufferedInputStream. ... Ist es also notwendig, Deinen InputStream pufferfaehig zu machen, ...
      (de.comp.lang.java)
    • Re: Why getInputStream in a http servlet request isnt getting the data sent by browser HTTP POST a
      ... BufferedInputStream is = new ... int count = is.read; ... That is only of interest if you are trying to avoid blocking, and not necessarily so much use even then. ... Furthermore, without looking at the source I speculate that BufferedInputStream's availablemethod might be based on the number of bytes available from the /buffer/, which might not be filled the first time until a read is attempted on the stream. ...
      (comp.lang.java.programmer)