BufferedInputStream vs. InputStream

Discussion in 'Java' started by Andersen, Oct 5, 2005.

  1. Andersen

    Andersen Guest

    What is the fundamental difference between BufferedInputStream and
    InputStream?
     
    Andersen, Oct 5, 2005
    #1
    1. Advertising

  2. Andersen

    Oliver Wong Guest

    "Andersen" <> wrote in message
    news:43442d2a$0$13403$...
    > What is the fundamental difference between BufferedInputStream and
    > InputStream?


    A BufferedInputStream adds functionality to another input
    stream-namely, the ability to buffer the input and to support the mark and
    reset methods. InputStream, meanwhile, is an abstract class is the
    superclass of all classes representing an input stream of bytes.

    BTW, I composed this "intelligent sounding" answer by copying and
    pasting the first sentence of the JavaDocs for BufferedInputStream and the
    first sentence of the JavaDocs for InputStream. You should try reading more
    about those two if you haven't already.

    - Oliver
     
    Oliver Wong, Oct 5, 2005
    #2
    1. Advertising

  3. Andersen

    Rationem Guest

    The difference, as you may have guessed, is that BufferedInputStream
    uses a buffer. BufferedInputStream is also almost always faster than
    regular InputStream implementations because a bufferedStream does not
    neet to as many asyncronous reads.
     
    Rationem, Oct 5, 2005
    #3
  4. Andersen

    Roedy Green Guest

    On Wed, 05 Oct 2005 21:44:38 +0200, Andersen
    <> wrote or quoted :

    >What is the fundamental difference between BufferedInputStream and
    >InputStream?


    see http://mindprod.com/jgloss/buffer.html
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Oct 6, 2005
    #4
  5. Andersen wrote:
    > What is the fundamental difference between BufferedInputStream and
    > InputStream?
    >


    An InputStream has to make an operating system call every time
    you call its read() method. This can be very inefficient in terms
    of cpu usage. A BufferedInputStream can call the operating system
    just once and collect a whole array of bytes, and then service
    many read() calls from its local buffer before going back to the
    operating system for more. This can improve performance by a
    factor of 10 or more.

    Steve
     
    Steve Horsley, Oct 6, 2005
    #5
  6. Andersen

    Roedy Green Guest

    On Wed, 05 Oct 2005 21:44:38 +0200, Andersen
    <> wrote or quoted :

    >What is the fundamental difference between BufferedInputStream and
    >InputStream?


    another answer is BufferedInputStream adds a readLine method.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Oct 6, 2005
    #6
  7. On Thu, 06 Oct 2005 17:51:46 GMT, Roedy Green wrote:
    > another answer is BufferedInputStream adds a readLine method.


    Since when?

    /gordon

    --
    [ do not email me copies of your followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
     
    Gordon Beaton, Oct 6, 2005
    #7
  8. Andersen

    Harry Bosch Guest

    >since when<
    I think someone is thinking of a BufferedReader
     
    Harry Bosch, Oct 6, 2005
    #8
  9. Andersen

    Roedy Green Guest

    On 6 Oct 2005 20:12:01 +0200, Gordon Beaton <> wrote or
    quoted :

    >> another answer is BufferedInputStream adds a readLine method.

    >
    >Since when?


    oops. I should have said BufferedReader adds readLine to a Reader.

    In the days before Readers could you not say

    System.in.readLine() ??? If not, how DID you read lines from the
    console?
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Oct 6, 2005
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Krick
    Replies:
    2
    Views:
    14,366
    Marco Schmidt
    Aug 28, 2003
  2. Jimmy Zhang

    reset issue in bufferedInputStream

    Jimmy Zhang, Oct 15, 2003, in forum: Java
    Replies:
    6
    Views:
    793
    Jimmy Zhang
    Oct 15, 2003
  3. Jimmy Zhang
    Replies:
    1
    Views:
    699
    Roedy Green
    Oct 31, 2003
  4. Marc Twain
    Replies:
    5
    Views:
    4,888
    Andrew Thompson
    Jan 15, 2004
  5. R
    Replies:
    5
    Views:
    2,146
    Kevin McMurtrie
    Mar 13, 2005
Loading...

Share This Page