Convert ByteBuffer to an IntBuffer : IntBuffer « File « Java Tutorial





import java.nio.ByteBuffer;
import java.nio.IntBuffer;

public class MainClass {
  public static void main(String[] args) {
    ByteBuffer bb = ByteBuffer.wrap(new byte[] { 0, 0, 0, 0, 0, 0, 0, 'a' });
    bb.rewind();
    IntBuffer ib = ((ByteBuffer) bb.rewind()).asIntBuffer();
    System.out.println("Int Buffer");
    while (ib.hasRemaining())
      System.out.println(ib.position() + " -> " + ib.get());

  }
}
/*

 */
Int Buffer
0 -> 0
1 -> 97










11.46.IntBuffer
11.46.1.Convert ByteBuffer to an IntBuffer
11.46.2.Use while loop to read an IntBuffer
11.46.3.Put integers to a mapped IntBuffer
11.46.4.Map FileChannel to an IntBuffer and read from the IntBuffer
11.46.5.Manipulating ints in a ByteBuffer with an IntBuffer