本文整理匯總了Java中org.jboss.netty.buffer.ChannelBuffer.readable方法的典型用法代碼示例。如果您正苦於以下問題:Java ChannelBuffer.readable方法的具體用法?Java ChannelBuffer.readable怎麽用?Java ChannelBuffer.readable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jboss.netty.buffer.ChannelBuffer
的用法示例。
在下文中一共展示了ChannelBuffer.readable方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: decode
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
// Strip not '$' (0x24) bytes from the beginning
while (buf.readable() && buf.getUnsignedByte(buf.readerIndex()) != 0x24) {
buf.readByte();
}
// Check length and return buffer
if (buf.readableBytes() >= MESSAGE_HEADER) {
int length = buf.getUnsignedShort(buf.readerIndex() + 2);
if (buf.readableBytes() >= length) {
return buf.readBytes(length);
}
}
return null;
}
示例2: decode
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
if (buf.readableBytes() >= MESSAGE_HEADER) {
int length = Integer.parseInt(buf.toString(2, 2, StandardCharsets.US_ASCII)) + 5;
if (buf.readableBytes() >= length) {
ChannelBuffer frame = buf.readBytes(length);
while (buf.readable() && buf.getUnsignedByte(buf.readerIndex()) != '$') {
buf.readByte();
}
return frame;
}
}
return null;
}
示例3: sendResponse
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
private static void sendResponse(Channel channel, int device, long id, int crc) {
if (channel != null) {
ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0);
response.writeByte(device);
response.writeByte(MSG_ACK);
response.writeInt((int) id);
response.writeShort(crc);
response.writeShort(Checksum.crc16(
Checksum.CRC16_XMODEM, response.toByteBuffer()));
ChannelBuffer encoded = ChannelBuffers.dynamicBuffer();
encoded.writeByte(0x01); // header
while (response.readable()) {
int b = response.readByte();
if (b == 0x01 || b == 0x04 || b == 0x10 || b == 0x11 || b == 0x13) {
encoded.writeByte(0x10);
b += 0x20;
}
encoded.writeByte(b);
}
encoded.writeByte(0x04); // ending
channel.write(encoded);
}
}
示例4: messageReceived
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
public void messageReceived(ChannelHandlerContext ctx,
MessageEvent e) throws Exception {
updateNow();
ChannelBuffer buf = (ChannelBuffer) e.getMessage();
while (buf.readable()) {
if (incomingBuffer.remaining() > buf.readableBytes()) {
int newLimit = incomingBuffer.position()
+ buf.readableBytes();
incomingBuffer.limit(newLimit);
}
buf.readBytes(incomingBuffer);
incomingBuffer.limit(incomingBuffer.capacity());
if (!incomingBuffer.hasRemaining()) {
incomingBuffer.flip();
if (incomingBuffer == lenBuffer) {
recvCount++;
readLength();
} else if (!initialized) {
readConnectResult();
lenBuffer.clear();
incomingBuffer = lenBuffer;
initialized = true;
updateLastHeard();
} else {
sendThread.readResponse(incomingBuffer);
lenBuffer.clear();
incomingBuffer = lenBuffer;
updateLastHeard();
}
}
}
wakeupCnxn();
}
示例5: decode
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
// Skip Alive message
while (buf.readable() && Character.isDigit(buf.getByte(buf.readerIndex()))) {
buf.readByte();
}
// Check minimum length
if (buf.readableBytes() < 11) {
return null;
}
// Read flags
int version = buf.getUnsignedByte(buf.readerIndex() + 1);
int offset = 1 + 1 + 3;
if ((version & 0x80) != 0) {
offset += 4;
}
// Get data length
int length = buf.getUnsignedShort(buf.readerIndex() + offset);
offset += 2;
if ((version & 0x40) != 0) {
offset += 3;
}
length += offset; // add header
// Return buffer
if (buf.readableBytes() >= length) {
return buf.readBytes(length);
}
return null;
}
示例6: readFrom
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
public PcepMessage readFrom(ChannelBuffer bb) throws PcepParseException, PcepOutOfBoundMessageException {
if (!bb.readable()) {
throw new PcepParseException("Empty message received");
}
/*
* 0 1 2 3
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Ver | Flags | |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
* Currently Version 1 is supported
* Currently no flags are used, it is all ignored
*/
byte packetVersion = bb.getByte(bb.readerIndex());
packetVersion = (byte) (packetVersion >> SHIFT_FLAG);
PcepFactory factory;
switch (packetVersion) {
case 1:
factory = org.onosproject.pcepio.protocol.ver1.PcepFactoryVer1.INSTANCE;
break;
default:
throw new PcepParseException("Unknown Packet version: " + packetVersion);
}
return factory.getReader().readFrom(bb);
}
示例7: readFrom
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
public BgpMessage readFrom(ChannelBuffer bb, BgpHeader bgpHeader)
throws BgpParseException {
BgpFactory factory;
if (!bb.readable()) {
log.error("Empty message received");
throw new BgpParseException("Empty message received");
}
// TODO: Currently only BGP version 4 is supported
factory = org.onosproject.bgpio.protocol.ver4.BgpFactoryVer4.INSTANCE;
return factory.getReader().readFrom(bb, bgpHeader);
}
示例8: decode
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
char marker = (char) buf.getByte(buf.readerIndex());
while (marker != '*' && marker != '$' && marker != 'X' && buf.readableBytes() > 0) {
buf.skipBytes(1);
if (buf.readableBytes() > 0) {
marker = (char) buf.getByte(buf.readerIndex());
}
}
switch (marker) {
case '*':
// Return text message
int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '#');
if (index != -1) {
ChannelBuffer result = buf.readBytes(index + 1 - buf.readerIndex());
while (buf.readable()
&& (buf.getByte(buf.readerIndex()) == '\r' || buf.getByte(buf.readerIndex()) == '\n')) {
buf.readByte(); // skip new line
}
return result;
}
break;
case '$':
if (messageLength == 0) {
if (buf.readableBytes() == MESSAGE_LONG) {
messageLength = MESSAGE_LONG;
} else {
messageLength = MESSAGE_SHORT;
}
}
if (buf.readableBytes() >= messageLength) {
return buf.readBytes(messageLength);
}
break;
case 'X':
if (buf.readableBytes() >= MESSAGE_SHORT) {
return buf.readBytes(MESSAGE_SHORT);
}
break;
default:
return null;
}
return null;
}