/** * @param ptr Pointer. * @param cnt Count. * @return Byte array. */ public byte[] readBytes(long ptr, int cnt) { return readBytes(ptr, new byte[cnt]); }
/** * @param ptr Pointer. * @param mem Memory. * @return Key bytes. */ static byte[] readKeyBytes(long ptr, GridUnsafeMemory mem) { int keyLen = readKeyLength(ptr, mem); return mem.readBytes(ptr + HEADER_SIZE, keyLen); }
/** {@inheritDoc} */ @Override public void readFully(byte[] b, int off, int len) throws IOException { mem.readBytes(move(len), b, off, len); }
/** {@inheritDoc} */ @Override public void readBytes(byte[] b, int offset, int len) throws IOException { while (len > 0) { if (bufPosition >= bufLength) { currBufIdx++; switchCurrentBuffer(true); } int remainInBuf = bufLength - bufPosition; int bytesToCp = len < remainInBuf ? len : remainInBuf; mem.readBytes(currBuf + bufPosition, b, offset, bytesToCp); offset += bytesToCp; len -= bytesToCp; bufPosition += bytesToCp; } }
/** * @param ptr Pointer. * @param mem Memory. * @return Value bytes. */ static byte[] readValueBytes(long ptr, GridUnsafeMemory mem) { int keyLen = readKeyLength(ptr, mem); int valLen = readValueLength(ptr, mem); return mem.readBytes(ptr + HEADER_SIZE + keyLen, valLen); }
/** * Get value stored in offheap along with a value type. * * @param ptr Pointer to read. * @return Stored byte array and "raw bytes" flag. */ public IgniteBiTuple<byte[], Byte> get(long ptr) { assert ptr != 0; int size = readInt(ptr); byte type = readByte(ptr + 4); byte[] bytes = readBytes(ptr + 5, size); return new IgniteBiTuple<>(bytes, type); }
private void advance() { assert bin.isEmpty(); long tblEnd = tblAddr + memCap; for (long binAddr = tblAddr; binAddr < tblEnd; binAddr += 8) { long entryAddr = Bin.first(binAddr, mem); if (entryAddr == 0) continue; while (entryAddr != 0) { // Read key and value bytes. // TODO: GG-8123: Inlined as a workaround. Revert when 7u60 is released. // bin.add(F.t(Entry.readKeyBytes(entryAddr, mem), Entry.readValueBytes(entryAddr, mem))); { int keyLen = Entry.readKeyLength(entryAddr, mem); int valLen = Entry.readValueLength(entryAddr, mem); byte[] valBytes = mem.readBytes(entryAddr + HEADER_SIZE + keyLen, valLen); bin.add(F.t(Entry.readKeyBytes(entryAddr, mem), valBytes)); } entryAddr = Entry.nextAddress(entryAddr, mem); } } }
int valLen = Entry.readValueLength(addr, mem); return mem.readBytes(addr + HEADER_SIZE + keyLen, valLen);
/** * @throws Exception If failed. */ @Test public void testBytes() throws Exception { GridUnsafeMemory mem = new GridUnsafeMemory(64); String s = "123"; byte[] bytes = s.getBytes(); int size = bytes.length * 2; long addr = mem.allocate(size); try { mem.writeBytes(addr, bytes); byte[] read = mem.readBytes(addr, bytes.length); assert Arrays.equals(bytes, read); } finally { mem.release(addr, size); } }
/** * @param s String. * @throws Exception If failed. */ public void checkCompare(String s) throws Exception { byte[] bytes = s.getBytes(); int size = bytes.length + 8; GridUnsafeMemory mem = new GridUnsafeMemory(size); for (int i = 0; i < 8; i++) { long addr = mem.allocate(size); long ptr = addr + i; try { mem.writeBytes(ptr, bytes); assert mem.compare(ptr, bytes); byte[] read = mem.readBytes(ptr, bytes.length); assert Arrays.equals(bytes, read); } finally { mem.release(addr, size); } } }
valBytes = mem.readBytes(cur + HEADER_SIZE + keyLen, valLen);
int valLen = Entry.readValueLength(cur, mem); valBytes = mem.readBytes(cur + HEADER_SIZE + keyLen, valLen);
/** * @param ptr Pointer. * @param cnt Count. * @return Byte array. */ public byte[] readBytes(long ptr, int cnt) { return readBytes(ptr, new byte[cnt]); }
/** * @param ptr Pointer. * @param mem Memory. * @return Key bytes. */ static byte[] readKeyBytes(long ptr, GridUnsafeMemory mem) { int keyLen = readKeyLength(ptr, mem); return mem.readBytes(ptr + HEADER_SIZE, keyLen); }
/** {@inheritDoc} */ @Override public void readBytes(byte[] b, int offset, int len) throws IOException { while (len > 0) { if (bufPosition >= bufLength) { currBufIdx++; switchCurrentBuffer(true); } int remainInBuf = bufLength - bufPosition; int bytesToCp = len < remainInBuf ? len : remainInBuf; mem.readBytes(currBuf + bufPosition, b, offset, bytesToCp); offset += bytesToCp; len -= bytesToCp; bufPosition += bytesToCp; } }
/** * @param ptr Pointer. * @param mem Memory. * @return Value bytes. */ static byte[] readValueBytes(long ptr, GridUnsafeMemory mem) { int keyLen = readKeyLength(ptr, mem); int valLen = readValueLength(ptr, mem); return mem.readBytes(ptr + HEADER_SIZE + keyLen, valLen); }
/** * Get value stored in offheap along with a value type. * * @param ptr Pointer to read. * @return Stored byte array and "raw bytes" flag. */ public IgniteBiTuple<byte[], Byte> get(long ptr) { assert ptr != 0; int size = readInt(ptr); byte type = readByte(ptr + 4); byte[] bytes = readBytes(ptr + 5, size); return new IgniteBiTuple<>(bytes, type); }
private void advance() { assert bin.isEmpty(); long tblEnd = tblAddr + memCap; for (long binAddr = tblAddr; binAddr < tblEnd; binAddr += 8) { long entryAddr = Bin.first(binAddr, mem); if (entryAddr == 0) continue; while (entryAddr != 0) { // Read key and value bytes. // TODO: GG-8123: Inlined as a workaround. Revert when 7u60 is released. // bin.add(F.t(Entry.readKeyBytes(entryAddr, mem), Entry.readValueBytes(entryAddr, mem))); { int keyLen = Entry.readKeyLength(entryAddr, mem); int valLen = Entry.readValueLength(entryAddr, mem); byte[] valBytes = mem.readBytes(entryAddr + HEADER_SIZE + keyLen, valLen); bin.add(F.t(Entry.readKeyBytes(entryAddr, mem), valBytes)); } entryAddr = Entry.nextAddress(entryAddr, mem); } } }
int valLen = Entry.readValueLength(addr, mem); return mem.readBytes(addr + HEADER_SIZE + keyLen, valLen);
valBytes = mem.readBytes(cur + HEADER_SIZE + keyLen, valLen);