net.openhft.chronicle.bytes.Bytes.write()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(175)

本文整理了Java中net.openhft.chronicle.bytes.Bytes.write()方法的一些代码示例,展示了Bytes.write()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bytes.write()方法的具体详情如下:
包路径:net.openhft.chronicle.bytes.Bytes
类名称:Bytes
方法名:write

Bytes.write介绍

暂无

代码示例

代码示例来源:origin: OpenHFT/Chronicle-Queue

private void append() {
  outbound.clear();
  outbound.write(new byte[msgSize], 0, msgSize);
  appender.writeBytes(outbound);
}

代码示例来源:origin: OpenHFT/Chronicle-Queue

@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();
  }
}

代码示例来源:origin: OpenHFT/Chronicle-Queue

@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());
    }
  }
}

代码示例来源:origin: net.openhft/chronicle-bytes

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);
}

代码示例来源:origin: net.openhft/chronicle-map

private void writePayload(Bytes payload, Bytes destination) {
  destination.writeByte(BOOTSTRAP_TIME_HUNK);
  destination.write(payload, payload.readPosition(), payload.readRemaining());
}

代码示例来源:origin: com.wavefront/proxy

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();
 }
}

代码示例来源:origin: OpenHFT/Chronicle-Queue

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;
  }
}

代码示例来源:origin: net.openhft/chronicle-bytes

/**
 * 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);
}

代码示例来源:origin: net.openhft/chronicle-bytes

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);
  }
}

代码示例来源:origin: wavefrontHQ/java

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();
 }
}

代码示例来源:origin: OpenHFT/Chronicle-Queue

@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
    }
  }
}

代码示例来源:origin: net.openhft/chronicle-bytes

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);
}

代码示例来源:origin: OpenHFT/Chronicle-Queue

long lengthCount = batchAppender.writeMessages(batchTmp.addressForWrite(0), maxMsgSize, 1);
int len = (int) lengthCount;
dc.wire().bytes().write(batchTmp, (long) Integer.BYTES, len - Integer.BYTES);

代码示例来源:origin: OpenHFT/Chronicle-Queue

try (DocumentContext dc = tailer.readingDocument()) {
  bytes.clear();
  bytes.write(dc.wire().bytes());

代码示例来源:origin: OpenHFT/Chronicle-Queue

dc.wire().bytes().write(nbs);
try (DocumentContext dc = tailer.readingDocument()) {
  bytes.clear();
  bytes.write(dc.wire().bytes());

代码示例来源:origin: OpenHFT/Chronicle-Queue

wdc.wire().bytes().write(bytes);

代码示例来源:origin: net.openhft/chronicle-bytes

HexDumpBytes(BytesStore base, Bytes text) {
  try {
    this.base.write(base);
    this.text.write(text);
  } catch (BufferOverflowException e) {
    throw new AssertionError(e);
  }
}

代码示例来源:origin: net.openhft/chronicle-bytes

/**
 * 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;
}

代码示例来源:origin: net.openhft/chronicle-bytes

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;
}

代码示例来源:origin: net.openhft/chronicle-engine

@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;
  }

相关文章

微信公众号

最新文章

更多