Example usage for java.nio ByteBuffer putShort

List of usage examples for java.nio ByteBuffer putShort

Introduction

In this page you can find the example usage for java.nio ByteBuffer putShort.

Prototype

public abstract ByteBuffer putShort(short value);

Source Link

Document

Writes the given short to the current position and increases the position by 2.

Usage

From source file:org.apache.hadoop.hbase.filter.TestFuzzyRowAndColumnRangeFilter.java

private void runTest(HTable hTable, int cqStart, int expectedSize) throws IOException {
    // [0, 2, ?, ?, ?, ?, 0, 0, 0, 1]
    byte[] fuzzyKey = new byte[10];
    ByteBuffer buf = ByteBuffer.wrap(fuzzyKey);
    buf.clear();/*from   ww  w . jav  a2s .  c  o  m*/
    buf.putShort((short) 2);
    for (int i = 0; i < 4; i++)
        buf.put((byte) 63);
    buf.putInt((short) 1);

    byte[] mask = new byte[] { 0, 0, 1, 1, 1, 1, 0, 0, 0, 0 };

    Pair<byte[], byte[]> pair = new Pair<byte[], byte[]>(fuzzyKey, mask);
    FuzzyRowFilter fuzzyRowFilter = new FuzzyRowFilter(Lists.newArrayList(pair));
    ColumnRangeFilter columnRangeFilter = new ColumnRangeFilter(Bytes.toBytes(cqStart), true, Bytes.toBytes(4),
            true);
    //regular test
    runScanner(hTable, expectedSize, fuzzyRowFilter, columnRangeFilter);
    //reverse filter order test
    runScanner(hTable, expectedSize, columnRangeFilter, fuzzyRowFilter);
}

From source file:org.getspout.spout.packet.PacketCustomBlockChunkOverride.java

public PacketCustomBlockChunkOverride(short[] customIds, int x, int z) {
    chunkX = x;//from   w w w  .  j  a  v  a 2s  . c om
    chunkZ = z;
    ByteBuffer buffer = ByteBuffer.allocate(customIds.length * 2);
    for (int i = 0; i < customIds.length; i++) {
        buffer.putShort(customIds[i]);
    }
    data = buffer.array();
}

From source file:com.offbynull.portmapper.pcp.PcpOption.java

/**
 * Dump this PCP option in to a byte buffer.
 * @param dst byte buffer to dump to//from  w ww . ja v a2  s.  c  o m
 * @throws NullPointerException if {@code dst} is {@code null}
 * @throws BufferOverflowException if {@code dst} doesn't have enough space to write this option
 * @throws ReadOnlyBufferException if {@code dst} is read-only
 */
final void dump(ByteBuffer dst) {
    Validate.notNull(data);

    dst.put((byte) code);
    dst.put((byte) 0); // reserved
    dst.putShort((short) length);
    dst.put(data.asReadOnlyBuffer());
}

From source file:org.apache.hadoop.hbase.filter.TestFuzzyRowAndColumnRangeFilter.java

@Test
public void Test() throws Exception {
    String cf = "f";
    String table = "TestFuzzyAndColumnRangeFilterClient";
    HTable ht = TEST_UTIL.createTable(Bytes.toBytes(table), Bytes.toBytes(cf), Integer.MAX_VALUE);

    // 10 byte row key - (2 bytes 4 bytes 4 bytes)
    // 4 byte qualifier
    // 4 byte value

    for (int i1 = 0; i1 < 2; i1++) {
        for (int i2 = 0; i2 < 5; i2++) {
            byte[] rk = new byte[10];

            ByteBuffer buf = ByteBuffer.wrap(rk);
            buf.clear();// w ww  .  ja  v a  2s.c  om
            buf.putShort((short) 2);
            buf.putInt(i1);
            buf.putInt(i2);

            for (int c = 0; c < 5; c++) {
                byte[] cq = new byte[4];
                Bytes.putBytes(cq, 0, Bytes.toBytes(c), 0, 4);

                Put p = new Put(rk);
                p.setDurability(Durability.SKIP_WAL);
                p.add(cf.getBytes(), cq, Bytes.toBytes(c));
                ht.put(p);
                LOG.info("Inserting: rk: " + Bytes.toStringBinary(rk) + " cq: " + Bytes.toStringBinary(cq));
            }
        }
    }

    TEST_UTIL.flush();

    // test passes
    runTest(ht, 0, 10);

    // test fails
    runTest(ht, 1, 8);
}

From source file:org.onlab.packet.IPv4Test.java

@Before
public void setUp() throws Exception {
    deserializer = IPv4.deserializer();/* ww w.  j  a  v a 2  s  .  c o m*/

    ByteBuffer bb = ByteBuffer.allocate(headerLength * 4);

    bb.put((byte) ((version & 0xf) << 4 | headerLength & 0xf));
    bb.put(diffServ);
    bb.putShort(totalLength);
    bb.putShort(identification);
    bb.putShort((short) ((flags & 0x7) << 13 | fragmentOffset & 0x1fff));
    bb.put(ttl);
    bb.put(protocol);
    bb.putShort(checksum);
    bb.putInt(sourceAddress);
    bb.putInt(destinationAddress);
    bb.put(options);

    headerBytes = bb.array();
}

From source file:org.openhab.binding.ulux.internal.ump.messages.AudioPlayLocalMessage.java

@Override
protected void addData(final ByteBuffer buffer) {
    buffer.put(this.volume);
    buffer.put(this.equalizer);
    buffer.putShort(this.playFlags.shortValue());
    buffer.putShort(this.incVolumeTime);
    buffer.putShort(this.repeats);
    buffer.putShort(this.delayBeforeRepeat);
    buffer.putShort(this.soundIndex);
}

From source file:edu.udo.scaffoldhunter.model.db.StringProperty.java

/**
 * Set the length in the BitFingerprint (first two bytes)
 * //from  w  ww . java2 s .  c  o  m
 * @param length
 *            the length
 * @param bitFingerprint
 *            the fingerprint
 */
private void lenghtToBitFingerprint(short length, byte[] bitFingerprint) {
    ByteBuffer bb = ByteBuffer.allocate(2);
    bb.order(ByteOrder.LITTLE_ENDIAN);
    bb.putShort(length);

    bitFingerprint[0] = bb.get(0);
    bitFingerprint[1] = bb.get(1);
}

From source file:org.openhab.binding.ulux.internal.ump.messages.AbstractUluxMessage.java

@Override
public final ByteBuffer getBuffer() {
    final ByteBuffer buffer = ByteBuffer.wrap(new byte[this.length]);
    buffer.order(ByteOrder.LITTLE_ENDIAN);

    buffer.put(this.length);
    buffer.put(this.messageId.toByte());
    buffer.putShort(this.actorId);

    addData(buffer);// www.ja  v  a 2 s  .  c  om

    buffer.flip();

    return buffer;
}

From source file:org.apache.asterix.experiment.builder.AbstractExperiment8Builder.java

protected String getPointLookUpAQL(int round) {
    ByteBuffer bb = ByteBuffer.allocate(8);
    bb.put((byte) 0);
    bb.put((byte) randGen.nextInt(N_PARTITIONS));
    bb.putShort((short) 0);
    bb.putInt(randGen.nextInt((int) (((1 + round) * dataInterval) / 1000)));
    bb.flip();/*ww w  . j a  v a 2 s  .c o m*/
    long key = bb.getLong();
    return pointQueryTemplate.replaceAll("\\$KEY\\$", Long.toString(key));
}

From source file:org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6StatsRequest.java

@Override
public void writeTo(ByteBuffer data) {
    data.putInt(this.vendor);
    data.putInt(this.msgsubtype);
    data.putInt((int) 0x0);//pad0
    data.putShort(this.outPort);
    data.putShort(this.match_len);
    data.put(this.tableId);
    for (int i = 0; i < 3; i++)
        data.put((byte) 0x0);//pad byte
}