List of usage examples for java.nio ByteBuffer putShort
public abstract ByteBuffer putShort(short value);
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();//www. ja va 2s .c om // Retrieve the values short s = buf.getShort(); }
From source file:Main.java
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.allocate(2); System.out.println("Default Byte Order: " + bb.order()); bb.putShort((short) 300); bb.flip();/*from www .ja v a2 s .co m*/ showByteOrder(bb); bb.clear(); bb.order(ByteOrder.LITTLE_ENDIAN); bb.putShort((short) 300); bb.flip(); showByteOrder(bb); }
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((short) 123); System.out.println(Arrays.toString(bbuf.array())); }
From source file:Main.java
public static void putUnsignedShort(ByteBuffer bb, int value) { bb.putShort((short) (value & 0xffff)); }
From source file:Main.java
public static byte[] shortToByteArray(int value) { ByteBuffer bb = ByteBuffer.allocate(2); bb.order(ByteOrder.LITTLE_ENDIAN); bb.putShort((short) value); return bb.array(); }
From source file:Main.java
public static byte[] shortToByteArray(short value) { ByteBuffer buffer = ByteBuffer.allocate(Short.SIZE / Byte.SIZE); buffer.order(ByteOrder.BIG_ENDIAN); buffer.putShort(value); return buffer.array(); }
From source file:Main.java
public static byte[] shortToByteArrayLE(short value) { ByteBuffer buffer = ByteBuffer.allocate(Short.SIZE / Byte.SIZE); buffer.order(ByteOrder.LITTLE_ENDIAN); buffer.putShort(value); return buffer.array(); }
From source file:org.apache.camel.converter.NIOConverter.java
@Converter public static ByteBuffer toByteBuffer(Short value) { ByteBuffer buf = ByteBuffer.allocate(2); buf.putShort(value); return buf;//from www. j a v a 2 s. c o m }
From source file:com.offbynull.portmapper.pcp.FilterPcpOption.java
private static ByteBuffer toDataSection(int prefixLength, int remotePeerPort, InetAddress remotePeerIpAddress) { Validate.inclusiveBetween(0, 128, prefixLength); // 0 indicates 'no filter' Validate.inclusiveBetween(0, 65535, remotePeerPort); // 0 indicates 'all ports' Validate.notNull(remotePeerIpAddress); ByteBuffer buffer = ByteBuffer.allocate(20); buffer.put((byte) 0); // reserved buffer.put((byte) prefixLength); buffer.putShort((short) remotePeerPort); buffer.put(NetworkUtils.convertToIpv6Array(remotePeerIpAddress)); return buffer; }
From source file:com.nridge.core.base.std.BufUtl.java
/** * Stores the <i>boolean</i> flag parameter value into the * <code>ByteBuffer</code> object. * * @param aBuffer Packet byte buffer object. * @param aFlag A boolean flag value./*from www.j av a 2 s . com*/ */ public static void putBool(ByteBuffer aBuffer, boolean aFlag) { if (aFlag) aBuffer.putShort((short) 1); else aBuffer.putShort((short) 0); }