本文整理汇总了Java中org.glassfish.grizzly.Buffer.get方法的典型用法代码示例。如果您正苦于以下问题:Java Buffer.get方法的具体用法?Java Buffer.get怎么用?Java Buffer.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.glassfish.grizzly.Buffer
的用法示例。
在下文中一共展示了Buffer.get方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: doDecode
import org.glassfish.grizzly.Buffer; //导入方法依赖的package包/类
protected Request doDecode(Buffer buffer, int len, byte ver) {
//read all byte from buffer first, in case exception during de serialize
short headLen = buffer.getShort();
byte[] bytes = new byte[ (int) headLen];
buffer.get( bytes);
//read request type before payload
byte type = buffer.get();
byte[] payload = new byte[ len - headLen - OFFSET - R_SIZE - H_SIZE ];
buffer.get( payload);
Header header = Header.toHeader( bytes);
// assign serializeVersion
header.setSerializeVersion( ver);
return new Request( header, payload, getRequestType( type));
}
示例3: doDecode
import org.glassfish.grizzly.Buffer; //导入方法依赖的package包/类
protected Request doDecode(Buffer buffer, int len, byte ver) {
//read all byte from buffer first, in case exception during de serialize
short headLen = buffer.getShort();
byte[] bytes = new byte[ (int) headLen];
buffer.get( bytes);
//read request type before payload
byte type = buffer.get();
byte[] payload = new byte[ len - headLen - TOTAL - R_SIZE ];
buffer.get( payload);
Header header = Header.toHeader( bytes);
// assign serializeVersion
header.setSerializeVersion( ver);
return new Request( header, payload, getRequestType( type));
}
示例4: readHeader
import org.glassfish.grizzly.Buffer; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public int readHeader(final Buffer input) throws IOException {
if (input == null) {
throw new IllegalArgumentException("'input' cannot be null.");
}
final byte[] messageLengthArr = new byte[headerLength];
input.get(messageLengthArr);
log.debug("inputRemaining={}", input.remaining());
return ByteBuffer.wrap(messageLengthArr).getInt();
}
示例5: 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);
}