本文整理匯總了Java中org.jboss.netty.buffer.ChannelBuffer.getBytes方法的典型用法代碼示例。如果您正苦於以下問題:Java ChannelBuffer.getBytes方法的具體用法?Java ChannelBuffer.getBytes怎麽用?Java ChannelBuffer.getBytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jboss.netty.buffer.ChannelBuffer
的用法示例。
在下文中一共展示了ChannelBuffer.getBytes方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: decode
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object decode(
ChannelHandlerContext ctx,
Channel channel,
ChannelBuffer buf) throws Exception {
if (buf.readableBytes() < 20) {
return null;
}
// Swap byte order for legacy protocol
if (buf.getUnsignedByte(buf.readerIndex()) == 0x80) {
int length = buf.readableBytes();
byte[] bytes = new byte[length];
buf.getBytes(buf.readerIndex(), bytes);
ChannelBuffer result = (ChannelBuffer) super.decode(
ctx, channel, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, bytes));
if (result != null) {
buf.skipBytes(result.readableBytes());
}
return result;
}
return super.decode(ctx, channel, buf);
}
示例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) {
ChannelBuffer lengthBuffer = ChannelBuffers.dynamicBuffer();
buf.getBytes(buf.readerIndex() + MESSAGE_HEADER - 4 - 1, lengthBuffer, 4);
int length = Integer.parseInt(lengthBuffer.toString(StandardCharsets.US_ASCII), 16) + MESSAGE_HEADER + 1;
if (buf.readableBytes() >= length) {
ChannelBuffer frame = ChannelBuffers.dynamicBuffer();
int endIndex = buf.readerIndex() + length;
while (buf.readerIndex() < endIndex) {
byte b = buf.readByte();
if (b == 0x7D) {
switch (buf.readByte()) {
case 0x01:
frame.writeByte(0x7D);
break;
case 0x02:
frame.writeByte(0x5B);
break;
case 0x03:
frame.writeByte(0x5D);
break;
case 0x04:
frame.writeByte(0x2C);
break;
case 0x05:
frame.writeByte(0x2A);
break;
default:
throw new IllegalArgumentException();
}
} else {
frame.writeByte(b);
}
}
return frame;
}
}
return null;
}