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

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

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

Buffer.flip介绍

[英]Flips this buffer. The limit is set to the current position and then the position is set to zero. If the mark is defined then it is discarded.

After a sequence of channel-read or put operations, invoke this method to prepare for a sequence of channel-write or relative get operations. For example:

buf.put(magic);    // Prepend header 
in.read(buf);      // Read data into rest of buffer 
buf.flip();        // Flip buffer 
out.write(buf);    // Write header + data to channel

This method is often used in conjunction with the Buffer#compact method when transferring data from one place to another.
[中]翻转此缓冲区。将限制设置为当前位置,然后将该位置设置为零。如果定义了标记,则该标记将被丢弃。
在一系列通道读取或put操作之后,调用此方法以准备一系列通道写入或相对get操作。例如:

buf.put(magic);    // Prepend header 
in.read(buf);      // Read data into rest of buffer 
buf.flip();        // Flip buffer 
out.write(buf);    // Write header + data to channel

在将数据从一个地方传输到另一个地方时,此方法通常与缓冲区压缩方法结合使用。

代码示例

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

@Override
public NextAction handleWrite(FilterChainContext context) throws IOException {
  Connection<?> connection = context.getConnection();
  GrizzlyChannel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler);
  try {
    ChannelBuffer channelBuffer = ChannelBuffers.dynamicBuffer(1024); // Do not need to close
    Object msg = context.getMessage();
    codec.encode(channel, channelBuffer, msg);
    GrizzlyChannel.removeChannelIfDisconnected(connection);
    Buffer buffer = connection.getTransport().getMemoryManager().allocate(channelBuffer.readableBytes());
    buffer.put(channelBuffer.toByteBuffer());
    buffer.flip();
    buffer.allowBufferDispose(true);
    context.setMessage(buffer);
  } finally {
    GrizzlyChannel.removeChannelIfDisconnected(connection);
  }
  return context.getInvokeAction();
}

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

@Override
public NextAction handleWrite(FilterChainContext context) throws IOException {
  Connection<?> connection = context.getConnection();
  GrizzlyChannel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler);
  try {
    ChannelBuffer channelBuffer = ChannelBuffers.dynamicBuffer(1024); // Do not need to close
    Object msg = context.getMessage();
    codec.encode(channel, channelBuffer, msg);
    GrizzlyChannel.removeChannelIfDisconnected(connection);
    Buffer buffer = connection.getTransport().getMemoryManager().allocate(channelBuffer.readableBytes());
    buffer.put(channelBuffer.toByteBuffer());
    buffer.flip();
    buffer.allowBufferDispose(true);
    context.setMessage(buffer);
  } finally {
    GrizzlyChannel.removeChannelIfDisconnected(connection);
  }
  return context.getInvokeAction();
}

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

@Override
public byte[] getBodyPartBytes() {
  byte[] bytes = contentBytes.get();
  if (bytes != null) {
    return bytes;
  }
  final Buffer b = content.getContent();
  final int origPos = b.position();
  bytes = new byte[b.remaining()];
  b.get(bytes);
  b.flip();
  b.position(origPos);
  contentBytes.compareAndSet(null, bytes);
  return bytes;
}

代码示例来源:origin: org.glassfish.shoal/shoal-gms-impl

@Override
public Buffer flip() {
  grizzlyBuffer.flip();
  return this;
}

代码示例来源:origin: org.shoal/shoal-gms-impl

@Override
public Buffer flip() {
  grizzlyBuffer.flip();
  return this;
}

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

static Buffer copy(final MemoryManager memoryManager,
    final Buffer buffer) {
  final Buffer tmpBuf = memoryManager.allocate(buffer.remaining());
  tmpBuf.put(buffer);
  return tmpBuf.flip();
}

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

static Buffer copy(final MemoryManager memoryManager,
    final Buffer buffer) {
  final Buffer tmpBuf = memoryManager.allocate(buffer.remaining());
  tmpBuf.put(buffer);
  return tmpBuf.flip();
}

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

static Buffer copy(final MemoryManager memoryManager,
    final Buffer buffer) {
  final Buffer tmpBuf = memoryManager.allocate(buffer.remaining());
  tmpBuf.put(buffer);
  return tmpBuf.flip();
}

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

static Buffer copy(final MemoryManager memoryManager,
    final Buffer buffer) {
  final Buffer tmpBuf = memoryManager.allocate(buffer.remaining());
  tmpBuf.put(buffer);
  return tmpBuf.flip();
}

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

static Buffer copy(final MemoryManager memoryManager,
    final Buffer buffer) {
  final Buffer tmpBuf = memoryManager.allocate(buffer.remaining());
  tmpBuf.put(buffer);
  return tmpBuf.flip();
}

代码示例来源:origin: org.mule.glassfish.grizzly/grizzly-framework

static Buffer copy(final MemoryManager memoryManager,
    final Buffer buffer) {
  final Buffer tmpBuf = memoryManager.allocate(buffer.remaining());
  tmpBuf.put(buffer);
  return tmpBuf.flip();
}

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

static Buffer copy(final MemoryManager memoryManager,
    final Buffer buffer) {
  final Buffer tmpBuf = memoryManager.allocate(buffer.remaining());
  tmpBuf.put(buffer);
  return tmpBuf.flip();
}

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

static Buffer copy(final MemoryManager memoryManager,
    final Buffer buffer) {
  final Buffer tmpBuf = memoryManager.allocate(buffer.remaining());
  tmpBuf.put(buffer);
  return tmpBuf.flip();
}

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

static Buffer copy(final MemoryManager memoryManager,
    final Buffer buffer) {
  final Buffer tmpBuf = memoryManager.allocate(buffer.remaining());
  tmpBuf.put(buffer);
  return tmpBuf.flip();
}

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

static Buffer copy(final MemoryManager memoryManager,
    final Buffer buffer) {
  final Buffer tmpBuf = memoryManager.allocate(buffer.remaining());
  tmpBuf.put(buffer);
  return tmpBuf.flip();
}

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

static Buffer copy(final MemoryManager memoryManager,
    final Buffer buffer) {
  final Buffer tmpBuf = memoryManager.allocate(buffer.remaining());
  tmpBuf.put(buffer);
  return tmpBuf.flip();
}

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

static Buffer copy(final MemoryManager memoryManager,
    final Buffer buffer) {
  final Buffer tmpBuf = memoryManager.allocate(buffer.remaining());
  tmpBuf.put(buffer);
  return tmpBuf.flip();
}

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

private void sendEndResponse(final FilterChainContext ctx) throws IOException {
  final Connection connection = ctx.getConnection();
  final MemoryManager mm = connection.getTransport().getMemoryManager();
  final Buffer buffer = mm.allocate(6);
  buffer.put((byte) 'A');
  buffer.put((byte) 'B');
  buffer.putShort((short) 2);
  buffer.put(AjpConstants.JK_AJP13_END_RESPONSE);
  buffer.put((byte) 1);
  buffer.flip();
  buffer.allowBufferDispose(true);
  ctx.write(buffer);
}

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

private void sendEndResponse(final FilterChainContext ctx) throws IOException {
  final Connection connection = ctx.getConnection();
  final MemoryManager mm = connection.getTransport().getMemoryManager();
  final Buffer buffer = mm.allocate(6);
  buffer.put((byte) 'A');
  buffer.put((byte) 'B');
  buffer.putShort((short) 2);
  buffer.put(AjpConstants.JK_AJP13_END_RESPONSE);
  buffer.put((byte) 1);
  buffer.flip();
  buffer.allowBufferDispose(true);
  ctx.write(buffer);
}

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

private void sendEndResponse(final FilterChainContext ctx) throws IOException {
  final Connection connection = ctx.getConnection();
  final MemoryManager mm = connection.getTransport().getMemoryManager();
  final Buffer buffer = mm.allocate(6);
  buffer.put((byte) 'A');
  buffer.put((byte) 'B');
  buffer.putShort((short) 2);
  buffer.put(AjpConstants.JK_AJP13_END_RESPONSE);
  buffer.put((byte) 1);
  buffer.flip();
  buffer.allowBufferDispose(true);
  ctx.write(buffer);
}

相关文章