Results 1 to 6 of 6
Like Tree2Likes
  • 2 Post By JosAH

Thread: BufferedInputStream

  1. #1
    prinnori is offline Member
    Join Date
    Aug 2011
    Posts
    4
    Rep Power
    0

    Default BufferedInputStream

    Hello!

    I'm new to Java and I'm trying to understand how a BufferedInputStream works. I understand the underlying principle but I still have some questions.
    1. Can I control the size of the buffer?
    2. When exactly do the system calls occur? After I read all the values in the buffer, or at specific time intervals?
    3. Can I perform any operations on the values stored in the buffer or should I copy them into an array, perform the operations and then copy the new values into a BufferedOutputStream?

    Thank you!

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,048
    Blog Entries
    7
    Rep Power
    23

    Default

    Quote Originally Posted by prinnori View Post
    I'm new to Java and I'm trying to understand how a BufferedInputStream works. I understand the underlying principle but I still have some questions.
    1. Can I control the size of the buffer?
    2. When exactly do the system calls occur? After I read all the values in the buffer, or at specific time intervals?
    3. Can I perform any operations on the values stored in the buffer or should I copy them into an array, perform the operations and then copy the new values into a BufferedOutputStream?
    1. Yes, look at one of the constructors for the BufferedInputStream class.
    2. A system call occurs when the buffer is empty and the BufferedInputStream object needs to produce at least one new character.
    3. The buffer is owned by a BufferedInputStream object and is of no concern to us (we can't even reach it in an orderly manner).

    Since a BufferedInputStream object wraps another InputStream, the wrapped InputStream may do its own buffering.

    kind regards,

    Jos
    prinnori and JeffGrigg like this.
    The only person who got everything done by Friday was Robinson Crusoe.

  3. #3
    prinnori is offline Member
    Join Date
    Aug 2011
    Posts
    4
    Rep Power
    0

    Default

    Thanks a lot!

  4. #4
    prinnori is offline Member
    Join Date
    Aug 2011
    Posts
    4
    Rep Power
    0

    Default

    One more question
    Is there a method to find out when my BufferedOutputStream is full? (Because I want to know when to call flush() )

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,048
    Blog Entries
    7
    Rep Power
    23

    Default

    The BufferredOutputStream takes care of it (if the buffer is full, it flushes it); you can call flush() on that output stream and it will flush the buffer (whatever is in it).

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  6. #6
    prinnori is offline Member
    Join Date
    Aug 2011
    Posts
    4
    Rep Power
    0

Similar Threads

  1. BufferedInputStream with Huffman Compression
    By Msnforum in forum New To Java
    Replies: 0
    Last Post: 11-03-2009, 10:04 PM
  2. Replies: 1
    Last Post: 08-07-2007, 07:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •