當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。