本文整理匯總了Java中org.jboss.netty.buffer.ChannelBuffer.getInt方法的典型用法代碼示例。如果您正苦於以下問題:Java ChannelBuffer.getInt方法的具體用法?Java ChannelBuffer.getInt怎麽用?Java ChannelBuffer.getInt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jboss.netty.buffer.ChannelBuffer
的用法示例。
在下文中一共展示了ChannelBuffer.getInt方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: decode
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object decode(
ChannelHandlerContext ctx,
Channel channel,
ChannelBuffer buf) throws Exception {
// Check minimum length
if (buf.readableBytes() < MESSAGE_MINIMUM_LENGTH) {
return null;
}
// Read packet
int length = buf.getUnsignedShort(buf.readerIndex());
if (length > 0) {
if (buf.readableBytes() >= (length + 2)) {
return buf.readBytes(length + 2);
}
} else {
int dataLength = buf.getInt(buf.readerIndex() + 4);
if (buf.readableBytes() >= (dataLength + 12)) {
return buf.readBytes(dataLength + 12);
}
}
return null;
}
示例2: decode
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception {
if (buffer.readableBytes() < 6) {
return null;
}
int readerIndex = buffer.readerIndex();
if (buffer.getByte(readerIndex) != 'E' || buffer.getByte(readerIndex + 1) != 'S') {
// special handling for what is probably HTTP
if (bufferStartsWith(buffer, readerIndex, "GET ") ||
bufferStartsWith(buffer, readerIndex, "POST ") ||
bufferStartsWith(buffer, readerIndex, "PUT ") ||
bufferStartsWith(buffer, readerIndex, "HEAD ") ||
bufferStartsWith(buffer, readerIndex, "DELETE ") ||
bufferStartsWith(buffer, readerIndex, "OPTIONS ") ||
bufferStartsWith(buffer, readerIndex, "PATCH ") ||
bufferStartsWith(buffer, readerIndex, "TRACE ")) {
throw new HttpOnTransportException("This is not a HTTP port");
}
// we have 6 readable bytes, show 4 (should be enough)
throw new StreamCorruptedException("invalid internal transport message format, got ("
+ Integer.toHexString(buffer.getByte(readerIndex) & 0xFF) + ","
+ Integer.toHexString(buffer.getByte(readerIndex + 1) & 0xFF) + ","
+ Integer.toHexString(buffer.getByte(readerIndex + 2) & 0xFF) + ","
+ Integer.toHexString(buffer.getByte(readerIndex + 3) & 0xFF) + ")");
}
int dataLen = buffer.getInt(buffer.readerIndex() + 2);
if (dataLen == NettyHeader.PING_DATA_SIZE) {
// discard the messages we read and continue, this is achieved by skipping the bytes
// and returning null
buffer.skipBytes(6);
return null;
}
if (dataLen <= 0) {
throw new StreamCorruptedException("invalid data length: " + dataLen);
}
// safety against too large frames being sent
if (dataLen > NINETY_PER_HEAP_SIZE) {
throw new TooLongFrameException(
"transport content length received [" + new ByteSizeValue(dataLen) + "] exceeded [" + new ByteSizeValue(NINETY_PER_HEAP_SIZE) + "]");
}
if (buffer.readableBytes() < dataLen + 6) {
return null;
}
buffer.skipBytes(6);
return buffer;
}