private void append() { outbound.clear(); outbound.write(new byte[msgSize], 0, msgSize); appender.writeBytes(outbound); }
@Override public void writeBytes(@NotNull BytesStore bytes) throws UnrecoverableTimeoutException { writeLock.lock(); try { int cycle = queue.cycle(); if (this.cycle != cycle || wire == null) rollCycleTo(cycle); position(writeHeader(wire, (int) queue.overlapSize())); assert ((AbstractWire) wire).isInsideHeader(); beforeAppend(wire, wire.headerNumber() + 1); Bytes<?> wireBytes = wire.bytes(); wireBytes.write(bytes); if (padToCacheLines == Padding.WORD) wireBytes.writeSkip((-wireBytes.writePosition()) & 0x3); wire.updateHeader(position, false, 0); lastIndex(wire.headerNumber()); lastPosition = position; lastCycle = cycle; store.writePosition(position); writeIndexForPosition(lastIndex, position); } catch (StreamCorruptedException e) { throw new AssertionError(e); } finally { writeLock.unlock(); } }
@Override public void run(long startTimeNS) { datum.setValue10(startTimeNS); try (DocumentContext dc = appender.writingDocument()) { dc.wire().bytes().write(datumBytes); //datum.writeMarshallable(dc.wire().bytes()); } try (DocumentContext dc = tailer.readingDocument()) { if (dc.wire() != null) { datumWrite.writePosition(0); dc.wire().readBytes(datumWrite); //datum.readMarshallable(dc.wire().bytes()); jlbh.sample(System.nanoTime() - datum.getValue10()); } } }
public static void write(@NotNull Bytes bytes, long capacity) { long start = bytes.writePosition(); bytes.write(SECTION1); bytes.append(capacity); while (bytes.writePosition() - start < CAPACITY + DIGITS) { bytes.writeUnsignedByte(' '); } bytes.write(SECTION2); bytes.write(ZERO); bytes.write(SECTION3); for (long i = 0; i < capacity; i++) { if (i > 0) bytes.appendUtf8(", "); bytes.write(ZERO); } bytes.write(SECTION4); }
private void writePayload(Bytes payload, Bytes destination) { destination.writeByte(BOOTSTRAP_TIME_HUNK); destination.write(payload, payload.readPosition(), payload.readRemaining()); }
private static void writeString(Bytes out, String s) { try { Preconditions.checkArgument(s == null || s.length() <= Short.MAX_VALUE, "String too long (more than 32K)"); byte[] bytes = s == null ? new byte[0] : s.getBytes("UTF-8"); out.writeShort((short) bytes.length); out.write(bytes); } catch (UnsupportedEncodingException e) { logger.log(Level.SEVERE, "Likely programmer error, String to Byte encoding failed: ", e); e.printStackTrace(); } }
private void writeBytesInternal(long index, @NotNull BytesStore bytes) { assert writeLock.locked(); try { if (wire == null) { int cycle = queue.rollCycle().toCycle(index); setCycle2(cycle, true); } int safeLength = (int) queue.overlapSize(); openContext(false, safeLength); try { context.wire().bytes().write(bytes); } finally { context.close(false); } } finally { context.isClosed = true; } }
/** * will unwrite from the offset upto the current write position of the destination bytes * * @param fromOffset the offset from the target byytes * @param count the number of bytes to un-write */ default void unwrite(long fromOffset, int count) { long wp = writePosition(); if (wp < fromOffset) return; write(fromOffset, this, fromOffset + count, wp - fromOffset); writeSkip(-count); }
public static void write(@NotNull Bytes bytes, int value) throws BufferOverflowException { long position = bytes.writePosition(); bytes.write(template); try { bytes.append(position + VALUE, value, DIGITS); } catch (IllegalArgumentException e) { throw new AssertionError(e); } }
private static void writeString(Bytes out, String s) { try { Preconditions.checkArgument(s == null || s.length() <= Short.MAX_VALUE, "String too long (more than 32K)"); byte[] bytes = s == null ? new byte[0] : s.getBytes("UTF-8"); out.writeShort((short) bytes.length); out.write(bytes); } catch (UnsupportedEncodingException e) { logger.log(Level.SEVERE, "Likely programmer error, String to Byte encoding failed: ", e); e.printStackTrace(); } }
@Test public void testWriteBytes() { File dir = DirectoryUtils.tempDir("WriteBytesTest"); try (ChronicleQueue queue = binary(dir) .testBlockSize() .build()) { ExcerptAppender appender = queue.acquireAppender(); ExcerptTailer tailer = queue.createTailer(); outgoingMsgBytes[0] = 'A'; outgoingBytes.write(outgoingMsgBytes); postOneMessage(appender); fetchOneMessage(tailer, incomingMsgBytes); System.out.println(new String(incomingMsgBytes)); outgoingBytes.clear(); outgoingMsgBytes[0] = 'A'; outgoingMsgBytes[1] = 'B'; outgoingBytes.write(outgoingMsgBytes); postOneMessage(appender); fetchOneMessage(tailer, incomingMsgBytes); System.out.println(new String(incomingMsgBytes)); } finally { try { IOTools.deleteDirWithFiles(dir, 2); } catch (IORuntimeException e) { // ignored } } }
public static void write(@NotNull Bytes bytes, long value) throws BufferOverflowException, IllegalArgumentException { long position = bytes.writePosition(); bytes.write(template); bytes.append(position + VALUE, value, DIGITS); }
long lengthCount = batchAppender.writeMessages(batchTmp.addressForWrite(0), maxMsgSize, 1); int len = (int) lengthCount; dc.wire().bytes().write(batchTmp, (long) Integer.BYTES, len - Integer.BYTES);
try (DocumentContext dc = tailer.readingDocument()) { bytes.clear(); bytes.write(dc.wire().bytes());
wdc.wire().bytes().write(bytes);
HexDumpBytes(BytesStore base, Bytes text) { try { this.base.write(base); this.text.write(text); } catch (BufferOverflowException e) { throw new AssertionError(e); } }
/** * copies the contents of bytes into a direct byte buffer * * @param bytes the bytes to wrap * @return a direct byte buffer contain the {@code bytes} */ @NotNull static Bytes allocateDirect(@NotNull byte[] bytes) throws IllegalArgumentException { Bytes<Void> result = allocateDirect(bytes.length); try { result.write(bytes); } catch (BufferOverflowException e) { throw new AssertionError(e); } return result; }
default boolean read8bit(@NotNull Bytes b) throws BufferUnderflowException, IllegalStateException, BufferOverflowException { b.clear(); if (readRemaining() <= 0) return false; long len0 = BytesInternal.readStopBit(this); if (len0 == -1) return false; int len = Maths.toUInt31(len0); b.write((BytesStore) this, readPosition(), (long) len); readSkip(len); return true; }
@NotNull private net.openhft.lang.io.Bytes toLangBytes(@NotNull BytesStore b, @NotNull Bytes tmpBytes, @NotNull net.openhft.lang.io.NativeBytes lb) { if (b.isDirectMemory()) { // check(b); lb.setStartPositionAddress(b.address(b.start()), b.address(b.readLimit())); // check(lb); } else { tmpBytes.clear(); tmpBytes.write(b); lb.setStartPositionAddress(tmpBytes.address(tmpBytes.start()), tmpBytes.address(tmpBytes.readLimit())); } return lb; }