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

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

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

Bytes.elasticHeapByteBuffer介绍

[英]Returns an elastic wrapper for a heap ByteBuffer which will be resized as required, with the given initial capacity.
[中]返回堆ByteBuffer的弹性包装器,该包装器将根据需要调整大小,并具有给定的初始容量。

代码示例

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

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

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

Bytes b = Bytes.elasticHeapByteBuffer(128);
final ExcerptTailer tailer = queue.createTailer();
tailer.readBytes(b);

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

static Bytes<?> allocateDefaultElasticBytes(long bytesCapacity) {
    if (bytesCapacity <= Bytes.MAX_BYTE_BUFFER_CAPACITY) {
      return Bytes.elasticHeapByteBuffer((int) bytesCapacity);
    } else {
      return Bytes.allocateElasticDirect(bytesCapacity);
    }
  }
}

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

@Override
  protected void setValue(Object o, @NotNull BytesIn read) throws IllegalAccessException, IORuntimeException {
    @NotNull Bytes bytes = (Bytes) field.get(o);
    long stopBit = read.readStopBit();
    if (stopBit == -1) {
      if (bytes != null)
        bytes.release();
      field.set(o, null);
      return;
    }
    int length = Maths.toUInt31(stopBit);
    @NotNull Bytes bs;
    if (bytes == null) {
      bs = Bytes.elasticHeapByteBuffer(length);
    } else {
      bs = bytes;
    }
    Object uo = bs.underlyingObject();
    if (uo instanceof ByteBuffer && !(bs.bytesStore() instanceof NativeBytesStore)) {
      read.read(((ByteBuffer) uo).array(), 0, length);
    } else {
      bs.clear();
      read.read(bs, length);
    }
    bs.readLimit(length);
    field.set(o, bs);
  }
}

相关文章

微信公众号

最新文章

更多