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 buffer
  • limit: This returns the first index of the buffer that should not be accessed
  • position: 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 ...

Get Learning Network Programming with Java now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.