本文整理汇总了Java中org.glassfish.grizzly.Buffer.remaining方法的典型用法代码示例。如果您正苦于以下问题:Java Buffer.remaining方法的具体用法?Java Buffer.remaining怎么用?Java Buffer.remaining使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.glassfish.grizzly.Buffer
的用法示例。
在下文中一共展示了Buffer.remaining方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: transformImpl
import org.glassfish.grizzly.Buffer; //导入方法依赖的package包/类
@Override
protected TransformationResult<Buffer, Request> transformImpl(AttributeStorage storage, Buffer input) throws TransformationException {
//Integer packSize = lengthAttribute.get(storage);
VersionLength versionLength = lengthAttribute.get(storage);
if (versionLength == null) {
if (input.remaining() < OFFSET) {
return TransformationResult.createIncompletedResult(input);
}
byte signature = input.get();
byte ver = input.get();
int packSize = input.getInt();
if (signature != SIGNATURE ) {
//channel.close();
throw new TransformationException("expect "+SIGNATURE+" but get "+signature+" "+" "+input.toString());
}
if ( packSize < 0 || packSize > MAX_LEN ) {
//channel.close();
throw new TransformationException(packSize+" Exceed Integer.MAX_VALUE or MAX_LEN");
}
//use versionlength
versionLength = new VersionLength(packSize, ver);
//lengthAttribute.set(storage, packSize);
lengthAttribute.set(storage, versionLength);
}
if (input.remaining() < (versionLength.getLength() -OFFSET) ) {
//logger.info("packSize "+versionLength.getLength() + " remaining "+input.remaining() );
return TransformationResult.createIncompletedResult(input);
}
int tmpLimit = input.limit();
input.limit(input.position() + (versionLength.getLength() -OFFSET) );
Request request= doDecode(input, versionLength.getLength(), versionLength.getVersion() );
input.position(input.limit());
input.limit(tmpLimit);
return TransformationResult.createCompletedResult(
request, input);
}
示例2: handleRead
import org.glassfish.grizzly.Buffer; //导入方法依赖的package包/类
@Override
public NextAction handleRead(FilterChainContext context) throws IOException {
Object message = context.getMessage();
Connection<?> connection = context.getConnection();
Channel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler);
try {
if (message instanceof Buffer) { // 收到新的数据包
Buffer grizzlyBuffer = (Buffer) message; // 缓存
ChannelBuffer frame;
if (previousData.readable()) {
if (previousData instanceof DynamicChannelBuffer) {
previousData.writeBytes(grizzlyBuffer.toByteBuffer());
frame = previousData;
} else {
int size = previousData.readableBytes() + grizzlyBuffer.remaining();
frame = ChannelBuffers.dynamicBuffer(size > bufferSize ? size : bufferSize);
frame.writeBytes(previousData, previousData.readableBytes());
frame.writeBytes(grizzlyBuffer.toByteBuffer());
}
} else {
frame = ChannelBuffers.wrappedBuffer(grizzlyBuffer.toByteBuffer());
}
Object msg;
int savedReadIndex;
do {
savedReadIndex = frame.readerIndex();
try {
msg = codec.decode(channel, frame);
} catch (Exception e) {
previousData = ChannelBuffers.EMPTY_BUFFER;
throw new IOException(e.getMessage(), e);
}
if (msg == Codec2.DecodeResult.NEED_MORE_INPUT) {
frame.readerIndex(savedReadIndex);
return context.getStopAction();
} else {
if (savedReadIndex == frame.readerIndex()) {
previousData = ChannelBuffers.EMPTY_BUFFER;
throw new IOException("Decode without read data.");
}
if (msg != null) {
context.setMessage(msg);
return context.getInvokeAction();
} else {
return context.getInvokeAction();
}
}
} while (frame.readable());
} else { // 其它事件直接往下传
return context.getInvokeAction();
}
} finally {
GrizzlyChannel.removeChannelIfDisconnectd(connection);
}
}
示例3: handleRead
import org.glassfish.grizzly.Buffer; //导入方法依赖的package包/类
@Override
public NextAction handleRead(final FilterChainContext ctx) throws IOException {
final Buffer buffer = ctx.getMessage();
final int sourceBufferLength = buffer.remaining();
// If source buffer doesn't contain header
if (sourceBufferLength < TOTAL) {
// shutdownNow the filterchain processing and store sourceBuffer to be
// used next time
return ctx.getStopAction(buffer);
}
byte signature = buffer.get();
byte ver = buffer.get();
int totalLen = buffer.getInt();
if (signature != SIGNATURE ) {
//channel.close();
throw new IOException("expect "+SIGNATURE+" but get "+signature+" "+ ctx.getAddress().toString()
+" "+buffer.toString());
}
if ( totalLen < 0 || totalLen > MAX_LEN ) {
//channel.close();
throw new IOException(totalLen+" Exceed Integer.MAX_VALUE or MAX_LEN"+" "+ctx.getAddress().toString());
}
if ( sourceBufferLength < totalLen) {
logger.info("notready bufferlength "+sourceBufferLength+" totallen "+totalLen);
// shutdownNow the filterchain processing and store sourceBuffer to be
// used next time
return ctx.getStopAction(buffer);
}
else
logger.info("ready bufferlength "+sourceBufferLength+" totallen "+totalLen);
// shutdownNow the filterchain processing and store sourceBuffer to be
// Check if the source buffer has more than 1 complete GIOP message
// If yes - split up the first message and the remainder
final Buffer remainder = sourceBufferLength > totalLen?
buffer.split( totalLen) : null;
ctx.setMessage( doDecode( buffer, totalLen, ver));
// We can try to dispose the buffer
buffer.tryDispose();
// Instruct FilterChain to store the remainder (if any) and continue execution
return ctx.getInvokeAction(remainder);
}