List of usage examples for java.nio ByteBuffer getShort
public abstract short getShort();
From source file:org.apache.druid.hll.HyperLogLogCollectorTest.java
@Test public void testFoldWithDifferentOffsets1() { ByteBuffer biggerOffset = makeCollectorBuffer(1, (byte) 0x00, 0x11); ByteBuffer smallerOffset = makeCollectorBuffer(0, (byte) 0x20, 0x00); HyperLogLogCollector collector = HyperLogLogCollector.makeLatestCollector(); collector.fold(biggerOffset);/*ww w.j a va 2 s. c o m*/ collector.fold(smallerOffset); ByteBuffer outBuffer = collector.toByteBuffer(); Assert.assertEquals(outBuffer.get(), collector.getVersion()); Assert.assertEquals(outBuffer.get(), 1); Assert.assertEquals(outBuffer.getShort(), 2047); outBuffer.get(); outBuffer.getShort(); Assert.assertEquals(outBuffer.get(), 0x10); while (outBuffer.hasRemaining()) { Assert.assertEquals(outBuffer.get(), 0x11); } collector = HyperLogLogCollector.makeLatestCollector(); collector.fold(smallerOffset); collector.fold(biggerOffset); outBuffer = collector.toByteBuffer(); Assert.assertEquals(outBuffer.get(), collector.getVersion()); Assert.assertEquals(outBuffer.get(), 1); Assert.assertEquals(outBuffer.getShort(), 2047); Assert.assertEquals(outBuffer.get(), 0); Assert.assertEquals(outBuffer.getShort(), 0); Assert.assertEquals(outBuffer.get(), 0x10); while (outBuffer.hasRemaining()) { Assert.assertEquals(outBuffer.get(), 0x11); } }
From source file:org.apache.druid.hll.HyperLogLogCollectorTest.java
@Test public void testFoldWithArbitraryInitialPositions() { ByteBuffer biggerOffset = shiftedBuffer(makeCollectorBuffer(1, (byte) 0x00, 0x11), 10); ByteBuffer smallerOffset = shiftedBuffer(makeCollectorBuffer(0, (byte) 0x20, 0x00), 15); HyperLogLogCollector collector = HyperLogLogCollector.makeLatestCollector(); collector.fold(biggerOffset);//from w ww .j a v a 2 s.c o m collector.fold(smallerOffset); ByteBuffer outBuffer = collector.toByteBuffer(); Assert.assertEquals(outBuffer.get(), collector.getVersion()); Assert.assertEquals(outBuffer.get(), 1); Assert.assertEquals(outBuffer.getShort(), 2047); outBuffer.get(); outBuffer.getShort(); Assert.assertEquals(outBuffer.get(), 0x10); while (outBuffer.hasRemaining()) { Assert.assertEquals(outBuffer.get(), 0x11); } collector = HyperLogLogCollector.makeLatestCollector(); collector.fold(smallerOffset); collector.fold(biggerOffset); outBuffer = collector.toByteBuffer(); Assert.assertEquals(outBuffer.get(), collector.getVersion()); Assert.assertEquals(outBuffer.get(), 1); Assert.assertEquals(outBuffer.getShort(), 2047); outBuffer.get(); outBuffer.getShort(); Assert.assertEquals(outBuffer.get(), 0x10); while (outBuffer.hasRemaining()) { Assert.assertEquals(outBuffer.get(), 0x11); } }
From source file:org.apache.druid.hll.HyperLogLogCollectorTest.java
@Test public void testFoldWithUpperNibbleTriggersOffsetChange() { byte[] arr1 = new byte[HyperLogLogCollector.getLatestNumBytesForDenseStorage()]; Arrays.fill(arr1, (byte) 0x11); ByteBuffer buffer1 = ByteBuffer.wrap(arr1); buffer1.put(0, VersionOneHyperLogLogCollector.VERSION); buffer1.put(1, (byte) 0); buffer1.putShort(2, (short) (2047)); buffer1.put(VersionOneHyperLogLogCollector.HEADER_NUM_BYTES, (byte) 0x1); byte[] arr2 = new byte[HyperLogLogCollector.getLatestNumBytesForDenseStorage()]; Arrays.fill(arr2, (byte) 0x11); ByteBuffer buffer2 = ByteBuffer.wrap(arr2); buffer2.put(0, VersionOneHyperLogLogCollector.VERSION); buffer2.put(1, (byte) 0); buffer2.putShort(2, (short) (2048)); HyperLogLogCollector collector = HyperLogLogCollector.makeCollector(buffer1); collector.fold(buffer2);/* w w w.java 2 s . c o m*/ ByteBuffer outBuffer = collector.toByteBuffer(); Assert.assertEquals(outBuffer.get(), VersionOneHyperLogLogCollector.VERSION); Assert.assertEquals(outBuffer.get(), 1); Assert.assertEquals(outBuffer.getShort(), 0); outBuffer.get(); outBuffer.getShort(); Assert.assertFalse(outBuffer.hasRemaining()); }
From source file:org.trafodion.sql.HBaseAccess.HBulkLoadClient.java
public boolean addToHFile(short rowIDLen, Object rowIDs, Object rows) throws IOException, URISyntaxException { if (logger.isDebugEnabled()) logger.debug("Enter addToHFile() "); Put put;/*from w w w . j av a2 s .c o m*/ if (isNewFileNeeded()) { doCreateHFile(); } ByteBuffer bbRows, bbRowIDs; short numCols, numRows; short colNameLen; int colValueLen; byte[] colName, colValue, rowID; bbRowIDs = (ByteBuffer) rowIDs; bbRows = (ByteBuffer) rows; numRows = bbRowIDs.getShort(); HTableClient htc = new HTableClient(); long now = System.currentTimeMillis(); for (short rowNum = 0; rowNum < numRows; rowNum++) { rowID = new byte[rowIDLen]; bbRowIDs.get(rowID, 0, rowIDLen); numCols = bbRows.getShort(); for (short colIndex = 0; colIndex < numCols; colIndex++) { colNameLen = bbRows.getShort(); colName = new byte[colNameLen]; bbRows.get(colName, 0, colNameLen); colValueLen = bbRows.getInt(); colValue = new byte[colValueLen]; bbRows.get(colValue, 0, colValueLen); KeyValue kv = new KeyValue(rowID, htc.getFamily(colName), htc.getName(colName), now, colValue); writer.append(kv); } } if (logger.isDebugEnabled()) logger.debug("End addToHFile() "); return true; }
From source file:org.apache.carbondata.processing.store.writer.AbstractFactDataWriter.java
/** * Below method will be used to update the no dictionary start and end key * * @param key key to be updated//from w w w . j av a 2 s. c o m * @return return no dictionary key */ protected byte[] updateNoDictionaryStartAndEndKey(byte[] key) { if (key.length == 0) { return key; } // add key to byte buffer remove the length part of the data ByteBuffer buffer = ByteBuffer.wrap(key, 2, key.length - 2); // create a output buffer without length ByteBuffer output = ByteBuffer.allocate(key.length - 2); short numberOfByteToStorLength = 2; // as length part is removed, so each no dictionary value index // needs to be reshuffled by 2 bytes for (int i = 0; i < dataWriterVo.getNoDictionaryCount(); i++) { output.putShort((short) (buffer.getShort() - numberOfByteToStorLength)); } // copy the data part while (buffer.hasRemaining()) { output.put(buffer.get()); } output.rewind(); return output.array(); }
From source file:org.apache.carbondata.core.indexstore.blockletindex.BlockDataMap.java
protected int getTotalBlocklets() { ByteBuffer byteBuffer = ByteBuffer.wrap(getBlockletRowCountForEachBlock()); int sum = 0;//from w ww. j a v a2 s .c o m while (byteBuffer.hasRemaining()) { sum += byteBuffer.getShort(); } return sum; }
From source file:org.opendaylight.lispflowmapping.lisp.serializer.MapRegisterSerializer.java
public MapRegister deserialize(ByteBuffer registerBuffer, InetAddress sourceRloc) { try {/* w w w. j a va 2 s.c o m*/ MapRegisterBuilder builder = new MapRegisterBuilder(); builder.setMappingRecordItem(new ArrayList<MappingRecordItem>()); byte typeAndFlags = registerBuffer.get(); boolean xtrSiteIdPresent = ByteUtil.extractBit(typeAndFlags, Flags.XTRSITEID); builder.setProxyMapReply(ByteUtil.extractBit(typeAndFlags, Flags.PROXY)); builder.setXtrSiteIdPresent(xtrSiteIdPresent); registerBuffer.position(registerBuffer.position() + Length.RES); byte mergeAndMapReply = registerBuffer.get(); builder.setWantMapNotify(ByteUtil.extractBit(mergeAndMapReply, Flags.WANT_MAP_NOTIFY)); builder.setMergeEnabled(ByteUtil.extractBit(mergeAndMapReply, Flags.MERGE_ENABLED)); byte recordCount = (byte) ByteUtil.getUnsignedByte(registerBuffer); builder.setNonce(registerBuffer.getLong()); builder.setKeyId(registerBuffer.getShort()); short authenticationLength = registerBuffer.getShort(); byte[] authenticationData = new byte[authenticationLength]; registerBuffer.get(authenticationData); builder.setAuthenticationData(authenticationData); if (xtrSiteIdPresent) { List<MappingRecordBuilder> mrbs = new ArrayList<MappingRecordBuilder>(); for (int i = 0; i < recordCount; i++) { mrbs.add(MappingRecordSerializer.getInstance().deserializeToBuilder(registerBuffer)); } byte[] xtrIdBuf = new byte[Length.XTRID_SIZE]; registerBuffer.get(xtrIdBuf); XtrId xtrId = new XtrId(xtrIdBuf); byte[] siteIdBuf = new byte[Length.SITEID_SIZE]; registerBuffer.get(siteIdBuf); SiteId siteId = new SiteId(siteIdBuf); builder.setXtrId(xtrId); builder.setSiteId(siteId); for (MappingRecordBuilder mrb : mrbs) { mrb.setXtrId(xtrId); mrb.setSiteId(siteId); mrb.setSourceRloc(getSourceRloc(sourceRloc)); builder.getMappingRecordItem() .add(new MappingRecordItemBuilder().setMappingRecord(mrb.build()).build()); } } else { for (int i = 0; i < recordCount; i++) { builder.getMappingRecordItem() .add(new MappingRecordItemBuilder() .setMappingRecord( MappingRecordSerializer.getInstance().deserialize(registerBuffer)) .build()); } } registerBuffer.limit(registerBuffer.position()); byte[] mapRegisterBytes = new byte[registerBuffer.position()]; registerBuffer.position(0); registerBuffer.get(mapRegisterBytes); return builder.build(); } catch (RuntimeException re) { throw new LispSerializationException( "Couldn't deserialize Map-Register (len=" + registerBuffer.capacity() + ")", re); } }
From source file:org.carbondata.core.util.CarbonUtil.java
public static short[] getUnCompressColumnIndex(int totalLength, byte[] columnIndexData) { ByteBuffer buffer = ByteBuffer.wrap(columnIndexData); buffer.rewind();//from ww w . j av a 2 s . com int indexDataLength = buffer.getInt(); short[] indexData = new short[indexDataLength / 2]; short[] indexMap = new short[(totalLength - indexDataLength - CarbonCommonConstants.INT_SIZE_IN_BYTE) / 2]; int counter = 0; while (counter < indexData.length) { indexData[counter] = buffer.getShort(); counter++; } counter = 0; while (buffer.hasRemaining()) { indexMap[counter++] = buffer.getShort(); } return UnBlockIndexer.uncompressIndex(indexData, indexMap); }
From source file:de.hpi.fgis.hdrs.Triple.java
public void readFields(ByteBuffer buffer) { // read header Slen = buffer.getShort(); Plen = buffer.getShort();/*ww w . j av a 2s . c o m*/ Olen = buffer.getInt(); multiplicity = buffer.getInt(); // read data this.buffer = buffer.array(); int size = (int) Slen + (int) Plen + Olen; offset = buffer.arrayOffset() + buffer.position(); buffer.position(buffer.position() + size); }
From source file:org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6Match.java
private void readEtherType(ByteBuffer data, int nxmLen, boolean hasMask) { /*/* w ww. ja va 2s .co m*/ * mask is not allowed in ethertype */ if ((nxmLen != 2) || (data.remaining() < 2) || (hasMask)) return; super.setDataLayerType(data.getShort()); this.ethTypeState = MatchFieldState.MATCH_FIELD_ONLY; this.wildcards ^= (1 << 4); // Sync with 0F 1.0 Match this.match_len += 6; }