本文整理汇总了Java中io.netty.buffer.ByteBuf.clear方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuf.clear方法的具体用法?Java ByteBuf.clear怎么用?Java ByteBuf.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.buffer.ByteBuf
的用法示例。
在下文中一共展示了ByteBuf.clear方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decode
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
if (in.readableBytes() <= 0)
return;
Packet packet = null;
byte packetId = in.readByte();
if (packetId < 0) {
in.clear();
throw new DecoderException("WTF, why is the packet id lower than zero?!?! Id: " + packetId);
}
Class<? extends Packet> clazz = PacketManager.getInstance().getPacketClass(packetId);
if (clazz != null)
packet = clazz.newInstance();
if (packet == null) {
throw new DecoderException("Cannot find packet id: " + packetId);
}
packet.decode(in);
out.add(packet);
}
示例2: writeNBT
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public NBTTagCompound writeNBT(NBTTagCompound compound) {
compound.setTag("Pos", NBTUtil.createPosTag(pos));
compound.setInteger("SyncType", type.ordinal());
compound.setInteger("Length", values.length);
ByteBuf buf = Unpooled.buffer();
NBTTagList list = new NBTTagList();
for (int i = 0; i < types.length; i++) {
NBTTagCompound element = new NBTTagCompound();
element.setByte("Type", types[i]);
buf.clear();
PacketUpdateGui.writeField(buf, values[i], types[i]);
element.setByteArray("Value", Arrays.copyOf(buf.array(), buf.writerIndex()));
list.appendTag(element);
}
buf.release();
compound.setTag("Data", list);
compound.setTag("Extra", extraData);
return compound;
}
示例3: decode
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
// 프로토콜 확인을 위해서 5byte를 확인한다.
if (in.readableBytes() < 5) {
// 다음 inbound 시 버퍼에 이전에 전송된 내용이 쌓이므로 버퍼를 비운다.
in.clear();
return;
}
if (isSsl(in)) {
enableSsl(ctx);
} else {
if (!isUnificationMode) {
switchToBinary(ctx);
return;
}
final int magicPacket1 = in.getUnsignedByte(in.readerIndex());
final int magicPacket2 = in.getUnsignedByte(in.readerIndex() + 1);
if (isHttp(magicPacket1, magicPacket2)) {
switchToHttp(ctx);
} else {
switchToBinary(ctx);
}
}
}
示例4: decode
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf,
List<Object> list) throws Exception {
String rawData = byteBuf.toString(CharsetUtil.UTF_8);
HTTPRequest request = HTTPRequestParser.parseRequest(rawData);
list.add(request);
byteBuf.clear();
}
示例5: encode
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
protected void encode(ChannelHandlerContext ctx, IOutgoingPacket packet, ByteBuf out)
{
if (out.order() != _byteOrder)
{
out = out.order(_byteOrder);
}
try
{
if (packet.write(new PacketWriter(out)))
{
if (out.writerIndex() > _maxPacketSize)
{
throw new IllegalStateException("Packet (" + packet + ") size (" + out.writerIndex() + ") is bigger than the limit (" + _maxPacketSize + ")");
}
}
else
{
// Avoid sending the packet
out.clear();
}
}
catch (Throwable e)
{
LOGGER.log(Level.WARNING, "Failed sending Packet(" + packet + ")", e);
// Avoid sending the packet if some exception happened
out.clear();
}
}