List of usage examples for java.nio ByteBuffer putShort
public abstract ByteBuffer putShort(short value);
From source file:org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6Match.java
private byte[] getIPv6ExtensionEtherTypeMatchMsg(short EtherType) { ByteBuffer ipv6ext_etype_msg = ByteBuffer.allocate(6); int nxm_header = getIPv6ExtensionMatchHeader(Extension_Types.OF_10, OF_Match_Types.MATCH_OF_ETH_TYPE.getValue(), 0, 2); ipv6ext_etype_msg.putInt(nxm_header); ipv6ext_etype_msg.putShort(EtherType); return (ipv6ext_etype_msg.array()); }
From source file:org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6Match.java
private byte[] getIPv6ExtensionVlanIDMatchMsg(short VLAN) { ByteBuffer ipv6ext_vlanid_msg = ByteBuffer.allocate(6); int nxm_header = getIPv6ExtensionMatchHeader(Extension_Types.OF_10, OF_Match_Types.MATCH_OF_VLAN_TCI.getValue(), 0, 2); ipv6ext_vlanid_msg.putInt(nxm_header); ipv6ext_vlanid_msg.putShort(VLAN); return (ipv6ext_vlanid_msg.array()); }
From source file:org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6Match.java
private byte[] getIPv6ExtensionTCPSrcPortMatchMsg(short src_port) { ByteBuffer ipv6ext_tcp_srcport_msg = ByteBuffer.allocate(6); int nxm_header = getIPv6ExtensionMatchHeader(Extension_Types.OF_10, OF_Match_Types.MATCH_OF_TCP_SRC.getValue(), 0, 2); ipv6ext_tcp_srcport_msg.putInt(nxm_header); ipv6ext_tcp_srcport_msg.putShort(src_port); return (ipv6ext_tcp_srcport_msg.array()); }
From source file:org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6Match.java
private byte[] getIPv6ExtensionTCPDstPortMatchMsg(short dst_port) { ByteBuffer ipv6ext_tcp_dstport_msg = ByteBuffer.allocate(6); int nxm_header = getIPv6ExtensionMatchHeader(Extension_Types.OF_10, OF_Match_Types.MATCH_OF_TCP_DST.getValue(), 0, 2); ipv6ext_tcp_dstport_msg.putInt(nxm_header); ipv6ext_tcp_dstport_msg.putShort(dst_port); return (ipv6ext_tcp_dstport_msg.array()); }
From source file:org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6Match.java
private byte[] getIPv6ExtensionUDPSrcPortMatchMsg(short src_port) { ByteBuffer ipv6ext_udp_srcport_msg = ByteBuffer.allocate(6); int nxm_header = getIPv6ExtensionMatchHeader(Extension_Types.OF_10, OF_Match_Types.MATCH_OF_UDP_SRC.getValue(), 0, 2); ipv6ext_udp_srcport_msg.putInt(nxm_header); ipv6ext_udp_srcport_msg.putShort(src_port); return (ipv6ext_udp_srcport_msg.array()); }
From source file:org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6Match.java
private byte[] getIPv6ExtensionUDPDstPortMatchMsg(short dst_port) { ByteBuffer ipv6ext_udp_dstport_msg = ByteBuffer.allocate(6); int nxm_header = getIPv6ExtensionMatchHeader(Extension_Types.OF_10, OF_Match_Types.MATCH_OF_UDP_DST.getValue(), 0, 2); ipv6ext_udp_dstport_msg.putInt(nxm_header); ipv6ext_udp_dstport_msg.putShort(dst_port); return (ipv6ext_udp_dstport_msg.array()); }
From source file:com.healthmarketscience.jackcess.impl.ColumnImpl.java
/** * Writes the column definitions into a table definition buffer. * @param buffer Buffer to write to//from www . j a v a 2s . c o m */ protected static void writeDefinitions(TableCreator creator, ByteBuffer buffer) throws IOException { List<ColumnBuilder> columns = creator.getColumns(); short fixedOffset = (short) 0; short variableOffset = (short) 0; // we specifically put the "long variable" values after the normal // variable length values so that we have a better chance of fitting it // all (because "long variable" values can go in separate pages) short longVariableOffset = countNonLongVariableLength(columns); for (ColumnBuilder col : columns) { buffer.put(col.getType().getValue()); buffer.putInt(TableImpl.MAGIC_TABLE_NUMBER); //constant magic number buffer.putShort(col.getColumnNumber()); //Column Number if (col.isVariableLength()) { if (!col.getType().isLongValue()) { buffer.putShort(variableOffset++); } else { buffer.putShort(longVariableOffset++); } } else { buffer.putShort((short) 0); } buffer.putShort(col.getColumnNumber()); //Column Number again if (col.getType().isTextual()) { // this will write 4 bytes (note we don't support writing dbs which // use the text code page) writeSortOrder(buffer, col.getTextSortOrder(), creator.getFormat()); } else { // note scale/precision not stored for calculated numeric fields if (col.getType().getHasScalePrecision() && !col.isCalculated()) { buffer.put(col.getPrecision()); // numeric precision buffer.put(col.getScale()); // numeric scale } else { buffer.put((byte) 0x00); //unused buffer.put((byte) 0x00); //unused } buffer.putShort((short) 0); //Unknown } buffer.put(getColumnBitFlags(col)); // misc col flags // note access doesn't seem to allow unicode compression for calced fields if (col.isCalculated()) { buffer.put(CALCULATED_EXT_FLAG_MASK); } else if (col.isCompressedUnicode()) { //Compressed buffer.put(COMPRESSED_UNICODE_EXT_FLAG_MASK); } else { buffer.put((byte) 0); } buffer.putInt(0); //Unknown, but always 0. //Offset for fixed length columns if (col.isVariableLength()) { buffer.putShort((short) 0); } else { buffer.putShort(fixedOffset); fixedOffset += col.getType().getFixedSize(col.getLength()); } if (!col.getType().isLongValue()) { short length = col.getLength(); if (col.isCalculated()) { // calced columns have additional value overhead if (!col.getType().isVariableLength() || col.getType().getHasScalePrecision()) { length = CalculatedColumnUtil.CALC_FIXED_FIELD_LEN; } else { length += CalculatedColumnUtil.CALC_EXTRA_DATA_LEN; } } buffer.putShort(length); //Column length } else { buffer.putShort((short) 0x0000); // unused } } for (ColumnBuilder col : columns) { TableImpl.writeName(buffer, col.getName(), creator.getCharset()); } }
From source file:com.healthmarketscience.jackcess.impl.TableImpl.java
/** * Writes the given name into the given buffer in the format as expected by * {@link #readName}.// ww w . j a v a 2 s . c om */ static void writeName(ByteBuffer buffer, String name, Charset charset) { ByteBuffer encName = ColumnImpl.encodeUncompressedText(name, charset); buffer.putShort((short) encName.remaining()); buffer.put(encName); }
From source file:com.healthmarketscience.jackcess.impl.IndexData.java
/** * Writes the data page info to the given buffer. *///from w ww . j av a 2 s . c o m protected static void writeDataPage(ByteBuffer buffer, DataPage dataPage, int tdefPageNumber, JetFormat format) throws IOException { buffer.put(dataPage.isLeaf() ? PageTypes.INDEX_LEAF : PageTypes.INDEX_NODE); //Page type buffer.put((byte) 0x01); //Unknown buffer.putShort((short) 0); //Free space buffer.putInt(tdefPageNumber); buffer.putInt(0); //Unknown buffer.putInt(dataPage.getPrevPageNumber()); //Prev page buffer.putInt(dataPage.getNextPageNumber()); //Next page buffer.putInt(dataPage.getChildTailPageNumber()); //ChildTail page byte[] entryPrefix = dataPage.getEntryPrefix(); buffer.putShort((short) entryPrefix.length); // entry prefix byte count buffer.put((byte) 0); //Unknown byte[] entryMask = new byte[format.SIZE_INDEX_ENTRY_MASK]; // first entry includes the prefix int totalSize = entryPrefix.length; for (Entry entry : dataPage.getEntries()) { totalSize += (entry.size() - entryPrefix.length); int idx = totalSize / 8; entryMask[idx] |= (1 << (totalSize % 8)); } buffer.put(entryMask); // first entry includes the prefix buffer.put(entryPrefix); for (Entry entry : dataPage.getEntries()) { entry.write(buffer, entryPrefix); } // update free space buffer.putShort(2, (short) (format.PAGE_SIZE - buffer.position())); }
From source file:org.opendaylight.lispflowmapping.lisp.serializer.MapRequestSerializer.java
public ByteBuffer serialize(MapRequest mapRequest) { int size = Length.HEADER_SIZE; if (mapRequest.getSourceEid() != null && mapRequest.getSourceEid().getEid() != null) { size += LispAddressSerializer.getInstance().getAddressSize(mapRequest.getSourceEid().getEid()); } else {// ww w. j a v a 2s. co m size += 2; } if (mapRequest.getItrRloc() != null) { for (ItrRloc address : mapRequest.getItrRloc()) { size += LispAddressSerializer.getInstance().getAddressSize(address.getRloc()); } } if (mapRequest.getEidItem() != null) { for (EidItem record : mapRequest.getEidItem()) { size += 2 + LispAddressSerializer.getInstance().getAddressSize(record.getEid()); } } ByteBuffer requestBuffer = ByteBuffer.allocate(size); requestBuffer.put((byte) ((byte) (MessageType.MapRequest.getIntValue() << 4) | ByteUtil.boolToBit(BooleanUtils.isTrue(mapRequest.isAuthoritative()), Flags.AUTHORITATIVE) | ByteUtil.boolToBit(BooleanUtils.isTrue(mapRequest.isMapDataPresent()), Flags.MAP_DATA_PRESENT) | ByteUtil.boolToBit(BooleanUtils.isTrue(mapRequest.isProbe()), Flags.PROBE) | ByteUtil.boolToBit(BooleanUtils.isTrue(mapRequest.isSmr()), Flags.SMR))); requestBuffer.put((byte) (ByteUtil.boolToBit(BooleanUtils.isTrue(mapRequest.isPitr()), Flags.PITR) | ByteUtil.boolToBit(BooleanUtils.isTrue(mapRequest.isSmrInvoked()), Flags.SMR_INVOKED))); if (mapRequest.getItrRloc() != null) { int IRC = mapRequest.getItrRloc().size(); if (IRC > 0) { IRC--; } requestBuffer.put((byte) (IRC)); } else { requestBuffer.put((byte) 0); } if (mapRequest.getEidItem() != null) { requestBuffer.put((byte) mapRequest.getEidItem().size()); } else { requestBuffer.put((byte) 0); } requestBuffer.putLong(NumberUtil.asLong(mapRequest.getNonce())); if (mapRequest.getSourceEid() != null && mapRequest.getSourceEid().getEid() != null) { LispAddressSerializer.getInstance().serialize(requestBuffer, mapRequest.getSourceEid().getEid()); } else { requestBuffer.putShort((short) 0); } if (mapRequest.getItrRloc() != null) { for (ItrRloc address : mapRequest.getItrRloc()) { LispAddressSerializer.getInstance().serialize(requestBuffer, address.getRloc()); } } if (mapRequest.getEidItem() != null) { for (EidItem record : mapRequest.getEidItem()) { requestBuffer.put((byte) 0); requestBuffer.put((byte) MaskUtil.getMaskForAddress(record.getEid().getAddress())); LispAddressSerializer.getInstance().serialize(requestBuffer, record.getEid()); } } if (mapRequest.getMapReply() != null) { ByteBuffer replyBuffer = ByteBuffer.allocate(MappingRecordSerializer.getInstance() .getSerializationSize(mapRequest.getMapReply().getMappingRecord())); MappingRecordSerializer.getInstance().serialize(replyBuffer, mapRequest.getMapReply().getMappingRecord()); ByteBuffer combinedBuffer = ByteBuffer.allocate(requestBuffer.capacity() + replyBuffer.capacity()); combinedBuffer.put(requestBuffer.array()); combinedBuffer.put(replyBuffer.array()); return combinedBuffer; } return requestBuffer; }