org.glassfish.grizzly.Buffer.toByteBuffer()方法的使用及代码示例

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

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

Buffer.toByteBuffer介绍

[英]Converts this Buffer to a ByteBuffer. If this Buffer is not composite - then returned ByteBuffer's content is a shared subsequence of this buffer's content, with CompositeBuffer this is not guaranteed. The position of the returned ByteBuffer is not guaranteed to be 0, the capacity of the returned ByteBuffer is not guaranteed to be equal to the capacity of this Buffer. It is guaranteed that the result of the returned ByteBuffer's ByteBuffer#remaining() call will be equal to this Buffer's #remaining() call. The Buffer's and ByteBuffer's position, limit, and mark values are not guaranteed to be independent, so it's recommended to save and restore position, limit values if it is planned to change them or ByteBuffer#slice() the returned ByteBuffer.
[中]将此Buffer转换为ByteBuffer。如果此Buffer不是复合的,则返回的ByteBuffer内容是此缓冲区内容的共享子序列,使用CompositeBuffer无法保证这一点。返回的ByteBuffer的位置不保证为0,返回的ByteBuffer的容量不保证等于此Buffer的容量。可以保证返回的ByteBuffer的ByteBuffer#remaining()调用的结果将等于此缓冲区的#remaining()调用。缓冲区和ByteBuffer的位置、限制和标记值不能保证是独立的,因此建议保存和恢复位置、限制值(如果计划更改它们),或ByteBuffer#slice()将返回的ByteBuffer值。

代码示例

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

previousData.writeBytes(grizzlyBuffer.toByteBuffer());
  frame = previousData;
} else {
  frame = ChannelBuffers.dynamicBuffer(size > bufferSize ? size : bufferSize);
  frame.writeBytes(previousData, previousData.readableBytes());
  frame.writeBytes(grizzlyBuffer.toByteBuffer());
frame = ChannelBuffers.wrappedBuffer(grizzlyBuffer.toByteBuffer());

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

previousData.writeBytes(grizzlyBuffer.toByteBuffer());
  frame = previousData;
} else {
  frame = ChannelBuffers.dynamicBuffer(size > bufferSize ? size : bufferSize);
  frame.writeBytes(previousData, previousData.readableBytes());
  frame.writeBytes(grizzlyBuffer.toByteBuffer());
frame = ChannelBuffers.wrappedBuffer(grizzlyBuffer.toByteBuffer());

代码示例来源:origin: com.ning/async-http-client

@Override
public ByteBuffer getResponseBodyAsByteBuffer() throws IOException {
  return responseBody.toByteBuffer();
}

代码示例来源:origin: org.glassfish.tyrus/tyrus-container-grizzly

/**
   * Converts {@link Buffer} to {@link ByteBuffer}.
   *
   * @param buffer buffer to be converted.
   * @return converted buffer.
   */
  public static ByteBuffer convertBuffer(Buffer buffer) {
    return buffer.toByteBuffer();
  }
}

代码示例来源:origin: org.apache.apex/apex-shaded-ning19

@Override
public ByteBuffer getResponseBodyAsByteBuffer() throws IOException {
  return responseBody.toByteBuffer();
}

代码示例来源:origin: org.glassfish.grizzly/grizzly-http-client

@Override
public ByteBuffer getResponseBodyAsByteBuffer() throws IOException {
  return responseBody.toByteBuffer();
}

代码示例来源:origin: io.gatling/async-http-client

@Override
public ByteBuffer getResponseBodyAsByteBuffer() throws IOException {
  return responseBody.toByteBuffer();
}

代码示例来源:origin: javaee/grizzly-ahc

@Override
public ByteBuffer getResponseBodyAsByteBuffer() throws IOException {
  return responseBody.toByteBuffer();
}

代码示例来源:origin: com.ning/async-http-client

Buffer buffer = mm.allocate(PayloadGenerator.MAX_CHUNK_SIZE);
buffer.allowBufferDispose(true);
final long readBytes = bodyLocal.read(buffer.toByteBuffer());
if (readBytes > 0) {
  buffer.position((int) readBytes);

代码示例来源:origin: com.ning/async-http-client

buffer.allowBufferDispose(true);
final long readBytes = bodyLocal.read(buffer.toByteBuffer());
if (readBytes > 0) {
  buffer.position((int) readBytes);

代码示例来源:origin: javaee/grizzly

private static void storeAvailableData(NIOInputStream in, FileChannel fileChannel)
    throws IOException {
  // Get the Buffer directly from NIOInputStream
  final Buffer buffer = in.readBuffer();
  // Retrieve ByteBuffer
  final ByteBuffer byteBuffer = buffer.toByteBuffer();
  
  try {
    while(byteBuffer.hasRemaining()) {
      // Write the ByteBuffer content to the file
      fileChannel.write(byteBuffer);
    }
  } finally {
    // we can try to dispose the buffer
    buffer.tryDispose();
  }
}

代码示例来源:origin: javaee/grizzly

/**
 * Writes next block of compressed data to the output stream.
 */
 protected Buffer deflate(Deflater deflater, MemoryManager memoryManager) {
  final Buffer buffer = memoryManager.allocate(bufferSize);
  final ByteBuffer byteBuffer = buffer.toByteBuffer();
  final byte[] array = byteBuffer.array();
  final int offset = byteBuffer.arrayOffset() + byteBuffer.position();
int len = deflater.deflate(array, offset, bufferSize);
  if (len <= 0) {
    buffer.dispose();
    return null;
  }
  buffer.position(len);
  buffer.trim();
  return buffer;
}

代码示例来源:origin: org.glassfish.grizzly/grizzly-websockets-server

/**
 * Writes next block of compressed data to the output stream.
 */
 protected Buffer deflate(Deflater deflater, MemoryManager memoryManager) {
  final Buffer buffer = memoryManager.allocate(bufferSize);
  final ByteBuffer byteBuffer = buffer.toByteBuffer();
  final byte[] array = byteBuffer.array();
  final int offset = byteBuffer.arrayOffset() + byteBuffer.position();
int len = deflater.deflate(array, offset, bufferSize);
  if (len <= 0) {
    buffer.dispose();
    return null;
  }
  buffer.position(len);
  buffer.trim();
  return buffer;
}

代码示例来源:origin: javaee/grizzly

/**
 * Writes next block of compressed data to the output stream.
 */
 protected Buffer deflate(Deflater deflater, MemoryManager memoryManager) {
  final Buffer buffer = memoryManager.allocate(bufferSize);
  final ByteBuffer byteBuffer = buffer.toByteBuffer();
  final byte[] array = byteBuffer.array();
  final int offset = byteBuffer.arrayOffset() + byteBuffer.position();
int len = deflater.deflate(array, offset, bufferSize);
  if (len <= 0) {
    buffer.dispose();
    return null;
  }
  buffer.position(len);
  buffer.trim();
  return buffer;
}

代码示例来源:origin: javaee/grizzly

/**
 * Writes next block of compressed data to the output stream.
 */
 protected Buffer deflate(Deflater deflater, MemoryManager memoryManager) {
  final Buffer buffer = memoryManager.allocate(bufferSize);
  final ByteBuffer byteBuffer = buffer.toByteBuffer();
  final byte[] array = byteBuffer.array();
  final int offset = byteBuffer.arrayOffset() + byteBuffer.position();
int len = deflater.deflate(array, offset, bufferSize);
  if (len <= 0) {
    buffer.dispose();
    return null;
  }
  buffer.position(len);
  buffer.trim();
  return buffer;
}

代码示例来源:origin: javaee/grizzly

/**
 * Writes next block of compressed data to the output stream.
 */
 protected Buffer deflate(Deflater deflater, MemoryManager memoryManager) {
  final Buffer buffer = memoryManager.allocate(bufferSize);
  final ByteBuffer byteBuffer = buffer.toByteBuffer();
  final byte[] array = byteBuffer.array();
  final int offset = byteBuffer.arrayOffset() + byteBuffer.position();
int len = deflater.deflate(array, offset, bufferSize);
  if (len <= 0) {
    buffer.dispose();
    return null;
  }
  buffer.position(len);
  buffer.trim();
  return buffer;
}

代码示例来源:origin: javaee/grizzly

@Override
  public NextAction handleRead(FilterChainContext ctx) throws IOException {
    Buffer b = ctx.getMessage();
    ByteBuffer bb = b.toByteBuffer();
    total.addAndGet(b.remaining());
    out.getChannel().write(bb);
    if (total.get() == f.length()) {
      future.result(temp);
    }
    return ctx.getStopAction();
  }
});

代码示例来源:origin: javaee/grizzly

/**
 * Read available file content data out of HTTP request and save the
 * chunk into local file output stream
 *
 * @throws IOException
 */
private void readAndSaveAvail() throws IOException {
  while (inputStream.isReady()) {
    final Buffer buffer = inputStream.readBuffer();
    if (buffer.isComposite()) {
      writeCompositeBuffer(buffer);
    } else {
      writeBufferToDiskAndUpdateStats(buffer.toByteBuffer());
    }
  }
}

代码示例来源:origin: javaee/grizzly

/**
 * Read available file content data out of HTTP request and save the
 * chunk into local file output stream
 *
 * @throws IOException
 */
private void readAndSaveAvail() throws IOException {
  while (inputStream.isReady()) {
    final Buffer buffer = inputStream.readBuffer();
    if (buffer.isComposite()) {
      writeCompositeBuffer(buffer);
    } else {
      writeBufferToDiskAndUpdateStats(buffer.toByteBuffer());
    }
  }
}

代码示例来源:origin: javaee/grizzly

@Test
public void testBufferSlice() {
  Buffer b = mm.allocate(10);
  b.putInt(1);
  ByteBuffer bb = b.slice().toByteBuffer().slice();
  bb.rewind();
  bb.putInt(2);
  b.rewind();
  assertEquals(1, b.getInt());
}

相关文章