List of usage examples for java.nio ByteBuffer getInt
public abstract int getInt();
From source file:MainClass.java
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.allocate(BSIZE); bb.asIntBuffer().put(99471142);/* w w w. j ava 2 s . co m*/ 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);/*from w ww. j a va2 s .com*/ 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); System.out.println(bb.getFloat()); bb = ByteBuffer.allocate(BSIZE); bb.asDoubleBuffer().put(99471142); System.out.println(bb.getDouble()); }
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);//from w ww. j a v a 2 s . c o m // Reset position for reading buf.flip(); // Retrieve the values int i = buf.getInt(); }
From source file:GetData.java
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.allocate(BSIZE); // Allocation automatically zeroes the ByteBuffer: int i = 0;// ww w.j a v a 2 s . c om 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 long getUnsignedInt(ByteBuffer bb) { return ((long) bb.getInt() & 0xffffffffL); }
From source file:Main.java
public static String readMAString(ByteBuffer in) { int tmp = in.getInt(); byte[] dst = new byte[tmp]; in.get(dst);//from ww w . j a v a 2 s. co m String ret = Charset.forName("UTF-8").decode(ByteBuffer.wrap(dst)).toString(); return ret; }
From source file:Main.java
public static long getUnsignedInt(final ByteBuffer pByteBuffer) { return pByteBuffer.getInt() & 0xFFFFFFFFL; }
From source file:Main.java
static public int[] getArray(ByteBuffer data, int dataSize) { int size = data.getInt(); int[] result = new int[size]; for (int i = 0; i < result.length; i++) { if (dataSize == 2) result[i] = data.getShort(); if (dataSize == 4) result[i] = data.getInt();// www.j ava 2s .c om } return result; }
From source file:Main.java
public static int fromArray(byte[] payload) { ByteBuffer buffer = ByteBuffer.wrap(payload); buffer.order(ByteOrder.LITTLE_ENDIAN); return buffer.getInt(); }
From source file:Main.java
private static void receive(Map<Integer, byte[]> map, DatagramSocket socket, int[] length) { byte[] b = new byte[limit + 4]; DatagramPacket p = new DatagramPacket(b, b.length); try {//from w w w .j a va2s. c o m socket.receive(p); } catch (IOException ex) { ex.printStackTrace(); } if (p.getLength() != 0) { ByteBuffer buf = ByteBuffer.wrap(b); int key = buf.getInt(); byte[] bytes = new byte[p.getLength() - 4]; length[0] += bytes.length; buf.get(bytes); map.put(key, bytes); receive(map, socket, length); } }