List of usage examples for java.nio ByteBuffer asShortBuffer
public abstract ShortBuffer asShortBuffer();
From source file:Main.java
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.allocate(BSIZE); bb.asShortBuffer().put((short) 471142); System.out.println(bb.getShort(0)); }
From source file:Main.java
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.allocate(BSIZE); bb.asShortBuffer().put((short) 471142); bb.rewind();/*from w w w .j a v a2 s .com*/ System.out.println(bb.getShort()); }
From source file:Main.java
public static void main(String[] argv) throws Exception { ByteBuffer buf = ByteBuffer.allocate(15); ShortBuffer sbuf = buf.asShortBuffer(); }
From source file:Main.java
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.allocate(BSIZE); bb.asCharBuffer().put("Howdy!"); char c;//w w w .j a v a 2 s.c om 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()); }
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 w w w . j av a 2s .c o 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(); }
From source file:Main.java
public static ShortBuffer newShortBuffer(int numElements) { ByteBuffer bb = newByteBuffer(numElements * SIZEOF_SHORT); return bb.asShortBuffer(); }
From source file:Main.java
public static ByteBuffer copyShortBufferAsByteBuffer(ShortBuffer buf) { ByteBuffer dest = newByteBuffer(buf.remaining() * SIZEOF_SHORT); buf.mark();//from w ww.j a v a2s. c om dest.asShortBuffer().put(buf); buf.reset(); dest.rewind(); return dest; }
From source file:Main.java
public static ShortBuffer allocateShortBuffer(int capacity) { ByteBuffer vbb = ByteBuffer.allocateDirect(capacity); vbb.order(ByteOrder.nativeOrder()); return vbb.asShortBuffer(); }
From source file:Main.java
public static ShortBuffer shortToBuffer(short[] a) { ShortBuffer shortBuffer;// w w w . j ava 2 s . c o m ByteBuffer ibb = ByteBuffer.allocateDirect(a.length * 2); ibb.order(ByteOrder.nativeOrder()); shortBuffer = ibb.asShortBuffer(); shortBuffer.put(a); shortBuffer.position(0); return shortBuffer; }
From source file:Main.java
public static ShortBuffer createShortBuffer(int shortCount) { ByteBuffer data = ByteBuffer.allocateDirect(shortCount * 4); data.order(ByteOrder.nativeOrder()); ShortBuffer p1 = data.asShortBuffer(); return p1;/*from w w w.j av a2s .c o m*/ }