protected static long get6BLongFromByteBuffer( ByteBuffer buffer, int startOffset ) { long low4b = buffer.getInt( startOffset ) & 0xFFFFFFFFL; long high2b = buffer.getShort( startOffset + Integer.BYTES ) & 0xFFFF; long result = low4b | (high2b << 32); return result == 0xFFFFFFFFFFFFL ? -1 : result; }
/** * build unit from buffer from current position. */ private boolean read(final ByteBuffer buffer) { if (buffer.position() + 2 > buffer.limit()) { return false; } this.size = buffer.getShort(); if (this.size < 1) { return false; } this.tagsCode = buffer.getLong(); this.msgStoreTime = buffer.getLong(); this.bitMapSize = buffer.getShort(); if (this.bitMapSize < 1) { return true; } if (this.filterBitMap == null || this.filterBitMap.length != this.bitMapSize) { this.filterBitMap = new byte[bitMapSize]; } buffer.get(this.filterBitMap); return true; }
public List<UUID> extractUUIDs(byte[] scanResult) { List<UUID> uuids = new ArrayList<>(); ByteBuffer buffer = ByteBuffer.wrap(scanResult).order(ByteOrder.LITTLE_ENDIAN); byte length = buffer.get(); if (length == 0) break; byte type = buffer.get(); switch (type) { case 0x02: // Partial list of 16-bit UUIDs case 0x03: // Complete list of 16-bit UUIDs while (length >= 2) { final String serviceUuidString = String.format(UUID_BASE, buffer.getShort()); final UUID serviceUuid = UUID.fromString(serviceUuidString); uuids.add(serviceUuid); case 0x05: // Complete list of 32-bit UUIDs while (length >= 4) { final String serviceUuidString = String.format(UUID_BASE, buffer.getInt()); final UUID serviceUuid = UUID.fromString(serviceUuidString); uuids.add(serviceUuid); buffer.position(buffer.position() + length - 1); break;
private void fillKeys(byte[] rowKey, String[] result) { int keyNum = keyIndexes.length; ByteBuffer byteBuffer = ByteBuffer.wrap(rowKey); byteBuffer.getShort(); // read shard for (int i = 0; i < keyNum; i++) { short keyLen = byteBuffer.getShort(); byte[] keyBytes = new byte[keyLen]; byteBuffer.get(keyBytes); result[keyIndexes[i]] = Bytes.toString(keyBytes); } }
Idmap_header(ByteBuffer buf, int offset) { super(buf, offset); magic = buf.getInt(offset); version = buf.getInt(offset + 4); target_crc32 = buf.getInt(offset + 8); overlay_crc32 = buf.getInt(offset + 12); buf.get(target_path, offset + 16, 256); buf.get(overlay_path, offset + 16 + 256, 256); target_package_id = buf.getShort(offset + 16 + 256 + 256); type_count = buf.getShort(offset + 16 + 256 + 256 + 2); } } // __attribute__((packed));
/** * Copies the first key/value from the given stream, and initializes * decompression state based on it. Assumes that we have already read key * and value lengths. Does not set {@link #qualifierLength} (not used by * decompression) or {@link #prevOffset} (set by the calle afterwards). */ private void decompressFirstKV(ByteBuffer out, DataInputStream in) throws IOException { int kvPos = out.position(); out.putInt(keyLength); out.putInt(valueLength); prevTimestampOffset = out.position() + keyLength - KeyValue.TIMESTAMP_TYPE_SIZE; ByteBufferUtils.copyFromStreamToBuffer(out, in, keyLength + valueLength); rowLength = out.getShort(kvPos + KeyValue.ROW_OFFSET); familyLength = out.get(kvPos + KeyValue.ROW_OFFSET + KeyValue.ROW_LENGTH_SIZE + rowLength); type = out.get(prevTimestampOffset + KeyValue.TIMESTAMP_SIZE); }
public void testByteBuffer() throws IOException { byte[] string = "Hello".getBytes(); ByteBuffer buf = ByteBuffer.allocate(1024); buf.order(ByteOrder.LITTLE_ENDIAN); buf.putInt(123); buf.putChar('z'); buf.putShort((short) 2017); buf.putFloat(3.1415f); buf.put(string); buf.putLong(9876543210L); buf.putDouble(3.14159265); buf.put((byte) 5); buf.flip(); // important // TestUtils.showBuffer(buf); assertEquals(123, buf.getInt()); assertEquals('z', buf.getChar()); assertEquals(2017, buf.getShort()); assertEquals(3.1415f, buf.getFloat()); byte[] so = new byte[string.length]; buf.get(so); assertTrue(TestUtils.sameBytes(string, so)); assertEquals(9876543210L, buf.getLong()); assertEquals(3.14159265, buf.getDouble()); assertEquals((byte) 5, buf.get()); }
/** * Only read first 2 byte to get unit size. * <p> * if size > 0, then skip buffer position with size. * </p> * <p> * if size <= 0, nothing to do. * </p> */ private void readBySkip(final ByteBuffer buffer) { ByteBuffer temp = buffer.slice(); short tempSize = temp.getShort(); this.size = tempSize; if (tempSize > 0) { buffer.position(buffer.position() + this.size); } }
@Override public void read(FileChannel fileChannel) throws IOException { if (fileChannel.size() == 0) { return; } fileChannel.position(0); fileChannel.read(byteBuffer()); byteBuffer().position(0); short readMagic = byteBuffer().getShort(); if (readMagic != magic) { throw new IOException("Invalid file type magic number 0x" + Integer.toHexString(readMagic & 0xFFFF)); } this.firstRecordId = byteBuffer().getLong(); }
@Override public void queueInput(ByteBuffer inputBuffer) { Assertions.checkState(outputChannels != null); int position = inputBuffer.position(); int limit = inputBuffer.limit(); int frameCount = (limit - position) / (2 * channelCount); int outputSize = frameCount * outputChannels.length * 2; if (buffer.capacity() < outputSize) { buffer = ByteBuffer.allocateDirect(outputSize).order(ByteOrder.nativeOrder()); } else { buffer.clear(); } while (position < limit) { for (int channelIndex : outputChannels) { buffer.putShort(inputBuffer.getShort(position + 2 * channelIndex)); } position += channelCount * 2; } inputBuffer.position(limit); buffer.flip(); outputBuffer = buffer; }
byte[] buffer = bbuf.array(); f.readFully(buffer); bbuf.order(ByteOrder.LITTLE_ENDIAN); for (eocdIdx = buffer.length - kEOCDLen; eocdIdx >= 0; eocdIdx--) { if (buffer[eocdIdx] == 0x50 && bbuf.getInt(eocdIdx) == kEOCDSignature) { if (LOGV) { Log.v(LOG_TAG, "+++ Found EOCD at index: " + eocdIdx); int numEntries = bbuf.getShort(eocdIdx + kEOCDNumEntries); long dirSize = bbuf.getInt(eocdIdx + kEOCDSize) & 0xffffffffL; long dirOffset = bbuf.getInt(eocdIdx + kEOCDFileOffset) & 0xffffffffL; buf.order(ByteOrder.LITTLE_ENDIAN);
@Override public void decode(byte[] a) { ByteBuffer byteBuffer = ByteBuffer.wrap(a); this.transactionId = byteBuffer.getLong(); this.timeout = byteBuffer.getInt(); short applicationIdLen = byteBuffer.getShort(); if (applicationIdLen > 0) { byte[] byApplicationId = new byte[applicationIdLen]; byteBuffer.get(byApplicationId); this.applicationId = new String(byApplicationId); } short serviceGroupLen = byteBuffer.getShort(); if (serviceGroupLen > 0) { byte[] byServiceGroup = new byte[serviceGroupLen]; byteBuffer.get(byServiceGroup); this.transactionServiceGroup = new String(byServiceGroup); } short txNameLen = byteBuffer.getShort(); if (txNameLen > 0) { byte[] byTxName = new byte[txNameLen]; byteBuffer.get(byTxName); this.transactionName = new String(byTxName); } this.beginTime = byteBuffer.getLong(); }
public List<UUID> extractUUIDs(byte[] scanResult) { List<UUID> uuids = new ArrayList<>(); ByteBuffer buffer = ByteBuffer.wrap(scanResult).order(ByteOrder.LITTLE_ENDIAN); int length = buffer.get() & 0xFF; // convert to unsigned if (length == 0) break; byte type = buffer.get(); switch (type) { case DATA_TYPE_SERVICE_UUIDS_16_BIT_PARTIAL: // Partial list of 16-bit UUIDs case DATA_TYPE_SERVICE_UUIDS_16_BIT_COMPLETE: // Complete list of 16-bit UUIDs while (length >= 2) { uuids.add(UUID.fromString(String.format(UUID_BASE_FORMAT, buffer.getShort()))); length -= 2; case DATA_TYPE_SERVICE_UUIDS_32_BIT_COMPLETE: // Complete list of 32-bit UUIDs while (length >= 4) { uuids.add(UUID.fromString(String.format(UUID_BASE_FORMAT, buffer.getInt()))); length -= 4; buffer.position(buffer.position() + safeLengthToProceed); break;
protected void decodeFromLenPfxBytes(byte[] rowKey, int[] valueIdx, String[] result) { ByteBuffer byteBuffer = ByteBuffer.wrap(rowKey); for (int i = 0; i < valueIdx.length; i++) { short keyLen = byteBuffer.getShort(); byte[] keyBytes = new byte[keyLen]; byteBuffer.get(keyBytes); result[valueIdx[i]] = fromBytes(keyBytes); } }