本文整理了Java中io.netty.buffer.ByteBuf.skipBytes()
方法的一些代码示例,展示了ByteBuf.skipBytes()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteBuf.skipBytes()
方法的具体详情如下:
包路径:io.netty.buffer.ByteBuf
类名称:ByteBuf
方法名:skipBytes
[英]Increases the current readerIndex by the specified length in this buffer.
[中]在此缓冲区中将当前readerIndex增加指定的长度。
代码示例来源:origin: netty/netty
private void exceededFrameLength(ByteBuf in, long frameLength) {
long discard = frameLength - in.readableBytes();
tooLongFrameLength = frameLength;
if (discard < 0) {
// buffer contains more bytes then the frameLength so we can discard all now
in.skipBytes((int) frameLength);
} else {
// Enter the discard mode and discard everything received so far.
discardingTooLongFrame = true;
bytesToDiscard = discard;
in.skipBytes(in.readableBytes());
}
failIfNecessary(true);
}
代码示例来源:origin: wildfly/wildfly
static String readUsAscii(ByteBuf buffer, int length) {
String s = buffer.toString(buffer.readerIndex(), length, CharsetUtil.US_ASCII);
buffer.skipBytes(length);
return s;
}
}
代码示例来源:origin: netty/netty
@Override
protected void decodeLast(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception {
switch (buffer.readableBytes()) {
case 0:
return;
case 1:
// Ignore the last TC_RESET
if (buffer.getByte(buffer.readerIndex()) == ObjectStreamConstants.TC_RESET) {
buffer.skipBytes(1);
return;
}
}
decode(ctx, buffer, out);
}
代码示例来源: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: com.github.cloudfoundry-community/nats-client
@Override
protected ServerFrame decodeCommand(ChannelHandlerContext context, String command, ByteBuf in) {
LOGGER.trace("Decoding '{}'", command);
throwTooLongFrameException(context);
final String body = in.toString(in.readerIndex(), length, CharsetUtil.UTF_8);
in.skipBytes(length);
in.skipBytes(ByteBufUtil.CRLF.length);
return new ServerPublishFrame(id, subject, replyTo, body);
代码示例来源:origin: org.apache.distributedlog/distributedlog-protocol
if (LOG.isTraceEnabled()) {
LOG.trace("Found position {} beyond {}", recordStream.getCurrentPosition(), dlsn);
if (LOG.isTraceEnabled()) {
LOG.trace("Found position {} beyond {}", currTxId, txId);
in.skipBytes(length);
if (LOG.isTraceEnabled()) {
LOG.trace("Skipped Record with TxId {} DLSN {}",
currTxId, recordStream.getCurrentPosition());
代码示例来源:origin: runelite/runelite
@Override
public void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception
if (in.readableBytes() < 8)
if (size + 3 + breaks > in.readableBytes())
logger.trace("Index {} archive {}: Not enough data yet {} > {}", index, file, size + 3 + breaks, in.readableBytes());
return;
in.skipBytes(3); // skip index/file
int bytesToRead = Math.min(bytesInBlock, size - compressedData.writerIndex());
logger.trace("{}/{}: reading block {}/{}, read so far this block: {}, file status: {}/{}",
index, file,
(totalRead % CHUNK_SIZE), CHUNK_SIZE,
logger.trace("{}/{}: done downloading file, remaining buffer {}",
index, file,
in.readableBytes());
代码示例来源:origin: traccar/traccar
buf.skipBytes(2); // header
buf.readShort(); // length
ByteBuf id = buf.readSlice(7);
int command = buf.readUnsignedShort();
photos.get(imageIndex).writeBytes(buf, buf.readableBytes() - 2 - 2);
buf.skipBytes(6);
} else if (command == MSG_RFID) {
for (int i = 0; i < 15; i++) {
String sentence = buf.toString(buf.readerIndex(), buf.readableBytes() - 4, StandardCharsets.US_ASCII);
代码示例来源:origin: weibocom/motan
private void decodeV1(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
long startTime = System.currentTimeMillis();
in.resetReaderIndex();
in.skipBytes(2);// skip magic num
byte messageType = (byte) in.readShort();
long requestId = in.readLong();
int dataLength = in.readInt();
// FIXME 如果dataLength过大,可能导致问题
if (in.readableBytes() < dataLength) {
in.resetReaderIndex();
return;
}
checkMaxContext(dataLength, ctx, messageType == MotanConstants.FLAG_REQUEST, requestId);
byte[] data = new byte[dataLength];
in.readBytes(data);
decode(data, out, messageType == MotanConstants.FLAG_REQUEST, requestId).setStartTime(startTime);
}
代码示例来源:origin: traccar/traccar
format = formats.get(buf.getUnsignedByte(buf.readerIndex()));
} else if (!formats.isEmpty()) {
format = formats.values().iterator().next();
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:
break;
default:
buf.skipBytes(getTagLength(tag));
break;
代码示例来源: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);
msg.skipBytes(wrappedMsgLength);
代码示例来源:origin: cloudfoundry-community/java-nats
@Override
protected ServerFrame decodeCommand(ChannelHandlerContext context, String command, ByteBuf in) {
LOGGER.trace("Decoding '{}'", command);
throwTooLongFrameException(context);
final String body = in.toString(in.readerIndex(), length, CharsetUtil.UTF_8);
in.skipBytes(length);
in.skipBytes(ByteBufUtil.CRLF.length);
return new ServerPublishFrame(id, subject, replyTo, body);
代码示例来源:origin: org.opendaylight.bgpcep/pcep-spi
final int type = bytes.readUnsignedShort();
final int length = bytes.readUnsignedShort();
if (length > bytes.readableBytes()) {
throw new PCEPDeserializerException("Wrong length specified. Passed: " + length + "; Expected: <= " + bytes.readableBytes()
+ ".");
LOG.trace("Parsing PCEP TLV : {}", ByteBufUtil.hexDump(tlvBytes));
final Optional<VendorInformationTlv> viTlv = this.viTlvReg.parseVendorInformationTlv(enterpriseNumber, tlvBytes);
if(viTlv.isPresent()) {
LOG.trace("Parsed VENDOR-INFORMATION TLV {}.", viTlv.get());
viTlvs.add(viTlv.get());
final Tlv tlv = this.tlvReg.parseTlv(type, tlvBytes);
if(tlv != null) {
LOG.trace("Parsed PCEP TLV {}.", tlv);
addTlv(builder, tlv);
bytes.skipBytes(TlvUtil.getPadding(TlvUtil.HEADER_SIZE + length, TlvUtil.PADDED_TO));
代码示例来源:origin: redisson/redisson
private void decodeNonJdkCompatible(ChannelHandlerContext ctx, ByteBuf in) {
try {
in.skipBytes(unwrap(ctx, in, in.readerIndex(), in.readableBytes()));
} catch (Throwable cause) {
handleUnwrapThrowable(ctx, cause);
}
}
代码示例来源:origin: jwpttcg66/NettyGameServer
byteBuf.skipBytes(2);
netMessageHead.setLength(byteBuf.readInt());
netMessageHead.setVersion(byteBuf.readByte());
short cmd = byteBuf.readShort();
netMessageHead.setCmd(cmd);
netMessageHead.setSerial(byteBuf.readInt());
short tockenLength = byteBuf.readShort();
byte[] tockenBytes = new byte[tockenLength];
ByteBuf tockenBuf = byteBuf.readBytes(tockenBytes);
int byteLength = byteBuf.readableBytes();
byte[] bytes = new byte[byteLength];
byteBuf.getBytes(byteBuf.readerIndex(), bytes);
netMessageBody.setBytes(bytes);
netMessage.setNetMessageHead(netMessageHead);
代码示例来源:origin: weibocom/motan
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
if (in.readableBytes() <= MotanConstants.NETTY_HEADER) {
return;
}
in.markReaderIndex();
short type = in.readShort();
if (type != MotanConstants.NETTY_MAGIC_TYPE) {
in.resetReaderIndex();
throw new MotanFrameworkException("NettyDecoder transport header not support, type: " + type);
}
in.skipBytes(1);
int rpcVersion = (in.readByte() & 0xff) >>> 3;
switch (rpcVersion) {
case 0:
decodeV1(ctx, in, out);
break;
case 1:
decodeV2(ctx, in, out);
break;
default:
decodeV2(ctx, in, out);
}
}
代码示例来源:origin: netty/netty
private void discardingTooLongFrame(ByteBuf in) {
long bytesToDiscard = this.bytesToDiscard;
int localBytesToDiscard = (int) Math.min(bytesToDiscard, in.readableBytes());
in.skipBytes(localBytesToDiscard);
bytesToDiscard -= localBytesToDiscard;
this.bytesToDiscard = bytesToDiscard;
failIfNecessary(false);
}
代码示例来源:origin: wildfly/wildfly
private static int readLengthField(ByteBuf buffer) {
int length = getSignedInt(buffer, buffer.readerIndex());
buffer.skipBytes(LENGTH_FIELD_SIZE);
return length;
}
代码示例来源:origin: traccar/traccar
if (buf.getUnsignedByte(buf.readerIndex()) == 0) {
String imei = buf.toString(buf.readerIndex(), 15, StandardCharsets.US_ASCII);
buf.skipBytes(4); // marker
position.setAltitude(buf.readShort());
position.setCourse(buf.readUnsignedShort());
代码示例来源: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);
msg.skipBytes(component.readableBytes());
component.skipBytes(component.readableBytes());
内容来源于网络,如有侵权,请联系作者删除!