Example usage for java.nio ByteBuffer getShort

List of usage examples for java.nio ByteBuffer getShort

Introduction

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

Prototype

public abstract short getShort();

Source Link

Document

Returns the short at the current position and increases the position by 2.

Usage

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

private void readTcpSrc(ByteBuffer data, int nxmLen, boolean hasMask) {
    /*//  w  ww . java2  s.  c  om
     * mask is not allowed in TCP SRC
     */
    if ((nxmLen != 2) || (data.remaining() < 2) || (hasMask))
        return;
    super.setTransportSource(data.getShort());
    this.tpSrcState = MatchFieldState.MATCH_FIELD_ONLY;
    this.match_len += 6;
    this.wildcards ^= (1 << 6); // Sync with 0F 1.0 Match
}

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

private void readUdpSrc(ByteBuffer data, int nxmLen, boolean hasMask) {
    /*//from w  ww  .ja v a  2s  .  co m
     * mask is not allowed in UDP SRC
     */
    if ((nxmLen != 2) || (data.remaining() < 2) || (hasMask))
        return;
    super.setTransportSource(data.getShort());
    this.tpSrcState = MatchFieldState.MATCH_FIELD_ONLY;
    this.match_len += 6;
    this.wildcards ^= (1 << 6); // Sync with 0F 1.0 Match
}

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

private void readTcpDst(ByteBuffer data, int nxmLen, boolean hasMask) {
    /*/*  www.  j  ava2s. c o  m*/
     * mask is not allowed in TCP DST
     */
    if ((nxmLen != 2) || (data.remaining() < 2) || (hasMask))
        return;
    super.setTransportDestination(data.getShort());
    this.tpDstState = MatchFieldState.MATCH_FIELD_ONLY;
    this.match_len += 6;
    this.wildcards ^= (1 << 7); // Sync with 0F 1.0 Match
}

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

private void readUdpDst(ByteBuffer data, int nxmLen, boolean hasMask) {
    /*//from  ww w . j ava  2s.c o m
     * mask is not allowed in UDP DST
     */
    if ((nxmLen != 2) || (data.remaining() < 2) || (hasMask))
        return;
    super.setTransportDestination(data.getShort());
    this.tpDstState = MatchFieldState.MATCH_FIELD_ONLY;
    this.match_len += 6;
    this.wildcards ^= (1 << 7); // Sync with 0F 1.0 Match
}

From source file:de.hpi.fgis.hdrs.Triple.java

public void readFields(ByteBuffer header, ByteBuffer data) {
    // read header
    Slen = header.getShort();
    Plen = header.getShort();//from  w  w w. j av  a 2 s  .com
    Olen = header.getInt();
    multiplicity = header.getInt();
    // read data
    this.buffer = data.array();
    int size = (int) Slen + (int) Plen + Olen;
    offset = data.arrayOffset() + data.position();
    data.position(data.position() + size);
}

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

private void readInPort(ByteBuffer data, int nxmLen, boolean hasMask) {
    if ((nxmLen != 2) || (data.remaining() < 2) || (hasMask))
        /*//w  w  w  .j a  v a 2 s  .  co  m
         * mask is not allowed for inport port
         */
        return;
    super.setInputPort(data.getShort());
    this.inputPortState = MatchFieldState.MATCH_FIELD_ONLY;
    this.wildcards ^= (1 << 0); // Sync with 0F 1.0 Match
    this.match_len += 6;
}

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

private void readVlanTci(ByteBuffer data, int nxmLen, boolean hasMask) {
    short vlan_mask = 0xfff;
    if (hasMask) {
        if ((nxmLen != 2 * 2) || (data.remaining() < 2 * 2))
            return;
        else {//from w ww.  j  ava 2s. c o  m
            short vlan = data.getShort();
            vlan &= vlan_mask;
            super.setDataLayerVirtualLan(vlan);
            this.dataLayerVirtualLanMask = data.getShort();
            this.dlVlanState = MatchFieldState.MATCH_FIELD_WITH_MASK;
            this.match_len += 8;
            this.wildcards ^= (1 << 20);
        }
    } else {
        if ((nxmLen != 2) || (data.remaining() < 2))
            return;
        else {
            short vlan = data.getShort();
            vlan &= vlan_mask;
            super.setDataLayerVirtualLan(vlan);
            this.dlVlanState = MatchFieldState.MATCH_FIELD_ONLY;
            this.match_len += 6;
        }
    }

    this.wildcards ^= (1 << 1); // Sync with 0F 1.0 Match
}

From source file:org.apache.carbondata.core.indexstore.blockletindex.BlockDataMap.java

/**
 * Method to get the relative blocklet ID. Absolute blocklet ID is the blocklet Id as per
 * task level but relative blocklet ID is id as per carbondata file/block level
 *
 * @param absoluteBlockletId//from ww w.  j av  a 2  s  .  co m
 * @return
 */
private ExtendedBlocklet createBlockletFromRelativeBlockletId(int absoluteBlockletId) {
    short relativeBlockletId = -1;
    int rowIndex = 0;
    // return 0 if absoluteBlockletId is 0
    if (absoluteBlockletId == 0) {
        relativeBlockletId = (short) absoluteBlockletId;
    } else {
        int diff = absoluteBlockletId;
        ByteBuffer byteBuffer = ByteBuffer.wrap(getBlockletRowCountForEachBlock());
        // Example: absoluteBlockletID = 17, blockletRowCountForEachBlock = {4,3,2,5,7}
        // step1: diff = 17-4, diff = 13
        // step2: diff = 13-3, diff = 10
        // step3: diff = 10-2, diff = 8
        // step4: diff = 8-5, diff = 3
        // step5: diff = 3-7, diff = -4 (satisfies <= 0)
        // step6: relativeBlockletId = -4+7, relativeBlockletId = 3 (4th index starting from 0)
        while (byteBuffer.hasRemaining()) {
            short blockletCount = byteBuffer.getShort();
            diff = diff - blockletCount;
            if (diff < 0) {
                relativeBlockletId = (short) (diff + blockletCount);
                break;
            }
            rowIndex++;
        }
    }
    DataMapRow row = memoryDMStore.getDataMapRow(getFileFooterEntrySchema(), rowIndex);
    String filePath = getFilePath();
    return createBlocklet(row, getFileNameWithFilePath(row, filePath), relativeBlockletId, false);
}

From source file:com.sonymobile.android.media.internal.VUParser.java

protected boolean parseODSMData(IsoTrack odsmTrack) {
    int kObjectSize = 11;
    SampleTable sampleTable = odsmTrack.getSampleTable();
    if (sampleTable.getSampleCount() > 1) {
        // TODO: Should multiple entries be supported?
        return false;
    }/*w  ww . ja va2s  . c  om*/
    mSinfList = new ArrayList<SinfData>(2);

    ByteBuffer stszData = sampleTable.getStszData();
    stszData.rewind();
    stszData.getInt(); // version and flags

    int dataSize = stszData.getInt();
    if (dataSize == 0) {
        stszData.getInt(); // sample_count
        dataSize = stszData.getInt();
    }

    byte[] data = new byte[dataSize];
    try {
        ByteBuffer stcoData = sampleTable.getStcoData();
        stcoData.rewind();

        stcoData.getInt(); // version and flags
        stcoData.getInt(); // entry_count

        long sampleOffset = 0;
        if (sampleTable.isUsingLongChunkOffsets()) {
            sampleOffset = stcoData.getLong();
        } else {
            sampleOffset = 0xFFFFFFFFL & stcoData.getInt();
        }

        mDataSource.readAt(sampleOffset, data, dataSize);
        ByteBuffer dataBuffer = ByteBuffer.wrap(data);
        byte updateTag = dataBuffer.get();
        if (updateTag != 1) {
            return false;
        }
        int size = 0;
        int sizePart = 0;
        do {
            sizePart = (dataBuffer.get() & 0xFF);
            size = ((size << 7) & 0xFFFFFF80) | (sizePart & 0x7F);
        } while (sizePart > 128);
        while (size >= kObjectSize) {
            byte descriptorTag = dataBuffer.get();
            if (descriptorTag != 17) {
                // not mp4 descriptor
                return false;
            }
            dataBuffer.get(); // ODLength
            dataBuffer.getShort(); // 10 bit ObjectDescriptorID, 1 bit
                                   // URL_FLAG and 5 bit reserved

            byte esTag = dataBuffer.get();
            if (esTag != 0x0F) {
                return false;
            }
            dataBuffer.get(); // ES Length
            short esTrackReferenceIndex = dataBuffer.getShort();
            byte ipmpDescriptorPointer = dataBuffer.get();
            if (ipmpDescriptorPointer != 0x0A) {
                // unexpected pointer
                return false;
            }
            dataBuffer.get(); // ipmpLength
            byte ipmpDescriptorId = dataBuffer.get();
            SinfData sinfData = new SinfData();
            sinfData.esIdReference = esTrackReferenceIndex;
            sinfData.ipmpDescriptorId = ipmpDescriptorId;
            mSinfList.add(sinfData);
            size -= kObjectSize;
        }
        dataBuffer.get(); // IPMP Descriptor Update Tag
        int sinfCount = mSinfList.size();
        size = 0;
        sizePart = 0;
        do {
            sizePart = (dataBuffer.get() & 0xFF);
            size = ((size << 7) & 0xFFFFFF80) | (sizePart & 0x7F);
        } while (sizePart > 128);
        while (size > 0) {
            dataBuffer.get(); // IPMP Descriptor Tag
            int ipmpByteCount = 1;
            int ipmpLength = 0;
            sizePart = 0;
            do {
                sizePart = (dataBuffer.get() & 0xFF);
                ipmpByteCount++;
                ipmpLength = ((ipmpLength << 7) & 0xFFFFFF80) | (sizePart & 0x7F);
            } while (sizePart > 128);
            ipmpByteCount += ipmpLength;
            byte ipmpDescriptorId = dataBuffer.get();
            dataBuffer.getShort(); // IPMPS Type
            byte[] ipmpData = new byte[ipmpLength - 3];
            dataBuffer.get(ipmpData);
            SinfData sinfData = null;
            for (int i = 0; i < sinfCount; i++) {
                sinfData = mSinfList.get(i);
                if (sinfData.ipmpDescriptorId == ipmpDescriptorId) {
                    sinfData.ipmpData = new byte[ipmpData.length];
                    for (int j = 0; j < ipmpData.length; j++) {
                        sinfData.ipmpData[j] = ipmpData[j];
                    }
                    break;
                }
            }
            size -= ipmpByteCount;
        }
        int ipmpDataLength = 0;
        for (int i = 0; i < sinfCount; i++) {
            SinfData sinfData = mSinfList.get(i);
            ipmpDataLength += sinfData.ipmpData.length;
        }

        int ipmpMetaDataLength = 16 // MARLIN_SYSTEM_ID
                + 4 // size of all SINF data
                + 4 // size of SINF box id
                + 4 * sinfCount // trackIndex * sinfCount
                + 4 * sinfCount // ipmpLength * sinfCount
                + ipmpDataLength; // size of ipmpData
        byte[] ipmpMetaData = new byte[ipmpMetaDataLength];
        int offset = 16;

        for (int i = 0; i < offset; i++) {
            int hexVal = Integer.parseInt(Util.MARLIN_SYSTEM_ID.substring(i * 2, i * 2 + 2), 16);
            ipmpMetaData[i] = (byte) hexVal;
        }
        ipmpMetaData[offset++] = (byte) ((ipmpDataLength >> 24) & 0xFF);
        ipmpMetaData[offset++] = (byte) ((ipmpDataLength >> 16) & 0xFF);
        ipmpMetaData[offset++] = (byte) ((ipmpDataLength >> 8) & 0xFF);
        ipmpMetaData[offset++] = (byte) (ipmpDataLength & 0xFF);
        ipmpMetaData[offset++] = 0x73; // S
        ipmpMetaData[offset++] = 0x69; // I
        ipmpMetaData[offset++] = 0x6E; // N
        ipmpMetaData[offset++] = 0x66; // F

        int numTracks = mTracks.size();
        for (int i = 0; i < numTracks; i++) {
            IsoTrack track = (IsoTrack) mTracks.get(i);
            for (int j = 0; j < sinfCount; j++) {
                SinfData sinfData = mSinfList.get(j);
                if (sinfData.esIdReference == track.getTrackId()) {
                    track.getMetaData().addValue(MetaData.KEY_IPMP_DATA, sinfData.ipmpData);
                    // track index
                    ipmpMetaData[offset++] = (byte) ((i >> 24) & 0xFF);
                    ipmpMetaData[offset++] = (byte) ((i >> 16) & 0xFF);
                    ipmpMetaData[offset++] = (byte) ((i >> 8) & 0xFF);
                    ipmpMetaData[offset++] = (byte) (i & 0xFF);

                    // sinf data length
                    ipmpMetaData[offset++] = (byte) ((sinfData.ipmpData.length >> 24) & 0xFF);
                    ipmpMetaData[offset++] = (byte) ((sinfData.ipmpData.length >> 16) & 0xFF);
                    ipmpMetaData[offset++] = (byte) ((sinfData.ipmpData.length >> 8) & 0xFF);
                    ipmpMetaData[offset++] = (byte) (sinfData.ipmpData.length & 0xFF);

                    System.arraycopy(sinfData.ipmpData, 0, ipmpMetaData, offset, sinfData.ipmpData.length);

                    byte[] tempData = new byte[4 + sinfData.ipmpData.length];
                    tempData[0] = (byte) ((sinfData.ipmpData.length >> 24) & 0xFF);
                    tempData[1] = (byte) ((sinfData.ipmpData.length >> 16) & 0xFF);
                    tempData[2] = (byte) ((sinfData.ipmpData.length >> 8) & 0xFF);
                    tempData[3] = (byte) (sinfData.ipmpData.length & 0xFF);
                    System.arraycopy(sinfData.ipmpData, 0, tempData, 4, sinfData.ipmpData.length);

                    // Create JSON for this track
                    String jsonData = null;
                    try {
                        jsonData = Util.getJSONIPMPData(tempData);
                    } catch (JSONException e) {
                        if (LOGS_ENABLED)
                            Log.e(TAG, "Exception when creating JSON object" + e);
                        return false;
                    }
                    track.getMediaFormat().setString(KEY_DRM_UUID, Util.MARLIN_SYSTEM_ID);
                    track.getMediaFormat().setString(KEY_MARLIN_JSON, jsonData);

                    offset += sinfData.ipmpData.length;
                    break;
                }
            }
        }

        mIpmpMetaData = ipmpMetaData;

        addMetaDataValue(KEY_IPMP_DATA, mIpmpMetaData);

        mCurrentTrack.getMetaData().addValue(KEY_MIME_TYPE, MimeType.OCTET_STREAM);

    } catch (IOException e) {
        if (LOGS_ENABLED)
            Log.e(TAG, "IOException when parsing ODSM data");
    }
    return true;
}

From source file:org.onosproject.dhcprelay.DhcpRelayManagerTest.java

private void buildRelayMsg(DHCP6 dhcp6Relay, byte msgType, Ip6Address linkAddr, Ip6Address peerAddr, byte hop,
        byte[] interfaceIdBytes, DHCP6 dhcp6Payload) {

    dhcp6Relay.setMsgType(msgType);//w  ww  . ja  v a 2  s .com

    dhcp6Relay.setLinkAddress(linkAddr.toOctets());
    dhcp6Relay.setPeerAddress(peerAddr.toOctets());
    dhcp6Relay.setHopCount(hop);
    List<Dhcp6Option> options = new ArrayList<Dhcp6Option>();

    // interfaceId  option
    Dhcp6Option interfaceId = new Dhcp6Option();
    interfaceId.setCode(DHCP6.OptionCode.INTERFACE_ID.value());

    interfaceId.setData(interfaceIdBytes);
    interfaceId.setLength((short) interfaceIdBytes.length);
    Dhcp6InterfaceIdOption interfaceIdOption = new Dhcp6InterfaceIdOption(interfaceId);
    byte[] optionData = interfaceIdOption.getData();
    ByteBuffer bb = ByteBuffer.wrap(interfaceIdBytes);

    byte[] macAddr = new byte[MacAddress.MAC_ADDRESS_LENGTH];
    byte[] port = new byte[optionData.length - MacAddress.MAC_ADDRESS_LENGTH - VLAN_LEN - SEPARATOR_LEN * 2];
    short vlan;
    bb.get(macAddr);
    bb.get(); // separator
    bb.get(port);
    bb.get(); // separator
    vlan = bb.getShort();
    interfaceIdOption.setMacAddress(MacAddress.valueOf(macAddr));
    interfaceIdOption.setInPort(port);
    interfaceIdOption.setVlanId(vlan);

    options.add(interfaceIdOption);

    // relay message option
    Dhcp6Option relayMsgOption = new Dhcp6Option();
    relayMsgOption.setCode(DHCP6.OptionCode.RELAY_MSG.value());
    byte[] dhcp6PayloadByte = dhcp6Payload.serialize();
    relayMsgOption.setLength((short) dhcp6PayloadByte.length);
    relayMsgOption.setPayload(dhcp6Payload);
    Dhcp6RelayOption relayOpt = new Dhcp6RelayOption(relayMsgOption);

    options.add(relayOpt);

    dhcp6Relay.setOptions(options);
}