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.
Originally Posted by prinnori
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.
One more question :(blush):
Is there a method to find out when my BufferedOutputStream is full? (Because I want to know when to call flush() )
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).