本文整理汇总了Java中org.glassfish.grizzly.Buffer.flip方法的典型用法代码示例。如果您正苦于以下问题:Java Buffer.flip方法的具体用法?Java Buffer.flip怎么用?Java Buffer.flip使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.glassfish.grizzly.Buffer
的用法示例。
在下文中一共展示了Buffer.flip方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleWrite
import org.glassfish.grizzly.Buffer; //导入方法依赖的package包/类
@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); // 不需要关闭
Object msg = context.getMessage();
codec.encode(channel, channelBuffer, msg);
GrizzlyChannel.removeChannelIfDisconnectd(connection);
Buffer buffer = connection.getTransport().getMemoryManager().allocate(channelBuffer.readableBytes());
buffer.put(channelBuffer.toByteBuffer());
buffer.flip();
buffer.allowBufferDispose(true);
context.setMessage(buffer);
} finally {
GrizzlyChannel.removeChannelIfDisconnectd(connection);
}
return context.getInvokeAction();
}
示例2: handleWrite
import org.glassfish.grizzly.Buffer; //导入方法依赖的package包/类
@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); // 不需要关闭
Object msg = context.getMessage();
codec.encode(channel, channelBuffer, msg);
GrizzlyChannel.removeChannelIfDisconnectd(connection);
Buffer buffer = connection.getTransport().getMemoryManager().allocate(channelBuffer.readableBytes());
buffer.put(channelBuffer.toByteBuffer());
buffer.flip();
buffer.allowBufferDispose(true);
context.setMessage(buffer);
} finally {
GrizzlyChannel.removeChannelIfDisconnectd(connection);
}
return context.getInvokeAction();
}
示例3: transformImpl
import org.glassfish.grizzly.Buffer; //导入方法依赖的package包/类
@Override
protected TransformationResult<Request, Buffer> transformImpl(AttributeStorage storage, Request request) throws TransformationException {
byte ver = request.getHeader().getSerializeVersion() ;
int pLen = request.getPayload() == null ? 0 : request.getPayload().length;
byte[] header = request.getHeader().toByte();
// encoding length , and check the max value of integer, should be 2GB
int totalLen = OFFSET + header.length + pLen + R_SIZE + H_SIZE;
if ( totalLen > Integer.MAX_VALUE ) {
throw new TransformationException( totalLen +" exceeding Integer.MAX_VALUE");
}
//logger.info("total "+totalLen+" hd "+header.length+" payload "+pLen);
// Retrieve the memory manager
//final MemoryManager memoryManager = ctx.getConnection().getTransport().getMemoryManager();
// allocate the buffer of required size
final Buffer bout = obtainMemoryManager(storage).allocate(totalLen);
// Instruct the FilterChain to call the next filter
bout.put(SIGNATURE);
bout.put(ver);
bout.putInt(totalLen);
bout.putShort((short) header.length);
bout.put(header);
// request type
bout.put((byte) request.getType().ordinal());
bout.put( request.getPayload());
bout.flip();
bout.allowBufferDispose(true);
return TransformationResult.createCompletedResult(bout, null);
}