当前位置: 首页>>代码示例>>Java>>正文


Java ByteBuf.clear方法代码示例

本文整理汇总了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);
}
 
开发者ID:CentauriCloud,项目名称:CentauriCloud,代码行数:25,代码来源:PacketDecoder.java

示例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;
}
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:21,代码来源:PacketDescription.java

示例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);
        }
    }
}
 
开发者ID:veritasware,项目名称:neto,代码行数:30,代码来源:ProtocolUnificationHandler.java

示例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();
}
 
开发者ID:D3adspaceEnterprises,项目名称:echidna,代码行数:12,代码来源:HTTPDecoder.java

示例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();
	}
}
 
开发者ID:rubenswagner,项目名称:L2J-Global,代码行数:31,代码来源:PacketEncoder.java


注:本文中的io.netty.buffer.ByteBuf.clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。