java.nio.ByteBuffer. Provides a range of operations:
get, put - read and write single byte, wrap - wraps a byte array into a buffer.
ByteBuffer is derived from the abstract class Buffer (aka java.nio.Buffer). "A buffer is a linear, finite sequence of elements of a specific primitive type". Properties include: capacity (number of items it contains, never negative and never changes), limit (index of first element that should not be read or written), position (index of next item to be read/written).
A byte buffer can be direct or non direct. Given a direct byte buffer, the JVM will do its best to do native I/O operations on it. This will avoid copying buffer's content to an intermediate buffer before invoking the O/S underlying I/O operations. There is a factory method allocateDirect(int capacity) that allocates a new direct byte buffer. If the capacity is negative we throw IllegalArgumentException.
No comments:
Post a Comment