Example usage for java.nio ByteBuffer asIntBuffer

List of usage examples for java.nio ByteBuffer asIntBuffer

Introduction

In this page you can find the example usage for java.nio ByteBuffer asIntBuffer.

Prototype

public abstract IntBuffer asIntBuffer();

Source Link

Document

Returns a int buffer which is based on the remaining content of this byte buffer.

Usage

From source file:Main.java

public static void main(String[] args) {
    ByteBuffer bb = ByteBuffer.allocate(BSIZE);
    bb.asIntBuffer().put(99471142);
    System.out.println(bb.getInt(0));
}

From source file:MainClass.java

public static void main(String[] args) {
    ByteBuffer bb = ByteBuffer.allocate(BSIZE);
    bb.asIntBuffer().put(99471142);
    System.out.println(bb.getInt());
}

From source file:Main.java

public static void main(String[] args) {
    ByteBuffer bb = ByteBuffer.allocate(BSIZE);
    bb.asIntBuffer().put(99471142);

    System.out.println(bb.getInt(0));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    ByteBuffer buf = ByteBuffer.allocate(15);

    IntBuffer ibuf = buf.asIntBuffer();

}

From source file:Main.java

public static void main(String[] args) {
    ByteBuffer bb = ByteBuffer.allocate(BSIZE);
    bb.asIntBuffer().put(99471142);
    System.out.println(bb.getInt());

    bb = ByteBuffer.allocate(BSIZE);
    bb.asLongBuffer().put(99472342341142L);
    System.out.println(bb.getLong());

    bb = ByteBuffer.allocate(BSIZE);

    bb.asFloatBuffer().put(99471142);/* w  w w .j av  a2 s .com*/
    System.out.println(bb.getFloat());

    bb = ByteBuffer.allocate(BSIZE);

    bb.asDoubleBuffer().put(99471142);
    System.out.println(bb.getDouble());

}

From source file:MainClass.java

public static void main(String[] args) {
    ByteBuffer bb = ByteBuffer.allocate(BSIZE);
    IntBuffer ib = bb.asIntBuffer();

    ib.put(new int[] { 1, 2, 7, 9, 3, 8, 6 });

    System.out.println(ib.get(3));
    ib.put(3, 1811);//from   w  w w  .  ja  v a  2 s.  co  m
    ib.rewind();
    while (ib.hasRemaining()) {
        int i = ib.get();
        if (i == 0)
            break; // Else we'll get the entire buffer
        System.out.println(i);
    }
}

From source file:IntBufferDemo.java

public static void main(String[] args) {
    ByteBuffer bb = ByteBuffer.allocate(BSIZE);
    IntBuffer ib = bb.asIntBuffer();
    // Store an array of int:
    ib.put(new int[] { 11, 42, 47, 99, 143, 811, 1016 });
    // Absolute location read and write:
    System.out.println(ib.get(3));
    ib.put(3, 1811);//from   w  w  w.j av  a2s.  c  o  m
    ib.rewind();
    while (ib.hasRemaining()) {
        int i = ib.get();
        if (i == 0)
            break; // Else we'll get the entire buffer
        System.out.println(i);
    }

}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    int port = 1919;

    SocketAddress address = new InetSocketAddress("127.0.0.1", port);
    SocketChannel client = SocketChannel.open(address);
    ByteBuffer buffer = ByteBuffer.allocate(4);
    IntBuffer view = buffer.asIntBuffer();

    for (int expected = 0;; expected++) {
        client.read(buffer);/*w  w  w .j a  va 2 s.  c  o m*/
        int actual = view.get();
        buffer.clear();
        view.rewind();

        if (actual != expected) {
            System.err.println("Expected " + expected + "; was " + actual);
            break;
        }
        System.out.println(actual);
    }
}

From source file:com.moscona.dataSpace.debug.ByteBufferTest.java

public static void main(String[] args) {
    ByteBuffer bytes = ByteBuffer.allocate(40);
    print("after allocation", bytes);
    byte[] byteArray = bytes.array();
    for (int i = 0; i < byteArray.length; i++) {
        byteArray[i] = 1;//  w w w.j av a  2  s .c o m
    }
    print("after filling with 1s", bytes);
    IntBuffer ints = bytes.asIntBuffer();
    System.out.println("ints has array: " + ints.hasArray());
    int[] array = ints.array();
    for (int i = 0; i < array.length; i++) {
        array[i] = 100 + i;
    }
    print("after filling ints array", bytes);
}

From source file:GetData.java

public static void main(String[] args) {
    ByteBuffer bb = ByteBuffer.allocate(BSIZE);
    // Allocation automatically zeroes the ByteBuffer:
    int i = 0;/*from  ww w  . j  av a  2s  .co m*/
    while (i++ < bb.limit())
        if (bb.get() != 0)
            System.out.println("nonzero");
    System.out.println("i = " + i);
    bb.rewind();
    // Store and read a char array:
    bb.asCharBuffer().put("Howdy!");
    char c;
    while ((c = bb.getChar()) != 0)
        System.out.print(c + " ");
    System.out.println();
    bb.rewind();
    // Store and read a short:
    bb.asShortBuffer().put((short) 471142);
    System.out.println(bb.getShort());
    bb.rewind();
    // Store and read an int:
    bb.asIntBuffer().put(99471142);
    System.out.println(bb.getInt());
    bb.rewind();
    // Store and read a long:
    bb.asLongBuffer().put(99471142);
    System.out.println(bb.getLong());
    bb.rewind();
    // Store and read a float:
    bb.asFloatBuffer().put(99471142);
    System.out.println(bb.getFloat());
    bb.rewind();
    // Store and read a double:
    bb.asDoubleBuffer().put(99471142);
    System.out.println(bb.getDouble());
    bb.rewind();

}