@Override public String toString() { return String.format("Length = %d, Derived = %s", this.data.getLength(), this.derived); } }
/** * Sets the Value at the given position. * * @param pos The Position to set the value at. * @param value A ByteArraySegment representing the value to set. */ private void setValueAtPosition(int pos, ByteArraySegment value) { Preconditions.checkElementIndex(pos, getCount(), "pos must be non-negative and smaller than the number of items."); Preconditions.checkArgument(value.getLength() == this.config.valueLength, "Given value has incorrect length."); this.data.copyFrom(value, pos * this.config.entryLength + this.config.keyLength, value.getLength()); }
private void setEntryAtIndex(int dataIndex, PageEntry entry) { Preconditions.checkElementIndex(dataIndex, this.data.getLength(), "dataIndex must be non-negative and smaller than the size of the data."); Preconditions.checkArgument(entry.getKey().getLength() == this.config.keyLength, "Given entry key has incorrect length."); Preconditions.checkArgument(entry.getValue().getLength() == this.config.valueLength, "Given entry value has incorrect length."); this.data.copyFrom(entry.getKey(), dataIndex, entry.getKey().getLength()); this.data.copyFrom(entry.getValue(), dataIndex + this.config.keyLength, entry.getValue().getLength()); }
@Override @SneakyThrows(IOException.class) public ByteBuffer toBytes() { ByteArraySegment serialized = SERIALIZER.serialize(this); return ByteBuffer.wrap(serialized.array(), serialized.arrayOffset(), serialized.getLength()); }
@SneakyThrows(IOException.class) public ByteBuffer toBytes() { ByteArraySegment serialized = SERIALIZER.serialize(this); return ByteBuffer.wrap(serialized.array(), serialized.arrayOffset(), serialized.getLength()); }
@Override @SneakyThrows(IOException.class) public ByteBuffer toBytes() { ByteArraySegment serialized = SERIALIZER.serialize(this); return ByteBuffer.wrap(serialized.array(), serialized.arrayOffset(), serialized.getLength()); }
@Override @SneakyThrows(IOException.class) public ByteBuffer toBytes() { ByteArraySegment serialized = SERIALIZER.serialize(this); return ByteBuffer.wrap(serialized.array(), serialized.arrayOffset(), serialized.getLength()); }
@Override @SneakyThrows(IOException.class) public ByteBuffer serialize(InitialUpdate<ReaderGroupState> value) { ByteArraySegment serialized = serializer.serialize(value); return ByteBuffer.wrap(serialized.array(), serialized.arrayOffset(), serialized.getLength()); }
private void write00(T o, RevisionDataOutput target) throws IOException { ByteArraySegment c = o.getContents(); target.length(Long.BYTES + target.getCompactIntLength(c.getLength()) + c.getLength()); target.writeLong(o.getSequenceNumber()); target.writeArray(c.array(), c.arrayOffset(), c.getLength()); }
@SneakyThrows(IOException.class) private int getSerializationLength(ImmutableClass ic) { // Note that this is an extremely expensive way to calculate the length. This is appropriate for this unit test // but this should be avoided in real production code. return serialize(ic).getLength(); } }
@Override public ReadResultEntry next() { if (!hasNext()) { return null; } int relativeOffset = this.consumedLength; int length = Math.min(this.entryLength, Math.min(this.data.getLength(), this.maxResultLength )- relativeOffset); this.consumedLength += length; return new Entry(relativeOffset, length); }
private void serializeHandle(RollingSegmentHandle handle) throws StreamSegmentException { ByteArraySegment handleData = HandleSerializer.serialize(handle); try { this.baseStorage.write(handle.getHeaderHandle(), 0, handleData.getReader(), handleData.getLength()); handle.setHeaderLength(handleData.getLength()); log.debug("Header for '{}' fully serialized to '{}'.", handle.getSegmentName(), handle.getHeaderHandle().getSegmentName()); } catch (BadOffsetException ex) { // If we get BadOffsetException when writing the Handle, it means it was modified externally. throw new StorageNotPrimaryException(handle.getSegmentName(), ex); } }
private List<ByteArraySegment> copy(List<ByteArraySegment> source) { return source.stream() .map(a -> new ByteArraySegment(Arrays.copyOf(a.array(), a.array().length), a.arrayOffset(), a.getLength())) .collect(Collectors.toList()); }
void commit() { Preconditions.checkState(this.buffer != null && !this.buffer.isReadOnly(), "Cannot commit a read-only FrameHeader"); assert this.buffer.getLength() == SERIALIZATION_LENGTH; // We already checked the size of the target buffer (in the constructor); no need to do it here again. int bufferOffset = 0; this.buffer.set(bufferOffset, getVersion()); bufferOffset += Byte.BYTES; bufferOffset += BitConverter.writeInt(this.buffer, bufferOffset, getContentLength()); this.buffer.set(bufferOffset, encodeFlags()); } }
@Override @SneakyThrows(IOException.class) protected byte[] getData(EnhancedByteArrayOutputStream stream) { val b = stream.getData(); return StreamHelpers.readAll(b.getReader(), b.getLength()); } }
@Override @SneakyThrows(IOException.class) protected byte[] getData(EnhancedByteArrayOutputStream stream) { val b = stream.getData(); return StreamHelpers.readAll(b.getReader(), b.getLength()); } }
@SneakyThrows(IOException.class) private byte[] serialize(RollingSegmentHandle handle) { val s = HandleSerializer.serialize(handle); return StreamHelpers.readAll(s.getReader(), s.getLength()); }
@Override @SneakyThrows(IOException.class) protected byte[] getData(FixedByteArrayOutputStream stream) { val b = stream.getData(); return StreamHelpers.readAll(b.getReader(), b.getLength()); } }