8 Replies Latest reply on Apr 10, 2007 10:05 AM by 807606

    Stupid question regarding BufferedInputStream

    807606
      Hi,

      I spent nearly all morning trying to further understand streams in java since I believe they are quite fondumental to say the least.

      I understand nearly completly the use of BufferedInputStream. What I cant understand is why it is actually required. I mean can't I have the same effect by using the InputStream method read(,,,) method? :

      http://java.sun.com/j2se/1.4.2/docs/api/java/io/InputStream.html#read(byte[],%20int,%20int)

      The BufferedInputStream will read a set of bytes from the stream before it is handled, and the read method mentioned above seems to do the same think.

      I labeled this question as stupid because I believe I am missing something fundomental about Streams which so far I am not picturing out!

      Regards,
      Sim085
        • 1. Re: Stupid question regarding BufferedInputStream
          800322
          Sure it does the same - since it's overridden, it follows the same contract. The difference it just that it might utilize the underlying buffer. So the implementation might differ, and it might not block as much or differently.
          • 2. Re: Stupid question regarding BufferedInputStream
            807606
            Do you know what buffering is?
            • 3. Re: Stupid question regarding BufferedInputStream
              807606
              Just another question regarding BufferedInputStream. The only different between a BufferedInputStream and a normal InputStream is that a BufferedInputStream will returned a set of bytes back while an InputStream will only return 1 byte at a time right?? The read mentod I mentioned above is another way how you can read many bytes at the same time from an incominng stream!? am I understanding this correctly?

              Regards,
              Sim085
              • 4. Re: Stupid question regarding BufferedInputStream
                800322
                Just another question regarding BufferedInputStream.
                The only different between a BufferedInputStream and
                a normal InputStream is that a BufferedInputStream
                will returned a set of bytes back while an
                InputStream will only return 1 byte at a time right??
                Sort of. Are you aware that buffered streams are also buffered?
                The read mentod I mentioned above is another way how
                you can read many bytes at the same time from an
                incominng stream!? am I understanding this
                correctly?
                uh, not sure.
                • 5. Re: Stupid question regarding BufferedInputStream
                  807606
                  Do you know what buffering is?
                  That could be the key to my misunderstanding. For me buffering means ammasing data to a certain limit untill actually do something with it. I get this opinion while reading on the BufferedOutputStream which ammasses the data to be saved so that rather then saving one byte a time it only saved a whole set of bytes at the same time so that there are less calls on the operating system. Naturally that could be wrong, or not to a required in dept level. Is this wrong?

                  Regards,
                  Sim085
                  • 6. Re: Stupid question regarding BufferedInputStream
                    807606
                    Sort of. Are you aware that buffered streams are also
                    buffered?
                    Does what I said above fit as an answer? I am asking coz I am not so sure..

                    Regards,
                    Sim085
                    • 7. Re: Stupid question regarding BufferedInputStream
                      800322
                      That could be the key to my misunderstanding. For me
                      buffering means ammasing data to a certain limit
                      untill actually do something with it. I get this
                      opinion while reading on the BufferedOutputStream
                      which ammasses the data to be saved so that rather
                      then saving one byte a time it only saved a whole set
                      of bytes at the same time so that there are less
                      calls on the operating system. Naturally that could
                      be wrong, or not to a required in dept level. Is this
                      wrong?
                      No, that's correct. Please also note that InputStream and especially read() is abstract. So the in-depth implementation will remain class-specific. In this case, the implementation uses a buffer to pre-fetch data.
                      • 8. Re: Stupid question regarding BufferedInputStream
                        807606
                        No, that's correct. Please also note that InputStream
                        and especially read() is abstract. So the in-depth
                        implementation will remain class-specific. In this
                        case, the implementation uses a buffer to pre-fetch
                        data.
                        Ok, so I see that my biggest mistake was to compare BufferedInputStream with InputStream which is abstract should compare it with other implementations of the InputStream.

                        Thanks :)

                        Regards,
                        Sim085