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 bbuf = ByteBuffer.allocate(10); int capacity = bbuf.capacity(); // 10 System.out.println(capacity); bbuf.putShort(2, (short) 123); System.out.println(Arrays.toString(bbuf.array())); System.out.println(bbuf.position()); }
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.putShort(2, (short) 123); System.out.println(Arrays.toString(bbuf.array())); System.out.println(bbuf.hasArray()); }
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.putShort(2, (short) 123); System.out.println(Arrays.toString(bbuf.array())); System.out.println(bbuf.arrayOffset()); }
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.putShort(2, (short) 123); System.out.println(Arrays.toString(bbuf.array())); System.out.println(bbuf.isReadOnly()); }
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.putShort(2, (short) 123); System.out.println(Arrays.toString(bbuf.array())); bbuf.flip();//from w w w .j a v a2 s . c om }
From source file:Main.java
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.allocate(BSIZE); bb.asCharBuffer().put("Howdy!"); char c;//from w w w . j a v a 2 s. c o m while ((c = bb.getChar()) != 0) System.out.print(c + " "); System.out.println(); }
From source file:Main.java
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.allocate(BSIZE); bb.asCharBuffer().put("java2s.com"); char c;/*www.j a v a2 s. c o m*/ while ((c = bb.getChar()) != 0) System.out.print(c + " "); System.out.println(); }
From source file:Main.java
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.allocate(BSIZE); int i = 0;/*from w ww . java 2 s . c o m*/ while (i++ < bb.limit()) if (bb.get() != 0) { System.out.println("nonzero"); } System.out.println("i = " + i); }
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("java2s.com".getBytes(), 0, 2); ByteBuffer bbuf1 = ByteBuffer.allocate(10); bbuf1.put(bbuf);/* w w w .j a va 2 s .c o m*/ System.out.println(Arrays.toString(bbuf1.array())); }
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.putShort(2, (short) 123); ByteBuffer bb = bbuf.slice(); System.out.println(Arrays.toString(bb.array())); }