Introduction to buffers
Buffers hold data temporarily because it is being moved to and from channels. When a buffer is created, it is created with a fixed size or capacity. Part or all of a buffer's memory can be used with several Buffer class fields available to manage the data in a buffer.
The Buffer class is abstract. However, it possesses the basic methods used to manipulate a buffer, including:
capacity: This returns the number of elements in the bufferlimit: This returns the first index of the buffer that should not be accessedposition: This returns the index of the next element to be read or written
The element depends on the buffer type.
The mark and reset methods also control the position within a buffer. The mark method will set the buffer's mark to its position. The reset method restores the mark position to the previously marked position. The following code shows the relationships between various buffer terms:
0 <= mark <= position <= limit <= capacity
A buffer can be...