List of usage examples for java.nio ByteBuffer getInt
public abstract int getInt();
From source file:com.healthmarketscience.jackcess.Index.java
protected Index(ByteBuffer tableBuffer, List<IndexData> indexDatas, JetFormat format) throws IOException { ByteUtil.forward(tableBuffer, format.SKIP_BEFORE_INDEX_SLOT); //Forward past Unknown _indexNumber = tableBuffer.getInt(); int indexDataNumber = tableBuffer.getInt(); // read foreign key reference info byte relIndexType = tableBuffer.get(); int relIndexNumber = tableBuffer.getInt(); int relTablePageNumber = tableBuffer.getInt(); byte cascadeUpdatesFlag = tableBuffer.get(); byte cascadeDeletesFlag = tableBuffer.get(); _indexType = tableBuffer.get();/*w w w . jav a 2s. c om*/ if ((_indexType == FOREIGN_KEY_INDEX_TYPE) && (relIndexNumber != INVALID_INDEX_NUMBER)) { _reference = new ForeignKeyReference(relIndexType, relIndexNumber, relTablePageNumber, (cascadeUpdatesFlag == CASCADE_UPDATES_FLAG), (cascadeDeletesFlag == CASCADE_DELETES_FLAG)); } else { _reference = null; } ByteUtil.forward(tableBuffer, format.SKIP_AFTER_INDEX_SLOT); //Skip past Unknown _data = indexDatas.get(indexDataNumber); _data.addIndex(this); }
From source file:alignment.BinaryToCSV.java
/** * //from w w w.ja v a 2 s . c o m * * @param * @return */ public int readBlocks() { byte[] buffer = new byte[Bp]; byte[] tempBytes = new byte[4]; int total = 0; int nRead = 0; try { while ((nRead = inputStream.read(buffer)) != -1) { for (int i = 0; i < nRead; i += (Bs + 2)) { tempBytes = new byte[4]; tempBytes[3] = buffer[i]; tempBytes[2] = buffer[i + 1]; ByteBuffer bb = ByteBuffer.wrap(tempBytes); int tsI = bb.getInt(); //System.out.println("Timestamp: " + tsI); double calTS = calibrateTimeStamp((double) tsI); timestampsCal.add(calTS); //System.out.println("CAL Timestamp: " + calTS); } total += nRead; } } catch (IOException e) { e.printStackTrace(); } return total; }
From source file:com.datatorrent.contrib.hdht.PurgeTest.java
int sliceToInt(Slice s) { ByteBuffer bb = ByteBuffer.wrap(s.buffer, s.offset, s.length); return bb.getInt(); }
From source file:com.hortonworks.registries.schemaregistry.serdes.avro.AvroSnapshotDeserializer.java
protected SchemaIdVersion retrieveSchemaIdVersion(InputStream payloadInputStream) throws SerDesException { // it can be enhanced to have respective protocol handlers for different versions // first byte is protocol version/id. // protocol format: // 1 byte : protocol version // 8 bytes : schema metadata Id // 4 bytes : schema version ByteBuffer byteBuffer = ByteBuffer.allocate(13); try {/*from w w w .ja v a 2 s . com*/ payloadInputStream.read(byteBuffer.array()); } catch (IOException e) { throw new SerDesException(e); } byte protocolId = byteBuffer.get(); if (protocolId != AvroSchemaProvider.CURRENT_PROTOCOL_VERSION) { throw new SerDesException( "Unknown protocol id [" + protocolId + "] received while deserializing the payload"); } long schemaMetadataId = byteBuffer.getLong(); int schemaVersion = byteBuffer.getInt(); return new SchemaIdVersion(schemaMetadataId, schemaVersion); }
From source file:alignment.BinaryToCSV.java
/** * /*from www.ja v a 2s . com*/ * * @param * @return */ public int readHeader() { byte[] buffer = new byte[HEADER_SIZE]; //178 int nRead = 0; try { if ((nRead = inputStream.read(buffer)) == -1) System.err.println("Header read failed"); } catch (IOException e) { e.printStackTrace(); } counter += nRead; byteToBits(buffer[0], 0); LN = b7; System.out.println("Low Noise: " + LN); gyro = b6; System.out.println("Gyroscope: " + gyro); mag = b5; System.out.println("Magnetometer: " + mag); byteToBits(buffer[1], 1); WR = b4; System.out.println("Wide Range: " + WR); byteToBits(buffer[10], 10); sync = b2; System.out.println("Sync: " + sync); master = b1; System.out.println("Master: " + master); NumberFormat nf = NumberFormat.getNumberInstance(Locale.ENGLISH); DecimalFormat df = (DecimalFormat) nf; df.applyPattern("#.#"); sampleRate = Double.parseDouble( df.format(TWO_EXP_15 / (double) ((int) (buffer[21] & 0xFF) + ((int) (buffer[20] & 0xFF) << 8)))); System.out.println("SampleRate: " + sampleRate); byte[] tempBytes = new byte[4]; tempBytes[3] = buffer[174]; tempBytes[2] = buffer[175]; tempBytes[1] = buffer[176]; tempBytes[0] = buffer[177]; ByteBuffer bb = ByteBuffer.wrap(tempBytes); initialTS32 = bb.getInt(); System.out.println("Initial Timestamp: " + initialTS32); for (int i = 0; i < buffer.length; i++) { //byteToBits(buffer[i], i); } return nRead; }
From source file:loci.formats.in.KLBReader.java
private int readUInt32() throws IOException { byte[] b = new byte[4]; in.read(b, 0, 4);// w w w. j a v a 2 s . co m ByteBuffer bb = ByteBuffer.wrap(b).order(ByteOrder.LITTLE_ENDIAN); return bb.getInt(); }
From source file:com.navercorp.pinpoint.common.buffer.FixedBufferTest.java
@Test public void testWrapByteBuffer() throws Exception { FixedBuffer buffer = new FixedBuffer(8); buffer.putInt(1);//from w w w .ja v a 2 s. c o m buffer.putInt(2); final ByteBuffer byteBuffer = buffer.wrapByteBuffer(); Assert.assertEquals(byteBuffer.getInt(), 1); Assert.assertEquals(byteBuffer.getInt(), 2); }
From source file:com.yobidrive.diskmap.needles.Needle.java
public boolean getNeedleDataFromBuffer(ByteBuffer input) throws Exception { try {/*from w w w . j a va 2 s. c om*/ // input.reset() ; // Back to end of header // int startPosition = readBytes * -1 ; if (size > 0) { data = new byte[size]; input.get(data); } else data = null; int magic = input.getInt(); if (magic != MAGICEND) { logger.error("No MAGICEND within needle " + this.needleNumber); return false; } byte[] md5 = new byte[16]; input.get(md5); byte[] currentMD5 = hashMD5(); if (!Arrays.equals(md5, currentMD5)) { logger.error("Needle MD5 failed for " + new String(keyBytes, "UTF-8")); return false; } } catch (BufferUnderflowException bue) { return false; } return true; }
From source file:com.linkedin.pinot.core.common.datatable.DataTableImplV2.java
/** * Construct data table from byte array. (broker side) *///from ww w .j a v a 2s . co m public DataTableImplV2(@Nonnull ByteBuffer byteBuffer) throws IOException { // Read header. _numRows = byteBuffer.getInt(); _numColumns = byteBuffer.getInt(); int dictionaryMapStart = byteBuffer.getInt(); int dictionaryMapLength = byteBuffer.getInt(); int metadataStart = byteBuffer.getInt(); int metadataLength = byteBuffer.getInt(); int dataSchemaStart = byteBuffer.getInt(); int dataSchemaLength = byteBuffer.getInt(); int fixedSizeDataStart = byteBuffer.getInt(); int fixedSizeDataLength = byteBuffer.getInt(); int variableSizeDataStart = byteBuffer.getInt(); int variableSizeDataLength = byteBuffer.getInt(); // Read dictionary. if (dictionaryMapLength != 0) { byte[] dictionaryMapBytes = new byte[dictionaryMapLength]; byteBuffer.position(dictionaryMapStart); byteBuffer.get(dictionaryMapBytes); _dictionaryMap = deserializeDictionaryMap(dictionaryMapBytes); } else { _dictionaryMap = null; } // Read metadata. byte[] metadataBytes = new byte[metadataLength]; byteBuffer.position(metadataStart); byteBuffer.get(metadataBytes); _metadata = deserializeMetadata(metadataBytes); // Read data schema. if (dataSchemaLength != 0) { byte[] schemaBytes = new byte[dataSchemaLength]; byteBuffer.position(dataSchemaStart); byteBuffer.get(schemaBytes); _dataSchema = DataSchema.fromBytes(schemaBytes); _columnOffsets = new int[_dataSchema.size()]; _rowSizeInBytes = DataTableUtils.computeColumnOffsets(_dataSchema, _columnOffsets); } else { _dataSchema = null; _columnOffsets = null; _rowSizeInBytes = 0; } // Read fixed size data. if (fixedSizeDataLength != 0) { _fixedSizeDataBytes = new byte[fixedSizeDataLength]; byteBuffer.position(fixedSizeDataStart); byteBuffer.get(_fixedSizeDataBytes); _fixedSizeData = ByteBuffer.wrap(_fixedSizeDataBytes); } else { _fixedSizeDataBytes = null; _fixedSizeData = null; } // Read variable size data. if (variableSizeDataLength != 0) { _variableSizeDataBytes = new byte[variableSizeDataLength]; byteBuffer.position(variableSizeDataStart); byteBuffer.get(_variableSizeDataBytes); _variableSizeData = ByteBuffer.wrap(_variableSizeDataBytes); } else { _variableSizeDataBytes = null; _variableSizeData = null; } }
From source file:nl.dobots.bluenet.ble.base.structs.CrownstoneServiceData.java
public CrownstoneServiceData(byte[] bytes) { super();/*from w ww . j a v a 2 s . c om*/ ByteBuffer bb = ByteBuffer.wrap(bytes); bb.order(ByteOrder.LITTLE_ENDIAN); bb.getShort(); // skip first two bytes (service UUID) bb.mark(); int val = bb.get(); if (val == 1) { setCrownstoneId(bb.getShort()); setCrownstoneStateId(bb.getShort()); setSwitchState((bb.get() & 0xff)); setEventBitmask(bb.get()); setTemperature(bb.get()); setPowerUsage(bb.getInt()); setAccumulatedEnergy(bb.getInt()); setRelayState(BleUtils.isBitSet(getSwitchState(), 7)); setPwm(getSwitchState() & ~(1 << 7)); } else { bb.reset(); setCrownstoneId(bb.getShort()); setCrownstoneStateId(bb.getShort()); setSwitchState((bb.get() & 0xff)); setEventBitmask(bb.get()); setTemperature(bb.get()); bb.get(); // skip reserved // bb.getShort(); // skip reserved setPowerUsage(bb.getInt()); setAccumulatedEnergy(bb.getInt()); setRelayState(BleUtils.isBitSet(getSwitchState(), 7)); setPwm(getSwitchState() & ~(1 << 7)); } }