List of usage examples for java.nio ByteBuffer allocate
public static ByteBuffer allocate(int capacity)
From source file:Main.java
public static void main(String[] argv) throws Exception { ByteBuffer buf = ByteBuffer.allocate(100); buf.putShort((short) 123); // Reset position for reading buf.flip();/*from ww w . java2s .c o m*/ // Retrieve the values short s = buf.getShort(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { ByteBuffer bbuf = ByteBuffer.allocate(10); int capacity = bbuf.capacity(); // 10 System.out.println(capacity); bbuf.put((byte) 0xFF); bbuf.position(5);/*from ww w . ja v a 2s. c o m*/ bbuf.put((byte) 0xFF); int pos = bbuf.position(); int rem = bbuf.remaining(); bbuf.limit(7); bbuf.rewind(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { ByteBuffer buf = ByteBuffer.allocate(100); // Put values of different types buf.putInt(123);//w ww. j a v a2 s .c om // Reset position for reading buf.flip(); // Retrieve the values int i = buf.getInt(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { ByteBuffer buf = ByteBuffer.allocate(100); // Put values of different types buf.putLong(123L);//from ww w .j a v a 2 s . com // Reset position for reading buf.flip(); // Retrieve the values long l = buf.getLong(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { ByteBuffer buf = ByteBuffer.allocate(100); // Put values of different types buf.putFloat(12.3F);//w ww. j ava 2 s . c om // Reset position for reading buf.flip(); // Retrieve the values float f = buf.getFloat(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { ByteBuffer buf = ByteBuffer.allocate(100); // Put values of different types buf.putChar((char) 123); // Reset position for reading buf.flip();/* w w w . j a v a2 s . c om*/ // Retrieve the values char c = buf.getChar(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { ByteBuffer buf = ByteBuffer.allocate(100); // Put values of different types buf.putDouble(12.3D);/*from www . j a va2 s.c om*/ // Reset position for reading buf.flip(); // Retrieve the values double d = buf.getDouble(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { ByteBuffer buf = ByteBuffer.allocate(10); buf.order(ByteOrder.LITTLE_ENDIAN); }
From source file:Main.java
public static void main(String[] argv) throws Exception { ByteBuffer buf = ByteBuffer.allocate(10); ByteOrder order = buf.order(); // ByteOrder.BIG_ENDIAN }
From source file:Main.java
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.allocate(BSIZE); bb.asIntBuffer().put(99471142);/*from w w w. ja v a 2 s .c o m*/ System.out.println(bb.getInt(0)); }