java.nio.ByteBuffer.asReadOnlyBuffer()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(5.1k)|赞(0)|评价(0)|浏览(167)

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

ByteBuffer.asReadOnlyBuffer介绍

[英]Returns a read-only buffer that shares its content with this buffer.

The returned buffer is guaranteed to be a new instance, even if this buffer is read-only itself. The new buffer's position, limit, capacity and mark are the same as this buffer.

The new buffer shares its content with this buffer, which means this buffer's change of content will be visible to the new buffer. The two buffer's position, limit and mark are independent.
[中]返回与此缓冲区共享其内容的只读缓冲区。
返回的缓冲区保证是一个新实例,即使该缓冲区本身是只读的。新缓冲区的位置、限制、容量和标记与此缓冲区相同。
新缓冲区与此缓冲区共享其内容,这意味着此缓冲区的内容更改将对新缓冲区可见。两个缓冲器的位置、极限和标记是独立的。

代码示例

代码示例来源:origin: prestodb/presto

/**
 * Returns a {@code ByteBuffer} view of the bytes in this {@code ByteString}.
 */
public ByteBuffer asByteBuffer() {
 return ByteBuffer.wrap(data).asReadOnlyBuffer();
}

代码示例来源:origin: apache/incubator-druid

private float[] getCoords(int offset)
 {
  final float[] retVal = new float[numDims];

  final ByteBuffer readOnlyBuffer = data.asReadOnlyBuffer();
  readOnlyBuffer.position(offset);
  readOnlyBuffer.asFloatBuffer().get(retVal);

  return retVal;
 }
}

代码示例来源:origin: libgdx/libgdx

@Override
public LongBuffer asReadOnlyBuffer () {
  LongToByteBufferAdapter buf = new LongToByteBufferAdapter(byteBuffer.asReadOnlyBuffer());
  buf.limit = limit;
  buf.position = position;
  buf.mark = mark;
  return buf;
}

代码示例来源:origin: libgdx/libgdx

@Override
public DoubleBuffer asReadOnlyBuffer () {
  DoubleToByteBufferAdapter buf = new DoubleToByteBufferAdapter(byteBuffer.asReadOnlyBuffer());
  buf.limit = limit;
  buf.position = position;
  buf.mark = mark;
  return buf;
}

代码示例来源:origin: libgdx/libgdx

@Override
public CharBuffer asReadOnlyBuffer () {
  CharToByteBufferAdapter buf = new CharToByteBufferAdapter(byteBuffer.asReadOnlyBuffer());
  buf.limit = limit;
  buf.position = position;
  buf.mark = mark;
  return buf;
}

代码示例来源:origin: libgdx/libgdx

@Override
public LongBuffer asReadOnlyBuffer () {
  LongToByteBufferAdapter buf = new LongToByteBufferAdapter(byteBuffer.asReadOnlyBuffer());
  buf.limit = limit;
  buf.position = position;
  buf.mark = mark;
  return buf;
}

代码示例来源:origin: libgdx/libgdx

@Override
public ShortBuffer asReadOnlyBuffer () {
  ShortToByteBufferAdapter buf = new ShortToByteBufferAdapter(byteBuffer.asReadOnlyBuffer());
  buf.limit = limit;
  buf.position = position;
  buf.mark = mark;
  return buf;
}

代码示例来源:origin: libgdx/libgdx

@Override
public FloatBuffer asReadOnlyBuffer () {
  FloatToByteBufferAdapter buf = new FloatToByteBufferAdapter(byteBuffer.asReadOnlyBuffer());
  buf.limit = limit;
  buf.position = position;
  buf.mark = mark;
  return buf;
}

代码示例来源:origin: libgdx/libgdx

@Override
public CharBuffer asReadOnlyBuffer () {
  CharToByteBufferAdapter buf = new CharToByteBufferAdapter(byteBuffer.asReadOnlyBuffer());
  buf.limit = limit;
  buf.position = position;
  buf.mark = mark;
  return buf;
}

代码示例来源:origin: libgdx/libgdx

@Override
public ShortBuffer asReadOnlyBuffer () {
  ShortToByteBufferAdapter buf = new ShortToByteBufferAdapter(byteBuffer.asReadOnlyBuffer());
  buf.limit = limit;
  buf.position = position;
  buf.mark = mark;
  return buf;
}

代码示例来源:origin: libgdx/libgdx

@Override
public IntBuffer asReadOnlyBuffer () {
  IntToByteBufferAdapter buf = new IntToByteBufferAdapter(byteBuffer.asReadOnlyBuffer());
  buf.limit = limit;
  buf.position = position;
  buf.mark = mark;
  return buf;
}

代码示例来源:origin: libgdx/libgdx

@Override
public IntBuffer asReadOnlyBuffer () {
  IntToByteBufferAdapter buf = new IntToByteBufferAdapter(byteBuffer.asReadOnlyBuffer());
  buf.limit = limit;
  buf.position = position;
  buf.mark = mark;
  return buf;
}

代码示例来源:origin: netty/netty

@Override
public ByteBuffer nioBuffer(int index, int length) {
  return unwrap().nioBuffer(index, length).asReadOnlyBuffer();
}

代码示例来源:origin: libgdx/libgdx

@Override
public FloatBuffer asReadOnlyBuffer () {
  FloatToByteBufferAdapter buf = new FloatToByteBufferAdapter(byteBuffer.asReadOnlyBuffer());
  buf.limit = limit;
  buf.position = position;
  buf.mark = mark;
  return buf;
}

代码示例来源:origin: libgdx/libgdx

@Override
public DoubleBuffer asReadOnlyBuffer () {
  DoubleToByteBufferAdapter buf = new DoubleToByteBufferAdapter(byteBuffer.asReadOnlyBuffer());
  buf.limit = limit;
  buf.position = position;
  buf.mark = mark;
  return buf;
}

代码示例来源:origin: bumptech/glide

public GifHeaderParser setData(@NonNull ByteBuffer data) {
 reset();
 rawData = data.asReadOnlyBuffer();
 rawData.position(0);
 rawData.order(ByteOrder.LITTLE_ENDIAN);
 return this;
}

代码示例来源:origin: bumptech/glide

ByteBuffer getBuffer() {
 return gifDecoder.getData().asReadOnlyBuffer();
}

代码示例来源:origin: apache/incubator-druid

@Override
public void writeTo(WritableByteChannel channel, FileSmoosher smoosher) throws IOException
{
 metaSerdeHelper.writeTo(channel, this);
 Channels.writeFully(channel, theBuffer.asReadOnlyBuffer());
}

代码示例来源:origin: apache/incubator-druid

@Override
public HyperLogLogCollector fromByteBuffer(ByteBuffer buffer, int numBytes)
{
 final ByteBuffer readOnlyBuffer = buffer.asReadOnlyBuffer();
 readOnlyBuffer.limit(readOnlyBuffer.position() + numBytes);
 return HyperLogLogCollector.makeCollector(readOnlyBuffer);
}

代码示例来源:origin: apache/kafka

@Test
public void testReadBytes() {
  byte[] myvar = "Any String you want".getBytes();
  ByteBuffer buffer = ByteBuffer.allocate(myvar.length);
  buffer.put(myvar);
  buffer.rewind();
  this.subTest(buffer);
  // test readonly buffer, different path
  buffer = ByteBuffer.wrap(myvar).asReadOnlyBuffer();
  this.subTest(buffer);
}

相关文章