Example usage for java.nio ByteBuffer getInt

List of usage examples for java.nio ByteBuffer getInt

Introduction

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

Prototype

public abstract int getInt();

Source Link

Document

Returns the int at the current position and increases the position by 4.

Usage

From source file:org.opendaylight.lispflowmapping.lisp.serializer.MappingRecordSerializer.java

public MappingRecordBuilder deserializeToBuilder(ByteBuffer buffer) {
    MappingRecordBuilder builder = new MappingRecordBuilder();
    builder.setRecordTtl(buffer.getInt());
    byte locatorCount = (byte) ByteUtil.getUnsignedByte(buffer);
    builder.setMaskLength((short) ByteUtil.getUnsignedByte(buffer));
    byte actionAndAuthoritative = buffer.get();
    Action act = Action.forValue(actionAndAuthoritative >> 5);
    if (act == null) {
        act = Action.NoAction;//w w w .  j  a v a  2  s  . c o m
    }
    builder.setAction(act);
    builder.setAuthoritative(ByteUtil.extractBit(actionAndAuthoritative, Flags.AUTHORITATIVE));
    buffer.position(buffer.position() + Length.RESERVED);
    builder.setMapVersion(buffer.getShort());

    LispAddressSerializerContext ctx = new LispAddressSerializerContext(builder.getMaskLength());
    builder.setEid(LispAddressSerializer.getInstance().deserializeEid(buffer, ctx));

    builder.setLocatorRecord(new ArrayList<LocatorRecord>());
    for (int i = 0; i < locatorCount; i++) {
        builder.getLocatorRecord().add(LocatorRecordSerializer.getInstance().deserialize(buffer));
    }

    builder.setTimestamp(System.currentTimeMillis());

    return builder;
}

From source file:ezbake.services.graph.archive.TransactionIdGenerator.java

public TransactionIdGenerator(String interfaceName) {
    ByteBuffer buf = ByteBuffer.wrap(getMacAddress(interfaceName));
    serverId = buf.getInt();
    lastTime = -1L;//w w  w  . j a v a 2 s .  c o  m
    sequence = 0;
}

From source file:org.opendaylight.lispflowmapping.implementation.serializer.EidToLocatorRecordSerializer.java

public EidToLocatorRecord deserialize(ByteBuffer buffer) {
    EidToLocatorRecordBuilder builder = new EidToLocatorRecordBuilder();
    builder.setRecordTtl(buffer.getInt());
    byte locatorCount = (byte) ByteUtil.getUnsignedByte(buffer);
    builder.setMaskLength((short) ByteUtil.getUnsignedByte(buffer));
    byte actionAndAuthoritative = buffer.get();
    Action act = Action.forValue(actionAndAuthoritative >> 5);
    if (act == null) {
        act = Action.NoAction;/* ww w. j  a  va2s .c  om*/
    }
    builder.setAction(act);
    builder.setAuthoritative(ByteUtil.extractBit(actionAndAuthoritative, Flags.AUTHORITATIVE));
    buffer.position(buffer.position() + Length.RESERVED);
    builder.setMapVersion(buffer.getShort());

    LispAFIAddress afiAddress = LispAddressSerializer.getInstance().deserialize(buffer);
    LispAddressContainer container = LispAFIConvertor.toContainer(afiAddress);
    builder.setLispAddressContainer(container);

    builder.setLocatorRecord(new ArrayList<LocatorRecord>());
    for (int i = 0; i < locatorCount; i++) {
        builder.getLocatorRecord().add(LocatorRecordSerializer.getInstance().deserialize(buffer));
    }

    return builder.build();
}

From source file:MainClass.java

public void run() {

    ByteBuffer sizeb = ByteBuffer.allocate(4);
    try {/*ww  w  .  j  a  v  a 2  s .  c  o m*/
        while (sizeb.hasRemaining())
            in.read(sizeb);
        sizeb.flip();
        int howMany = sizeb.getInt();
        sizeb.clear();

        for (int i = 0; i < howMany; i++) {
            while (sizeb.hasRemaining())
                in.read(sizeb);
            sizeb.flip();
            int length = sizeb.getInt();
            sizeb.clear();

            ByteBuffer data = ByteBuffer.allocate(length);
            while (data.hasRemaining())
                in.read(data);

            BigInteger result = new BigInteger(data.array());
            System.out.println(result);
        }
    } catch (IOException ex) {
        System.err.println(ex);
    } finally {
        try {
            in.close();
        } catch (Exception ex) {
            // We tried
        }
    }
}

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

public Integer getPort() {
    ByteBuffer portBB = ByteBuffer.wrap(this.getPortId().getValue());
    portBB.position(1);// w w  w .j a  va2  s  .c om
    return portBB.getInt();
}

From source file:io.druid.query.aggregation.HyperloglogAggregatorFactory.java

@Override
public Object deserialize(Object object) {
    log.debug("class name: [%s]:value [%s]", object.getClass().getName(), object);

    final String k = (String) object;
    final byte[] ibmapByte = Base64.decodeBase64(k);

    final ByteBuffer buffer = ByteBuffer.wrap(ibmapByte);
    final int keylength = buffer.getInt();
    final int valuelength = buffer.getInt();

    TIntByteHashMap newIbMap;//from  ww  w. j a v  a  2 s.com

    if (keylength == 0) {
        newIbMap = new TIntByteHashMap();
    } else {
        final int[] keys = new int[keylength];
        final byte[] values = new byte[valuelength];

        for (int i = 0; i < keylength; i++) {
            keys[i] = buffer.getInt();
        }
        buffer.get(values);

        newIbMap = new TIntByteHashMap(keys, values);
    }

    return newIbMap;
}

From source file:edu.umass.cs.gigapaxos.paxospackets.PValuePacket.java

protected PValuePacket(ByteBuffer bbuf) throws UnsupportedEncodingException, UnknownHostException {
    super(bbuf);/* w w  w  .  j  av a  2 s .c  o m*/
    this.ballot = new Ballot(bbuf.getInt(), bbuf.getInt());
    this.recovery = bbuf.get() == (byte) 1;
    this.medianCheckpointedSlot = bbuf.getInt();
    this.noCoalesce = bbuf.get() == (byte) 1;
}

From source file:org.commoncrawl.hadoop.mergeutils.MergeSortSpillWriter.java

private static final int compareUsingRawComparator(RawKeyValueComparator comparator, byte[] keyValueData1,
        int offset1, byte[] keyValueData2, int offset2) throws IOException {

    ByteBuffer buffer = ByteBuffer.wrap(keyValueData1);
    int testKey1Length = buffer.getInt();
    int key1Length = getIntB(keyValueData1, offset1);
    int key1Offset = offset1 + 4;
    int value1Offset = key1Offset + key1Length + 4;

    int value1Length = getIntB(keyValueData1, key1Offset + key1Length);

    int key2Length = getIntB(keyValueData2, offset2);
    int key2Offset = offset2 + 4;
    int value2Offset = key2Offset + key2Length + 4;
    int value2Length = getIntB(keyValueData2, key2Offset + key2Length);

    return comparator.compareRaw(keyValueData1, key1Offset, key1Length, keyValueData2, key2Offset, key2Length,
            keyValueData1, value1Offset, value1Length, keyValueData2, value2Offset, value2Length);
}

From source file:net.jenet.Header.java

public void fromBuffer(ByteBuffer buffer) {
    peerID = buffer.getShort();/* w  w  w  .  ja  v a2 s . co m*/
    flags = buffer.get();
    commandCount = buffer.get();
    sentTime = buffer.getInt();
    challenge = buffer.getInt();
}

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

private void parse(final ByteBuffer data) {
    final BigInteger controlFlags = BigInteger.valueOf(data.getInt());

    this.i2cPlugAndPlay = controlFlags.testBit(31);
    this.i2cHumidityChangeRequest = controlFlags.testBit(25);
    this.i2cTemperatureChangeRequest = controlFlags.testBit(24);
    this.motionSensorChangeRequest = controlFlags.testBit(11);
    this.keepAlive = controlFlags.testBit(10);
    this.changeFilter = controlFlags.testBit(9);
    this.frameAcknowledgement = controlFlags.testBit(8);
    this.volumeChangeRequest = controlFlags.testBit(5);
    this.pageChangeRequest = controlFlags.testBit(4);
    this.audioActiveChangeRequest = controlFlags.testBit(3);
    this.displayActiveChangeRequest = controlFlags.testBit(2);
    this.proximitySensorChangeRequest = controlFlags.testBit(1);
    this.lightSensorChangeRequest = controlFlags.testBit(0);

    boolean lockMode0 = controlFlags.testBit(12);
    boolean lockMode1 = controlFlags.testBit(13);
    if (lockMode0) {
        if (lockMode1) {
            this.lockMode = LockMode.ALL_LOGO;
        } else {/*  w  ww.j av a 2s  .  c  o m*/
            this.lockMode = LockMode.ALL; // TODO verify
        }
    } else {
        if (lockMode1) {
            this.lockMode = LockMode.NAVIGATION; // TODO verify
        } else {
            this.lockMode = LockMode.NONE;
        }
    }

    boolean backgroundLight0 = controlFlags.testBit(14);
    boolean backgroundLight1 = controlFlags.testBit(15);
    if (backgroundLight0) {
        if (backgroundLight1) {
            this.backgroundLight = BackgroundLight.ON;
        } else {
            this.backgroundLight = BackgroundLight.OFF; // TODO verify
        }
    } else {
        if (backgroundLight1) {
            this.backgroundLight = BackgroundLight.AUTO_NIGHT; // TODO
            // verify
        } else {
            this.backgroundLight = BackgroundLight.AUTO_DAY;
        }
    }
}