We will wrap up by examining several other buffer operations that can be useful. These include bulk data transfers between a buffer and an array using a view, and read-only buffers.
Bulk transfer is a way of transferring data between a buffer and an array. There are several get and put type methods that support bulk data transfers. They usually have two versions. The first version uses a single argument, which is the transfer array. The second version also uses an array, but it has two additional arguments: the starting index in the array, and the number of elements to transfer.
To demonstrate these techniques, we will use an IntBuffer
buffer. We will use the following displayBuffer
method to help us understand how data transfers work:
public void displayBuffer(IntBuffer buffer) { for (int i = 0; i < buffer.position(); i++) { System.out.print(buffer.get(i) + " "); } System.out.println(); }
We will start...