import java.nio.*;
import java.nio.IntBuffer;

public class BufferIsReadOnly {
  public static void main(String[] args) {
    IntBuffer intBuf = IntBuffer.allocate(24);
    intBuf.put(2);
    intBuf.flip();
    System.out.println("Content in int buffer.");
    while (intBuf.hasRemaining()) {
      System.out.println(intBuf.get());
    }
    if (intBuf.isReadOnly()) {
      System.out.println("Buffer is read only.");
    else {
      System.out.println("Buffer is not read only.");
    }
    IntBuffer readIntBuffer = intBuf.asReadOnlyBuffer();
    readIntBuffer.flip();
    System.out.println("Content in readonly buffer.");
    while (readIntBuffer.hasRemaining()) {
      System.out.println(readIntBuffer.get());
    }

    if (readIntBuffer.isReadOnly()) {
      System.out.println("Buffer is read only.");
    else {
      System.out.println("Buffer is not read only.");
    }
  }
}