/** * Returns a readonly ByteArraySegment wrapping this Stream's buffer. * * @return A readonly ByteArraySegment from the current buffer. */ public ByteArraySegment getData() { return new ByteArraySegment(this.array, this.offset, this.length, true); }
/** * Returns a readonly ByteArraySegment wrapping the current buffer of the ByteArrayOutputStream. * * @return A readonly ByteArraySegment from the current buffer of the ByteArrayOutputStream. */ public ByteArraySegment getData() { return new ByteArraySegment(this.buf, 0, this.count, true); }
@SneakyThrows(IOException.class) public static EventPointerInternal fromBytes(ByteBuffer data) { return SERIALIZER.deserialize(new ByteArraySegment(data)); } }
/** * Creates a new instance of an empty BTreePage class.. * * @param config Page Configuration. */ BTreePage(Config config) { this(config, new ByteArraySegment(new byte[DATA_OFFSET + FOOTER_LENGTH]), false); formatHeaderAndFooter(this.count, ID_GENERATOR.nextInt()); }
private ByteArraySegment serializeValue(Long value) { if (value == null || value == Attributes.NULL_ATTRIBUTE_VALUE) { // Deletion. return null; } byte[] result = new byte[VALUE_LENGTH]; BitConverter.writeLong(result, 0, value); return new ByteArraySegment(result); }
@SneakyThrows(IOException.class) public static Checkpoint fromBytes(ByteBuffer buff) { return SERIALIZER.deserialize(new ByteArraySegment(buff)); } }
@SneakyThrows(IOException.class) Object readResolve() throws ObjectStreamException { return SERIALIZER.deserialize(new ByteArraySegment(value)); } }
@Override @SneakyThrows(IOException.class) public InitialUpdate<ReaderGroupState> deserialize(ByteBuffer serializedValue) { return serializer.deserialize(new ByteArraySegment(serializedValue)); } }
private ArrayList<PageEntry> generate(int count) { val result = new ArrayList<PageEntry>(count); val rnd = new Random(count); for (int i = 0; i < count; i++) { val key = new byte[KEY_LENGTH]; val value = new byte[VALUE_LENGTH]; rnd.nextBytes(key); rnd.nextBytes(value); result.add(new PageEntry(new ByteArraySegment(key), new ByteArraySegment(value))); } return result; }
private ByteArraySegment serializeLong(long value) { byte[] r = new byte[Long.BYTES]; BitConverter.writeLong(r, 0, value); return new ByteArraySegment(r); }
private List<TableKey> generateUnversionedKeys(int count, TestContext context) { val result = new ArrayList<TableKey>(count); for (int i = 0; i < count; i++) { byte[] keyData = new byte[Math.max(1, context.random.nextInt(100))]; context.random.nextBytes(keyData); result.add(TableKey.unversioned(new ByteArraySegment(keyData))); } return result; }
private List<TableKey> generateKeys(Random rnd) { val result = new ArrayList<TableKey>(); for (int i = 0; i < COUNT; i++) { val key = new byte[1 + rnd.nextInt(EntrySerializer.MAX_KEY_LENGTH)]; rnd.nextBytes(key); result.add(TableKey.unversioned(new ByteArraySegment(key))); } return result; }
private TableKey newTableKey(Random rnd) { byte[] buf = new byte[rnd.nextInt(100) + 1]; rnd.nextBytes(buf); return TableKey.unversioned(new ByteArraySegment(buf)); }
private PageEntry generateEntry(byte keyByte, byte valueByte) { val key = new ByteArraySegment(new byte[KEY_LENGTH]); Arrays.fill(key.array(), keyByte); val newValue = new ByteArraySegment(new byte[VALUE_LENGTH]); Arrays.fill(newValue.array(), valueByte); return new PageEntry(key, newValue); }
@Test public void testHashToBucketByteArrayView() { val rnd = new Random(0); testBucketUniformity(HashHelper::hashToBucket, () -> { byte[] r = new byte[16]; rnd.nextBytes(r); return new ByteArraySegment(r); }); }
/** * Tests the case when a RevisionDataOutputStream is created but left empty upon closing, while writing to a non-seekable OutputStream. */ @Test public void testZeroLengthNonSeekable() throws Exception { testZeroLength(ByteArrayOutputStream::new, os -> new ByteArraySegment(os.toByteArray())); }
@SafeVarargs private final <T> void test(Write<T> write, Read<T> read, T... testValues) { byte[] buffer = new byte[MAX_LENGTH]; for (T value : testValues) { int length = write.apply(buffer, 0, value); T readValue = read.apply(new ByteArraySegment(buffer, 0, length), 0); Assert.assertEquals("Unexpected deserialized value.", value, readValue); } }
/** * Tests the NonSeekableRevisionDataOutput class. */ @Test public void testNonSeekableOutputImpl() throws Exception { @Cleanup val s = new ByteArrayOutputStream(); @Cleanup val impl = RevisionDataOutputStream.wrap(s); testImpl(impl, () -> new ByteArraySegment(s.toByteArray())); }
private ByteArraySegment serializePointer(PagePointer pointer) { assert pointer.getLength() <= Short.MAX_VALUE : "PagePointer.length too large"; ByteArraySegment result = new ByteArraySegment(new byte[this.indexPageConfig.getValueLength()]); BitConverter.writeLong(result, 0, pointer.getOffset()); BitConverter.writeShort(result, Long.BYTES, (short) pointer.getLength()); BitConverter.writeLong(result, Long.BYTES + Short.BYTES, pointer.getMinOffset()); return result; }
private void write01(ReaderGroupConfig object, RevisionDataOutput revisionDataOutput) throws IOException { revisionDataOutput.writeLong(object.getAutomaticCheckpointIntervalMillis()); revisionDataOutput.writeLong(object.getGroupRefreshTimeMillis()); ElementSerializer<Stream> keySerializer = (out, s) -> out.writeUTF(s.getScopedName()); ElementSerializer<StreamCut> valueSerializer = (out, cut) -> out.writeArray(new ByteArraySegment(cut.toBytes())); revisionDataOutput.writeMap(object.startingStreamCuts, keySerializer, valueSerializer); revisionDataOutput.writeMap(object.endingStreamCuts, keySerializer, valueSerializer); revisionDataOutput.writeInt(object.getMaxOutstandingCheckpointRequest()); } }