@Test public void testReadingLessBytesThanWritten() { try (final ChronicleQueue queue = builder(getTmpDir(), wireType) .build()) { final ExcerptAppender appender = queue.acquireAppender(); final Bytes<byte[]> expected = Bytes.wrapForRead("some long message".getBytes(ISO_8859_1)); for (int i = 0; i < 10; i++) { appender.writeBytes(expected); } final ExcerptTailer tailer = queue.createTailer(); // Sequential read for (int i = 0; i < 10; i++) { Bytes b = Bytes.allocateDirect(8); tailer.readBytes(b); Assert.assertEquals(expected.readInt(0), b.readInt(0)); b.release(); } } }
@Test//(timeout = 5000) public void testTailerReadingEmptyQueue() { assumeFalse(Jvm.isArm()); final File path = DirectoryUtils.tempDir("testTailerReadingEmptyQueue"); final ChronicleQueue rqueue = SingleChronicleQueueBuilder.fieldlessBinary(path) .testBlockSize() .rollCycle(TEST_DAILY) .build(); final ExcerptTailer tailer = rqueue.createTailer(); final ChronicleQueue wqueue = SingleChronicleQueueBuilder.fieldlessBinary(path) .testBlockSize() .rollCycle(TEST_DAILY) .build(); Bytes bytes = Bytes.elasticByteBuffer(); assertFalse(tailer.readBytes(bytes)); final ExcerptAppender appender = wqueue.acquireAppender(); appender.writeBytes(Bytes.wrapForRead("Hello World".getBytes(ISO_8859_1))); bytes.clear(); assertTrue(tailer.readBytes(bytes)); assertEquals("Hello World", bytes.toString()); bytes.release(); }
static Bytes<byte[]> fromString(@NotNull String text) throws IllegalArgumentException, IllegalStateException { return wrapForRead(text.getBytes(StandardCharsets.ISO_8859_1)); }
public InMemoryDoubleColumn(TimeSeries timeSeries, String name, BytesDoubleLookup lookup, long capacity) { super(timeSeries, name); this.lookup = lookup; // this.bytes = NativeBytesStore.lazyNativeBytesStoreWithFixedCapacity(lookup.sizeFor(capacity)); this.bytes = Bytes.wrapForRead(ByteBuffer.allocateDirect(Math.toIntExact(lookup.sizeFor(capacity)))); }
@NotNull public static NativeBytesStore from(@NotNull byte[] bytes) { try { @NotNull NativeBytesStore nbs = nativeStore(bytes.length); Bytes.wrapForRead(bytes).copyTo(nbs); return nbs; } catch (IllegalArgumentException e) { throw new AssertionError(e); } }
/** * Convert text to bytes using ISO-8859-1 encoding and return a Bytes ready for reading. * * @param text to convert * @return Bytes ready for reading. */ static Bytes<byte[]> from(@NotNull CharSequence text) { if (text instanceof BytesStore) return ((BytesStore) text).copy().bytesForRead(); return wrapForRead(text.toString().getBytes(StandardCharsets.ISO_8859_1)); }
public static Bytes readFile(@org.jetbrains.annotations.NotNull String name) throws IOException { File file = new File(name); URL url = null; if (!file.exists()) { url = urlFor(name); file = new File(url.getFile()); } return // name.endsWith(".gz") || !file.exists() || OS.isWindows() ? Bytes.wrapForRead(readAsBytes(url == null ? new FileInputStream(file) : open(url))); //: MappedFile.readOnly(file).acquireBytesForRead(0); }
public InMemoryLongColumn(TimeSeries timeSeries, String name, BytesLongLookup lookup, long capacity) { super(timeSeries, name); this.lookup = lookup; long value = lookup.sizeFor(capacity); this.bytes = Jvm.isDebug() ? Bytes.wrapForRead(ByteBuffer.allocateDirect(Math.toIntExact(value))) : NativeBytesStore.lazyNativeBytesStoreWithFixedCapacity(value); }
@Override public void ensureCapacity(long capacity) { long cap = lookup.sizeFor(capacity); if (cap > bytes.realCapacity()) { // BytesStore bytes2 = NativeBytesStore.lazyNativeBytesStoreWithFixedCapacity(Maths.divideRoundUp(cap, OS.pageSize())); BytesStore bytes2 = Bytes.wrapForRead(ByteBuffer.allocateDirect(Math.toIntExact(lookup.sizeFor(capacity)))); bytes2.write(0, bytes); bytes.release(); bytes = bytes2; } }
@Override public void ensureCapacity(long capacity) { long cap = lookup.sizeFor(capacity); if (cap > bytes.realCapacity()) { long value = lookup.sizeFor(capacity); BytesStore bytes2 = Jvm.isDebug() ? Bytes.wrapForRead(ByteBuffer.allocateDirect(Math.toIntExact(value))) : NativeBytesStore.lazyNativeBytesStoreWithFixedCapacity(value); bytes2.write(0, bytes); bytes.release(); bytes = bytes2; } }
Bytes<ByteBuffer> headerBytes = Bytes.wrapForRead(headerBuffer); headerBytes.readPosition(headerBuffer.position()); headerBytes.readLimit(headerBuffer.limit());