本文整理匯總了Java中org.jboss.netty.buffer.ChannelBuffer.readerIndex方法的典型用法代碼示例。如果您正苦於以下問題:Java ChannelBuffer.readerIndex方法的具體用法?Java ChannelBuffer.readerIndex怎麽用?Java ChannelBuffer.readerIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jboss.netty.buffer.ChannelBuffer
的用法示例。
在下文中一共展示了ChannelBuffer.readerIndex方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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() < 10) {
return null;
}
int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ',');
if (index != -1) {
int length = index - buf.readerIndex() + Integer.parseInt(
buf.toString(buf.readerIndex() + 3, index - buf.readerIndex() - 3, StandardCharsets.US_ASCII));
if (buf.readableBytes() >= length) {
return buf.readBytes(length);
}
}
return null;
}
示例2: decodeJ1708
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
private void decodeJ1708(Position position, ChannelBuffer buf, int length) {
int end = buf.readerIndex() + length;
while (buf.readerIndex() < end) {
int mark = buf.readUnsignedByte();
int len = BitUtil.between(mark, 0, 6);
int type = BitUtil.between(mark, 6, 8);
int id = buf.readUnsignedByte();
if (type == 3) {
id += 256;
}
String value = ChannelBuffers.hexDump(buf.readBytes(len - 1));
if (type == 2 || type == 3) {
position.set("pid" + id, value);
}
}
}
示例3: decode
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ')') + 1;
if (endIndex > 0) {
ChannelBuffer frame = ChannelBuffers.dynamicBuffer();
while (buf.readerIndex() < endIndex) {
int b = buf.readByte();
if (b == '=') {
frame.writeByte(buf.readByte() ^ '=');
} else {
frame.writeByte(b);
}
}
return frame;
}
return null;
}
示例4: decode
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
if (buf.readableBytes() < 80) {
return null;
}
int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0x02);
if (index == -1) {
index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0x04);
if (index == -1) {
return null;
}
}
index += 2; // checksum
if (buf.readableBytes() >= index - buf.readerIndex()) {
return buf.readBytes(index - buf.readerIndex());
}
return null;
}
示例5: readString
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
private static String readString(ChannelBuffer buf) {
String result = null;
int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0);
if (index > buf.readerIndex()) {
result = buf.readBytes(index - buf.readerIndex()).toString(StandardCharsets.US_ASCII);
}
buf.readByte();
return result;
}
示例6: decode
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
if (buf.readableBytes() < 5) {
return null;
}
int length = 2 + 2; // head and tail
if (buf.getByte(buf.readerIndex()) == 0x78) {
length += 1 + buf.getUnsignedByte(buf.readerIndex() + 2);
} else {
length += 2 + buf.getUnsignedShort(buf.readerIndex() + 2);
}
if (buf.readableBytes() >= length && buf.getUnsignedShort(buf.readerIndex() + length - 2) == 0x0d0a) {
return buf.readBytes(length);
}
int endIndex = buf.readerIndex() - 1;
do {
endIndex = buf.indexOf(endIndex + 1, buf.writerIndex(), (byte) 0x0d);
if (endIndex > 0 && buf.writerIndex() > endIndex + 1 && buf.getByte(endIndex + 1) == 0x0a) {
return buf.readBytes(endIndex + 2 - buf.readerIndex());
}
} while (endIndex > 0);
return null;
}
示例7: decode
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
if (buf.readableBytes() < 10) {
return null;
}
int beginIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("$$"));
if (beginIndex == -1) {
return null;
} else if (beginIndex > buf.readerIndex()) {
buf.readerIndex(beginIndex);
}
int length;
int flagIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("AA"));
if (flagIndex != -1 && flagIndex - beginIndex == 6) {
length = Integer.parseInt(buf.toString(buf.readerIndex() + 2, 4, StandardCharsets.US_ASCII));
} else {
length = Integer.parseInt(buf.toString(buf.readerIndex() + 2, 2, StandardCharsets.US_ASCII), 16);
}
if (length <= buf.readableBytes()) {
return buf.readBytes(length);
}
return null;
}
示例8: isCompressed
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
public boolean isCompressed(ChannelBuffer buffer) {
int offset = buffer.readerIndex();
return buffer.readableBytes() >= 3 &&
buffer.getByte(offset) == LZFChunk.BYTE_Z &&
buffer.getByte(offset + 1) == LZFChunk.BYTE_V &&
(buffer.getByte(offset + 2) == LZFChunk.BLOCK_TYPE_COMPRESSED || buffer.getByte(offset + 2) == LZFChunk.BLOCK_TYPE_NON_COMPRESSED);
}
示例9: decode
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
buf.readerIndex(buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 'E'));
int endIndex = buf.indexOf(buf.readerIndex() + 1, buf.writerIndex(), (byte) 'E');
if (endIndex > 0) {
return buf.readBytes(endIndex - buf.readerIndex());
} else {
return buf.readBytes(buf.readableBytes()); // assume full frame
}
}
示例10: decode
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object decode(
ChannelHandlerContext ctx,
Channel channel,
ChannelBuffer buf) throws Exception {
if (buf.readableBytes() < 2) {
return null;
}
int index = buf.indexOf(buf.readerIndex() + 1, buf.writerIndex(), (byte) 0x04);
if (index != -1) {
ChannelBuffer result = ChannelBuffers.buffer(ByteOrder.LITTLE_ENDIAN, index + 1 - buf.readerIndex());
while (buf.readerIndex() <= index) {
int b = buf.readUnsignedByte();
if (b == 0x10) {
result.writeByte(buf.readUnsignedByte() - 0x20);
} else {
result.writeByte(b);
}
}
return result;
}
return null;
}
示例11: decode
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
if (buf.readableBytes() < 2) {
return null;
}
int index = buf.indexOf(buf.readerIndex() + 1, buf.writerIndex(), (byte) 0x7e);
if (index != -1) {
ChannelBuffer result = ChannelBuffers.buffer(index + 1 - buf.readerIndex());
while (buf.readerIndex() <= index) {
int b = buf.readUnsignedByte();
if (b == 0x7d) {
int ext = buf.readUnsignedByte();
if (ext == 0x01) {
result.writeByte(0x7d);
} else if (ext == 0x02) {
result.writeByte(0x7e);
}
} else {
result.writeByte(b);
}
}
return result;
}
return null;
}
示例12: decodeObd
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
private void decodeObd(Position position, ChannelBuffer buf, int length) {
int end = buf.readerIndex() + length;
while (buf.readerIndex() < end) {
int parameterLength = buf.getUnsignedByte(buf.readerIndex()) >> 4;
int mode = buf.readUnsignedByte() & 0x0F;
position.add(ObdDecoder.decode(mode, ChannelBuffers.hexDump(buf.readBytes(parameterLength - 1))));
}
}
示例13: isCompressed
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
public boolean isCompressed(ChannelBuffer buffer) {
if (buffer.readableBytes() < HEADER.length) {
return false;
}
final int offset = buffer.readerIndex();
for (int i = 0; i < HEADER.length; ++i) {
if (buffer.getByte(offset + i) != HEADER[i]) {
return false;
}
}
return true;
}
示例14: parsePackedIp4Prefixes
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
* Parses a message that contains encoded IPv4 network prefixes.
* <p>
* The IPv4 prefixes are encoded in the form:
* <Length, Prefix> where Length is the length in bits of the IPv4 prefix,
* and Prefix is the IPv4 prefix (padded with trailing bits to the end
* of an octet).
*
* @param totalLength the total length of the data to parse
* @param message the message with data to parse
* @return a collection of parsed IPv4 network prefixes
* @throws BgpMessage.BgpParseException
*/
private static Collection<Ip4Prefix> parsePackedIp4Prefixes(
int totalLength,
ChannelBuffer message)
throws BgpMessage.BgpParseException {
Collection<Ip4Prefix> result = new ArrayList<>();
if (totalLength == 0) {
return result;
}
// Parse the data
byte[] buffer = new byte[Ip4Address.BYTE_LENGTH];
int dataEnd = message.readerIndex() + totalLength;
while (message.readerIndex() < dataEnd) {
int prefixBitlen = message.readUnsignedByte();
int prefixBytelen = (prefixBitlen + 7) / 8; // Round-up
if (message.readerIndex() + prefixBytelen > dataEnd) {
String errorMsg = "Malformed Network Prefixes";
throw new BgpMessage.BgpParseException(errorMsg);
}
message.readBytes(buffer, 0, prefixBytelen);
Ip4Prefix prefix = Ip4Prefix.valueOf(Ip4Address.valueOf(buffer),
prefixBitlen);
result.add(prefix);
}
return result;
}
示例15: 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;
}