List of usage examples for java.nio ByteBuffer putShort
public abstract ByteBuffer putShort(short value);
From source file:org.getspout.spoutapi.packet.PacketCustomBlockChunkOverride.java
public PacketCustomBlockChunkOverride(short[] customIds, byte[] customData, int x, int z) { chunkX = x;//from w w w.ja v a 2 s . c o m chunkZ = z; if (customIds != null) { ByteBuffer buffer = ByteBuffer.allocate(customIds.length * 3); for (int i = 0; i < customIds.length; i++) { buffer.putShort(customIds[i]); buffer.put(customData == null ? 0 : customData[i]); } data = buffer.array(); hasData = true; } }
From source file:net.jenet.Connect.java
@Override public void toBuffer(ByteBuffer buffer) { super.toBuffer(buffer); buffer.putShort(outgoingPeerID); buffer.putShort(mtu);/* w w w. java2 s. c o m*/ buffer.putInt(windowSize); buffer.putInt(channelCount); buffer.putInt(incomingBandwidth); buffer.putInt(outgoingBandwidth); buffer.putInt(packetThrottleInterval); buffer.putInt(packetThrottleAcceleration); buffer.putInt(packetThrottleDeceleration); }
From source file:org.getspout.spoutapi.packet.PacketCustomMultiBlockOverride.java
public PacketCustomMultiBlockOverride(TIntArrayList xCoords, TIntArrayList yCoords, TIntArrayList zCoords, TIntArrayList blockTypeIds, TByteArrayList blockData) { short size = (short) xCoords.size(); ByteBuffer rawData = ByteBuffer.allocate(size * 7); chunkX = xCoords.get(0) >> 4;// w w w .jav a 2 s. co m chunkZ = zCoords.get(0) >> 4; for (int i = 0; i < size; i++) { rawData.put((byte) (xCoords.get(i) - chunkX * 16)); rawData.putShort((short) yCoords.get(i)); rawData.put((byte) (zCoords.get(i) - chunkZ * 16)); rawData.putShort((short) blockTypeIds.get(i)); rawData.put(blockData.get(i)); } data = rawData.array(); }
From source file:com.offbynull.portmapper.pcp.MapPcpRequest.java
@Override protected void dumpOpCodeSpecificInformation(ByteBuffer dst) { dst.put(mappingNonce.asReadOnlyBuffer()); dst.put((byte) protocol); for (int i = 0; i < 3; i++) { // reserved block dst.put((byte) 0); }// w w w .j ava 2 s .c om dst.putShort((short) internalPort); dst.putShort((short) suggestedExternalPort); dst.put(NetworkUtils.convertToIpv6Array(suggestedExternalIpAddress)); }
From source file:org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6FlowMod.java
/** * This method forms the Vendor extension IPv6 Flow Mod message.It uses the * fields in V6FlowMod class, and writes the data according to vendor * extension format. The fields include flow properties (cookie, timeout, * priority, etc), flow match, and action list. It also takes care of * required padding.// ww w .ja va 2 s.co m */ @Override public void writeTo(ByteBuffer data) { super.writeTo(data); data.putInt(getIPv6ExtensionFlowModAddSubType()); data.putLong(this.cookie); data.putShort(command); /* should be OFPFC_ADD, OFPFC_DELETE_STRICT, etc*/ data.putShort(this.idleTimeout); data.putShort(this.hardTimeout); data.putShort(this.priority); data.putInt(OFPacketOut.BUFFER_ID_NONE); data.putShort(outPort); /* output_port */ data.putShort(flags); /* flags */ match_len = this.match.getIPv6MatchLen(); data.putShort(match_len); byte[] pad = new byte[6]; data.put(pad); this.match.writeTo(data); pad_size = (short) (((match_len + 7) / 8) * 8 - match_len); /* * action list should be preceded by a padding of 0 to 7 bytes based upon * above formula. */ byte[] pad2 = new byte[pad_size]; data.put(pad2); if (actions != null) { for (OFAction action : actions) { actions_len += action.getLength(); action.writeTo(data); } } logger.trace("{}", this); }
From source file:com.linkedin.pinot.core.startree.MmapLinkedListStarTreeTable.java
@Override protected ByteBuffer toByteBuffer(StarTreeTableRow row) { ByteBuffer buffer = getNextBuffer(); for (int i = 0; i < dimensionTypes.size(); i++) { buffer.putInt(row.getDimensions().get(i)); }/*from w w w . j a v a2 s .c o m*/ for (int i = 0; i < metricTypes.size(); i++) { switch (metricTypes.get(i)) { case SHORT: buffer.putShort(row.getMetrics().get(i).shortValue()); break; case INT: buffer.putInt(row.getMetrics().get(i).intValue()); break; case LONG: buffer.putLong(row.getMetrics().get(i).longValue()); break; case FLOAT: buffer.putFloat(row.getMetrics().get(i).floatValue()); break; case DOUBLE: buffer.putDouble(row.getMetrics().get(i).doubleValue()); break; default: throw new IllegalArgumentException("Unsupported metric type " + metricTypes.get(i)); } } return buffer; }
From source file:com.offbynull.portmapper.pcp.PeerPcpRequest.java
@Override protected void dumpOpCodeSpecificInformation(ByteBuffer dst) { dst.put(mappingNonce.asReadOnlyBuffer()); dst.put((byte) protocol); for (int i = 0; i < 3; i++) { // reserved block dst.put((byte) 0); }// w w w . jav a2 s . co m dst.putShort((short) internalPort); dst.putShort((short) suggestedExternalPort); dst.put(NetworkUtils.convertToIpv6Array(suggestedExternalIpAddress)); dst.putShort((short) remotePeerPort); for (int i = 0; i < 2; i++) { // reserved block dst.put((byte) 0); } dst.put(NetworkUtils.convertToIpv6Array(remotePeerIpAddress)); }
From source file:org.apache.kylin.storage.hbase.cube.v1.filter.TestFuzzyRowFilterV2EndToEnd.java
@SuppressWarnings("unchecked") private void runTest(HTable hTable, int expectedSize) throws IOException { // [0, 2, ?, ?, ?, ?, 0, 0, 0, 1] byte[] fuzzyKey1 = new byte[10]; ByteBuffer buf = ByteBuffer.wrap(fuzzyKey1); buf.clear();/*w w w .ja v a 2 s. com*/ buf.putShort((short) 2); for (int i = 0; i < 4; i++) buf.put(fuzzyValue); buf.putInt((short) 1); byte[] mask1 = new byte[] { 0, 0, 1, 1, 1, 1, 0, 0, 0, 0 }; byte[] fuzzyKey2 = new byte[10]; buf = ByteBuffer.wrap(fuzzyKey2); buf.clear(); buf.putShort((short) 2); buf.putInt((short) 2); for (int i = 0; i < 4; i++) buf.put(fuzzyValue); byte[] mask2 = new byte[] { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1 }; Pair<byte[], byte[]> pair1 = Pair.newPair(fuzzyKey1, mask1); Pair<byte[], byte[]> pair2 = Pair.newPair(fuzzyKey2, mask2); FuzzyRowFilterV2 fuzzyRowFilter1 = new FuzzyRowFilterV2(Lists.newArrayList(pair1)); FuzzyRowFilterV2 fuzzyRowFilter2 = new FuzzyRowFilterV2(Lists.newArrayList(pair2)); // regular test - we expect 1 row back (5 KVs) runScanner(hTable, expectedSize, fuzzyRowFilter1, fuzzyRowFilter2); }
From source file:org.apache.hadoop.hbase.filter.TestFuzzyRowFilterEndToEnd.java
@SuppressWarnings("unchecked") private void runTest(Table hTable, int expectedSize) throws IOException { // [0, 2, ?, ?, ?, ?, 0, 0, 0, 1] byte[] fuzzyKey1 = new byte[10]; ByteBuffer buf = ByteBuffer.wrap(fuzzyKey1); buf.clear();//w ww .ja va 2 s .co m buf.putShort((short) 2); for (int i = 0; i < 4; i++) buf.put(fuzzyValue); buf.putInt((short) 1); byte[] mask1 = new byte[] { 0, 0, 1, 1, 1, 1, 0, 0, 0, 0 }; byte[] fuzzyKey2 = new byte[10]; buf = ByteBuffer.wrap(fuzzyKey2); buf.clear(); buf.putShort((short) 2); buf.putInt((short) 2); for (int i = 0; i < 4; i++) buf.put(fuzzyValue); byte[] mask2 = new byte[] { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1 }; Pair<byte[], byte[]> pair1 = new Pair<byte[], byte[]>(fuzzyKey1, mask1); Pair<byte[], byte[]> pair2 = new Pair<byte[], byte[]>(fuzzyKey2, mask2); FuzzyRowFilter fuzzyRowFilter1 = new FuzzyRowFilter(Lists.newArrayList(pair1)); FuzzyRowFilter fuzzyRowFilter2 = new FuzzyRowFilter(Lists.newArrayList(pair2)); // regular test - we expect 1 row back (5 KVs) runScanner(hTable, expectedSize, fuzzyRowFilter1, fuzzyRowFilter2); }
From source file:org.apache.kylin.storage.hbase.cube.v1.filter.TestFuzzyRowFilterV2EndToEnd.java
private void runTest1(HTable hTable) throws IOException { // [0, 2, ?, ?, ?, ?, 0, 0, 0, 1] byte[] mask = new byte[] { 0, 0, 1, 1, 1, 1, 0, 0, 0, 0 }; List<Pair<byte[], byte[]>> list = new ArrayList<Pair<byte[], byte[]>>(); for (int i = 0; i < totalFuzzyKeys; i++) { byte[] fuzzyKey = new byte[10]; ByteBuffer buf = ByteBuffer.wrap(fuzzyKey); buf.clear();// w w w . j av a 2s . c o m buf.putShort((short) 2); for (int j = 0; j < 4; j++) { buf.put(fuzzyValue); } buf.putInt(i); Pair<byte[], byte[]> pair = Pair.newPair(fuzzyKey, mask); list.add(pair); } int expectedSize = secondPartCardinality * totalFuzzyKeys * colQualifiersTotal; FuzzyRowFilterV2 fuzzyRowFilter0 = new FuzzyRowFilterV2(list); // Filters are not stateless - we can't reuse them FuzzyRowFilterV2 fuzzyRowFilter1 = new FuzzyRowFilterV2(list); // regular test runScanner(hTable, expectedSize, fuzzyRowFilter0); // optimized from block cache runScanner(hTable, expectedSize, fuzzyRowFilter1); }