use of net.openhft.chronicle.bytes.Bytes in project Chronicle-Queue by OpenHFT.
the class SingleChronicleQueue method dump.
@Override
public void dump(@NotNull Writer writer, long fromIndex, long toIndex) {
try {
long firstIndex = firstIndex();
writer.append("# firstIndex: ").append(Long.toHexString(firstIndex)).append("\n");
ExcerptTailer tailer = createTailer();
if (!tailer.moveToIndex(fromIndex)) {
if (firstIndex > fromIndex) {
tailer.toStart();
} else {
return;
}
}
Bytes bytes = Wires.acquireBytes();
TextWire text = new TextWire(bytes);
while (true) {
try (DocumentContext dc = tailer.readingDocument()) {
if (!dc.isPresent()) {
writer.append("# no more messages at ").append(Long.toHexString(dc.index())).append("\n");
return;
}
if (dc.index() > toIndex)
return;
writer.append("# index: ").append(Long.toHexString(dc.index())).append("\n");
Wire wire = dc.wire();
long start = wire.bytes().readPosition();
try {
text.clear();
wire.copyTo(text);
writer.append(bytes.toString());
} catch (Exception e) {
wire.bytes().readPosition(start);
writer.append(wire.bytes()).append("\n");
}
}
}
} catch (Exception e) {
e.printStackTrace(new PrintWriter(writer));
} finally {
try {
writer.flush();
} catch (IOException e) {
LoggerFactory.getLogger(SingleChronicleQueue.class).debug("", e);
}
}
}
use of net.openhft.chronicle.bytes.Bytes in project Chronicle-Queue by OpenHFT.
the class SingleCQFormatTest method expected.
private static void expected(@NotNull ExcerptTailer tailer, String expected) {
try (DocumentContext dc = tailer.readingDocument()) {
assertTrue("No document found", dc.isPresent());
Bytes bytes2 = Bytes.elasticHeapByteBuffer(128);
dc.wire().copyTo(new TextWire(bytes2));
assertEquals(expected, bytes2.toString());
}
}
use of net.openhft.chronicle.bytes.Bytes in project Chronicle-Queue by OpenHFT.
the class DirectChronicleQueueStringTest method writeSome.
private void writeSome(DirectChronicleQueue chronicle) {
NativeBytesStore allocate = NativeBytesStore.nativeStoreWithFixedCapacity(EXPECTED_BYTES.length);
final Bytes toWrite = allocate.bytes();
for (int i = 0; i < RUNS; i++) {
toWrite.clear();
toWrite.write(EXPECTED_BYTES);
toWrite.flip();
chronicle.appendDocument(toWrite);
}
}
use of net.openhft.chronicle.bytes.Bytes in project Chronicle-Bytes by OpenHFT.
the class OptimisedBytesStoreHashTest method testReadIncompleteLong.
@Test
public void testReadIncompleteLong() {
Bytes bs = Bytes.allocateDirect(8);
for (int i = 1; i <= 8; i++) bs.writeUnsignedByte(i);
@NotNull Bytes bs2 = Bytes.allocateDirect(9).unchecked(true);
for (int i = 0; i <= 8; i++) {
assertEquals("i: " + i, Long.toHexString(bs2.readLong(0)), Long.toHexString(OptimisedBytesStoreHash.readIncompleteLong(bs.addressForRead(0), i)));
bs2.writeUnsignedByte(i + 1);
}
bs.release();
bs2.release();
}
use of net.openhft.chronicle.bytes.Bytes in project Chronicle-Bytes by OpenHFT.
the class BinaryLongArrayReferenceTest method getSetValues.
@Test
public void getSetValues() {
int length = 128 * 8 + 2 * 8;
Bytes bytes = Bytes.allocateDirect(length);
BinaryLongArrayReference.write(bytes, 128);
@NotNull BinaryLongArrayReference array = new BinaryLongArrayReference();
array.bytesStore(bytes, 0, length);
assertEquals(128, array.getCapacity());
for (int i = 0; i < 128; i++) array.setValueAt(i, i + 1);
for (int i = 0; i < 128; i++) assertEquals(i + 1, array.getValueAt(i));
bytes.release();
}
Aggregations