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

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

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

Bytes.writeInt介绍

暂无

代码示例

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

@Override
  public long recoverAndWriteHeader(@NotNull Wire wire,
                   long timeoutMS,
                   @NotNull final LongValue lastPosition,
                   Sequence sequence) throws UnrecoverableTimeoutException {
    Jvm.warn().on(getClass(), "Clearing an incomplete header so a header can be written");
    wire.bytes().writeInt(0);
    wire.pauser().reset();
    try {
      return wire.writeHeaderOfUnknownLength(timeoutMS, TimeUnit.MILLISECONDS, lastPosition, sequence);
    } catch (@NotNull TimeoutException | EOFException e) {
      throw new UnrecoverableTimeoutException(e);
    }
  }
}

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

static void writeMany(Bytes bytes, int size) {
  for (int i = 0; i < size; i += 32) {
    bytes.writeInt(i);// 4 bytes
    bytes.writeFloat(i);// 4 bytes
    bytes.writeLong(i);// 8 bytes
    bytes.writeDouble(i);// 8 bytes
    bytes.writeUtf8("Hello!!"); // 8 bytes
  }
}

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

@Test
public void testCheckIndexWithWritingDocument2() {
  doTestCheckIndex(
      (appender, n) -> {
        try (final DocumentContext dc = appender.writingDocument()) {
          dc.wire().bytes().writeUtf8("Hello")
              .writeStopBit(12345)
              .writeStopBit(1.2) // float also supported.
              .writeInt(1);
        }
      });
}

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

files = dir.listFiles(pathname -> pathname.getAbsolutePath().endsWith(".cq4"));
wire.bytes().writeInt(wp, Wires.END_OF_DATA);
appender.writeText("hello world  2");

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

private void removeEOF(Path path) throws IOException {
  long blockSize = 64 << 10;
  long chunkSize = OS.pageAlign(blockSize);
  long overlapSize = OS.pageAlign(blockSize / 4);
  final MappedBytes mappedBytes = MappedBytes.mappedBytes(path.toFile(), chunkSize, overlapSize, false);
  mappedBytes.reserve();
  try {
    final Wire wire = WireType.BINARY_LIGHT.apply(mappedBytes);
    final Bytes<?> bytes = wire.bytes();
    bytes.readLimit(bytes.capacity());
    bytes.readSkip(4);
    // move past header
    try (final SingleChronicleQueueStore qs = loadStore(wire)) {
      assertNotNull(qs);
      long l = qs.writePosition();
      long len = Wires.lengthOf(bytes.readVolatileInt(l));
      long eofOffset = l + len + 4L;
      bytes.writePosition(eofOffset);
      bytes.writeInt(0);
    }
  } finally {
    mappedBytes.release();
  }
}

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

@Test
public void testWriteToCorruptedFile() {
  File dir = DirectoryUtils.tempDir("testWriteToCorruptedFile");
  try (ChronicleQueue queue = SingleChronicleQueueBuilder
      .binary(dir)
      .testBlockSize()
      .rollCycle(RollCycles.TEST_DAILY)
      .build()) {
    ExcerptAppender appender = queue.acquireAppender();
    try (DocumentContext dc = appender.writingDocument()) {
      dc.wire().write().text("hello world");
    }
    Bytes bytes;
    long pos;
    try (DocumentContext dc = appender.writingDocument()) {
      bytes = dc.wire().bytes();
      pos = bytes.writePosition() - 4;
    }
    // write as not complete.
    bytes.writeInt(pos, Wires.NOT_COMPLETE_UNKNOWN_LENGTH);
    try (DocumentContext dc = appender.writingDocument()) {
      dc.wire().write().text("hello world 2");
    }
    try (DocumentContext dc = appender.writingDocument()) {
      dc.wire().write().text("hello world 3");
    }
  }
}

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

@Override
public void write(Bytes out, @NotNull Integer toWrite) {
  out.writeInt(toWrite);
}

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

@Override
public void write(@NotNull Bytes out, long size, @NotNull Integer toWrite) {
  out.writeInt(toWrite);
}

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

@Override
public void write(Bytes out, @NotNull List<T> toWrite) {
  out.writeInt(toWrite.size());
  // indexed loop to avoid garbage creation
  //noinspection ForLoopReplaceableByForEach
  for (int i = 0; i < toWrite.size(); i++) {
    elementWriter.write(out, toWrite.get(i));
  }
}

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

@Override
public void write(Bytes out, @NotNull Set<T> toWrite) {
  out.writeInt(toWrite.size());
  toWrite.forEach(e -> elementWriter.write(out, e));
}

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

@Override
public void write(Bytes out, @NotNull Map<K, V> toWrite) {
  out.writeInt(toWrite.size());
  toWrite.forEach((k, v) -> {
    keyWriter.write(out, k);
    valueWriter.write(out, v);
  });
}

代码示例来源:origin: peter-lawrey/Performance-Examples

public ChronicleBytesCASPingPongMain() throws IOException {
  bytes = MappedBytes.mappedBytes("deleteme", OS.pageSize());
  bytes.writeLong(COUNTER_OFFSET, 0L);
  bytes.writeInt(TOGGLE_OFFSET, 0);
}

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

@Override
 public void write(Bytes out, @NotNull HistogramKey toWrite) {
  int accumulatorKeySize = 5;
  out.writeByte(toWrite.granularityOrdinal);
  out.writeInt(toWrite.binId);
  accumulatorKeySize += 2 + toWrite.metric.length();
  writeString(out, toWrite.metric);
  accumulatorKeySize += 2 + (toWrite.source == null ? 0 : toWrite.source.length());
  writeString(out, toWrite.source);
  short numTags = toWrite.tags == null ? 0 : (short) toWrite.tags.length;
  accumulatorKeySize += 2;
  out.writeShort(numTags);
  for (short i = 0; i < numTags; ++i) {
   accumulatorKeySize += 2 + (toWrite.tags[i] == null ? 0 : toWrite.tags[i].length());
   writeString(out, toWrite.tags[i]);
  }
  accumulatorKeySizes.update(accumulatorKeySize);
 }
}

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

@Override
  public long recoverAndWriteHeader(@NotNull Wire wire,
                   long timeoutMS,
                   @NotNull final LongValue lastPosition,
                   Sequence sequence) throws UnrecoverableTimeoutException {
    Jvm.warn().on(getClass(), "Clearing an incomplete header so a header can be written");
    wire.bytes().writeInt(0);
    wire.pauser().reset();
    try {
      return wire.writeHeaderOfUnknownLength(timeoutMS, TimeUnit.MILLISECONDS, lastPosition, sequence);
    } catch (@NotNull TimeoutException | EOFException e) {
      throw new UnrecoverableTimeoutException(e);
    }
  }
}

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

@Override
 public void write(Bytes out, @NotNull HistogramKey toWrite) {
  int accumulatorKeySize = 5;
  out.writeByte(toWrite.granularityOrdinal);
  out.writeInt(toWrite.binId);
  accumulatorKeySize += 2 + toWrite.metric.length();
  writeString(out, toWrite.metric);
  accumulatorKeySize += 2 + (toWrite.source == null ? 0 : toWrite.source.length());
  writeString(out, toWrite.source);
  short numTags = toWrite.tags == null ? 0 : (short) toWrite.tags.length;
  accumulatorKeySize += 2;
  out.writeShort(numTags);
  for (short i = 0; i < numTags; ++i) {
   accumulatorKeySize += 2 + (toWrite.tags[i] == null ? 0 : toWrite.tags[i].length());
   writeString(out, toWrite.tags[i]);
  }
  accumulatorKeySizes.update(accumulatorKeySize);
 }
}

相关文章

微信公众号

最新文章

更多