本文整理了Java中io.netty.buffer.ByteBuf.readerIndex()
方法的一些代码示例,展示了ByteBuf.readerIndex()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteBuf.readerIndex()
方法的具体详情如下:
包路径:io.netty.buffer.ByteBuf
类名称:ByteBuf
方法名:readerIndex
[英]Returns the readerIndex of this buffer.
[中]返回此缓冲区的readerIndex。
代码示例来源:origin: netty/netty
@Override
public long skip(long bytes) throws IOException {
int readable = buffer.readableBytes();
if (readable < bytes) {
bytes = readable;
}
buffer.readerIndex((int) (buffer.readerIndex() + bytes));
return bytes;
}
代码示例来源:origin: wildfly/wildfly
/**
* Returns the closing status code as per <a href="http://tools.ietf.org/html/rfc6455#section-7.4">RFC 6455</a>. If
* a getStatus code is set, -1 is returned.
*/
public int statusCode() {
ByteBuf binaryData = content();
if (binaryData == null || binaryData.capacity() == 0) {
return -1;
}
binaryData.readerIndex(0);
int statusCode = binaryData.readShort();
binaryData.readerIndex(0);
return statusCode;
}
代码示例来源:origin: redisson/redisson
@Override
public Object decode(ByteBuf buf, State state) throws IOException {
int decompressSize = buf.readInt();
ByteBuf out = ByteBufAllocator.DEFAULT.buffer(decompressSize);
try {
LZ4SafeDecompressor decompressor = factory.safeDecompressor();
ByteBuffer outBuffer = out.internalNioBuffer(out.writerIndex(), out.writableBytes());
int pos = outBuffer.position();
decompressor.decompress(buf.internalNioBuffer(buf.readerIndex(), buf.readableBytes()), outBuffer);
int compressedLength = outBuffer.position() - pos;
out.writerIndex(compressedLength);
return innerCodec.getValueDecoder().decode(out, state);
} finally {
out.release();
}
}
};
代码示例来源:origin: org.opendaylight.openflowjava/simple-client
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
ByteBuf bb = (ByteBuf) msg;
if (LOG.isDebugEnabled()) {
LOG.debug("<< {}", ByteBufUtils.byteBufToHexString(bb));
}
int length = bb.getUnsignedShort(bb.readerIndex() + LENGTH_INDEX_IN_HEADER);
LOG.trace("SimpleClientHandler - start of read");
byte[] message = new byte[length];
bb.readBytes(message);
scenarioHandler.addOfMsg(message);
LOG.trace("end of read");
}
代码示例来源:origin: org.opendaylight.netconf/netconf-netty-util
@Override
public void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out) throws IOException, SAXException {
if (in.isReadable()) {
if (LOG.isTraceEnabled()) {
LOG.trace("Received to decode: {}", ByteBufUtil.hexDump(in));
if (!isWhitespace(in.readByte())) {
in.readerIndex(in.readerIndex() - 1);
break;
if (in.readerIndex() != 0 && LOG.isWarnEnabled()) {
final byte[] strippedBytes = new byte[in.readerIndex()];
in.getBytes(0, strippedBytes, 0, in.readerIndex());
LOG.warn("XML message with unwanted leading bytes detected. Discarded the {} leading byte(s): '{}'",
in.readerIndex(), ByteBufUtil.hexDump(Unpooled.wrappedBuffer(strippedBytes)));
代码示例来源:origin: apache/drill
public void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws IOException {
logger.trace("Channel closed before decoding the message of {} bytes", msg.readableBytes());
msg.skipBytes(msg.readableBytes());
return;
if(logger.isTraceEnabled()) {
logger.trace("Trying to decrypt the encrypted message of size: {} with maxWrappedSize", msg.readableBytes());
msg.getBytes(msg.readerIndex(), lengthOctets.array(), 0, RpcConstants.LENGTH_FIELD_LENGTH);
final int wrappedMsgLength = lengthOctets.getInt(0);
msg.skipBytes(RpcConstants.LENGTH_FIELD_LENGTH);
msg.getBytes(msg.readerIndex(), wrappedMsg, 0, wrappedMsgLength);
if(logger.isTraceEnabled()) {
logger.trace("Successfully decrypted incoming message. Length after decryption: {}", decodedMsg.length);
代码示例来源:origin: Graylog2/graylog2-server
LOG.trace("Attempting to decode DNS record [{}]", dnsRecord);
try {
final ByteBuf byteBuf = dnsRawRecord.content();
ipAddressBytes = new byte[byteBuf.readableBytes()];
int readerIndex = byteBuf.readerIndex();
byteBuf.getBytes(readerIndex, ipAddressBytes);
} finally {
LOG.trace("The IP address has [{}] bytes", ipAddressBytes.length);
LOG.trace("The resulting IP address is [{}]", ipAddress.getHostAddress());
代码示例来源:origin: apache/hive
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out)
throws Exception {
if (in.readableBytes() < 4) {
return;
}
in.markReaderIndex();
int msgSize = in.readInt();
checkSize(msgSize);
if (in.readableBytes() < msgSize) {
// Incomplete message in buffer.
in.resetReaderIndex();
return;
}
try {
ByteBuffer nioBuffer = maybeDecrypt(in.nioBuffer(in.readerIndex(), msgSize));
Input kryoIn = new Input(new ByteBufferInputStream(nioBuffer));
Object msg = kryos.get().readClassAndObject(kryoIn);
LOG.trace("Decoded message of type {} ({} bytes)",
msg != null ? msg.getClass().getName() : msg, msgSize);
out.add(msg);
} finally {
in.skipBytes(msgSize);
}
}
代码示例来源:origin: qunarcorp/qmq
@Override
protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf in, List<Object> list) throws Exception {
if (in.readableBytes() < RemotingHeader.MIN_HEADER_SIZE + RemotingHeader.LENGTH_FIELD) return;
int magicCode = in.getInt(in.readerIndex() + RemotingHeader.LENGTH_FIELD);
if (DEFAULT_MAGIC_CODE != magicCode) {
throw new IOException("Illegal Data, MagicCode=" + Integer.toHexString(magicCode));
int total = in.readInt();
if (in.readableBytes() < total) {
in.resetReaderIndex();
return;
short headerSize = in.readShort();
RemotingHeader remotingHeader = decodeHeader(in);
代码示例来源:origin: alibaba/fescar
@Override
public boolean decode(ByteBuf in) {
int i = in.readableBytes();
try {
short len = in.readShort();
if (len > 0) {
byte[] bs = new byte[len];
this.setVersion(new String(bs, UTF8));
len = in.readShort();
if (len > 0) {
byte[] bs = new byte[len];
this.setApplicationId(new String(bs, UTF8));
len = in.readShort();
if (len > 0) {
byte[] bs = new byte[len];
LOGGER.debug(in.writerIndex() == in.readerIndex() ? "true" : "false" + this);
代码示例来源:origin: traccar/traccar
int idLength = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0x00) - buf.readerIndex();
String id = buf.readBytes(idLength).toString(StandardCharsets.US_ASCII);
buf.readByte();
int blockEnd = buf.readInt() + buf.readerIndex();
int nameLength = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0x00) - buf.readerIndex();
String name = buf.readBytes(nameLength).toString(StandardCharsets.US_ASCII);
buf.readByte();
position.setLatitude(buf.readDoubleLE());
position.setAltitude(buf.readDoubleLE());
position.setSpeed(buf.readShort());
position.setCourse(buf.readShort());
position.set(Position.KEY_SATELLITES, buf.readByte());
} else {
switch (dataType) {
case 1:
int len = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0x00) - buf.readerIndex();
position.set(name, buf.readBytes(len).toString(StandardCharsets.US_ASCII));
buf.readByte();
break;
case 3:
position.set(name, buf.readInt());
break;
case 4:
buf.readerIndex(blockEnd);
代码示例来源:origin: waterguo/antsdb
int pos = in.readerIndex();
int size = BufferUtils.readLongInt(in);
int sequence = in.readByte() & 0xff;
if (!in.isReadable(size)) {
in.readerIndex(pos);
return;
packet.retain();
try {
in.readerIndex(pos + size + 4);
_log.trace("packet {}", ByteBufUtil.dump(packet));
out.add(packet);
代码示例来源:origin: org.opendaylight.controller/netconf-netty-util
@Override
public void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out) throws IOException, SAXException {
if (in.isReadable()) {
if (LOG.isTraceEnabled()) {
LOG.trace("Received to decode: {}", ByteBufUtil.hexDump(in));
if (!isWhitespace(in.readByte())) {
in.readerIndex(in.readerIndex() - 1);
break;
if (in.readerIndex() != 0 && LOG.isWarnEnabled()) {
final byte[] strippedBytes = new byte[in.readerIndex()];
in.getBytes(0, strippedBytes, 0, in.readerIndex());
LOG.warn("XML message with unwanted leading bytes detected. Discarded the {} leading byte(s): '{}'",
in.readerIndex(), ByteBufUtil.hexDump(Unpooled.wrappedBuffer(strippedBytes)));
代码示例来源:origin: apache/drill
if (component.readableBytes() > wrapSizeLimit) {
throw new RpcException(String.format("Component Chunk size: %d is greater than the wrapSizeLimit: %d",
component.readableBytes(), wrapSizeLimit));
component.getBytes(component.readerIndex(), origMsg, 0, component.readableBytes());
if(logger.isTraceEnabled()) {
logger.trace("Trying to encrypt chunk of size:{} with wrapSizeLimit:{} and chunkMode: {}",
component.readableBytes(), wrapSizeLimit);
final byte[] wrappedMsg = saslCodec.wrap(origMsg, 0, component.readableBytes());
if(logger.isTraceEnabled()) {
logger.trace("Successfully encrypted message, original size: {} Final Size: {}",
component.readableBytes(), wrappedMsg.length);
代码示例来源:origin: whizzosoftware/WZWave
cbuf.addComponent(previousBuf.copy());
cbuf.addComponent(in);
cbuf.writerIndex(previousBuf.readableBytes() + in.readableBytes());
data = cbuf;
if (data.readableBytes() == 1 && isSingleByteFrame(data, data.readerIndex())) {
out.add(createSingleByteFrame(data));
} else {
boolean foundFrame = false;
for (int searchStartIx = data.readerIndex(); searchStartIx < data.readerIndex() + data.readableBytes(); searchStartIx++) {
if (data.getByte(searchStartIx) == DataFrame.START_OF_FRAME) {
int frameEndIx = scanForFrame(data, searchStartIx);
if (frameEndIx > 0) {
if (searchStartIx > data.readerIndex() && isSingleByteFrame(data, searchStartIx - 1)) {
data.readerIndex(searchStartIx - 1);
out.add(createSingleByteFrame(data));
} else if (searchStartIx > data.readerIndex()) {
data.readerIndex(searchStartIx);
in.readBytes(in.readableBytes());
logger.trace("Done processing received data: {}", out);
代码示例来源:origin: netty/netty
@Override
public int readableBytes() {
if (terminated) {
return buffer.readableBytes();
} else {
return Integer.MAX_VALUE - buffer.readerIndex();
}
}
代码示例来源:origin: redisson/redisson
@Override
public Object decode(ByteBuf buf, State state) throws IOException {
int decompressSize = buf.readInt();
ByteBuf out = ByteBufAllocator.DEFAULT.buffer(decompressSize);
try {
LZ4SafeDecompressor decompressor = factory.safeDecompressor();
ByteBuffer outBuffer = out.internalNioBuffer(out.writerIndex(), out.writableBytes());
int pos = outBuffer.position();
decompressor.decompress(buf.internalNioBuffer(buf.readerIndex(), buf.readableBytes()), outBuffer);
int compressedLength = outBuffer.position() - pos;
out.writerIndex(compressedLength);
return innerCodec.getValueDecoder().decode(out, state);
} finally {
out.release();
}
}
};
代码示例来源:origin: alipay/sofa-bolt
public void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
if (in.readableBytes() >= lessLen) {
in.markReaderIndex();
byte protocol = in.readByte();
if (in.readableBytes() > 2 + 1) {
int startIndex = in.readerIndex();
in.markReaderIndex();
if (type == RpcCommandType.REQUEST || type == RpcCommandType.REQUEST_ONEWAY) {
if (in.readableBytes() >= RpcProtocolV2.getRequestHeaderLength() - 3) {
short cmdCode = in.readShort();
byte ver2 = in.readByte();
int requestId = in.readInt();
byte serializer = in.readByte();
byte protocolSwitchValue = in.readByte();
int timeout = in.readInt();
short classLen = in.readShort();
short headerLen = in.readShort();
int contentLen = in.readInt();
byte[] clazz = null;
byte[] header = null;
代码示例来源:origin: wildfly/wildfly
return;
if (buffer.readableBytes() == 1) {
protocolViolation(ctx, "Invalid close frame body");
int idx = buffer.readerIndex();
buffer.readerIndex(0);
int statusCode = buffer.readShort();
if (statusCode >= 0 && statusCode <= 999 || statusCode >= 1004 && statusCode <= 1006
|| statusCode >= 1012 && statusCode <= 2999) {
buffer.readerIndex(idx);
代码示例来源:origin: traccar/traccar
format = formats.get(buf.getUnsignedByte(buf.readerIndex()));
} else if (!formats.isEmpty()) {
format = formats.values().iterator().next();
break;
case 0x07:
position.setLatitude(buf.readInt() * 0.000001);
break;
case 0x08:
position.setLongitude(buf.readInt() * 0.000001);
break;
case 0x09:
position.setAltitude(buf.readShort() * 0.1);
break;
case 0x0a:
position.setCourse(buf.readShort() * 0.1);
break;
case 0x0b:
break;
case 0x14:
position.set(Position.KEY_RSSI, buf.readShort());
break;
case 0x16:
内容来源于网络,如有侵权,请联系作者删除!