Example usage for io.netty.buffer ByteBuf alloc

List of usage examples for io.netty.buffer ByteBuf alloc

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf alloc.

Prototype

public abstract ByteBufAllocator alloc();

Source Link

Document

Returns the ByteBufAllocator which created this buffer.

Usage

From source file:org.evilco.mc.defense.common.network.DefenseChannelHandler.java

License:Apache License

/**
 * {@inheritDoc}/*  w  ww .j  a v  a 2s  .c  o  m*/
 */
@Override
protected void encode(ChannelHandlerContext ctx, AbstractDefensePacket msg, List<Object> out) throws Exception {
    ByteBuf target = Unpooled.buffer();

    // find packet identifer
    int packetID = DefensePacketType.valueOf(msg.getClass());

    // write packetID
    target.writeInt(packetID);

    // create packet buffer
    ByteBuf packetBuffer = target.alloc().buffer();

    // write packet
    msg.write(packetBuffer);

    // write packet data
    target.writeBytes(packetBuffer);

    // add output
    out.add(new FMLProxyPacket(target.copy(), CHANNEL_NAME));
}

From source file:org.mobicents.protocols.ss7.m3ua.impl.AspFactoryImpl.java

License:Open Source License

private void processPayload(IpChannelType ipChannelType, ByteBuf byteBuf) {
    M3UAMessage m3UAMessage;/*ww  w  .j a va 2  s .  c o m*/
    if (ipChannelType == IpChannelType.SCTP) {
        try {
            // TODO where is streamNumber stored?
            m3UAMessage = this.messageFactory.createMessage(byteBuf);
            if (this.isHeartBeatEnabled()) {
                this.heartBeatTimer.reset();
            }
            this.read(m3UAMessage);
        } finally {
            ReferenceCountUtil.release(byteBuf);
        }
    } else {
        if (tcpIncBuffer == null) {
            tcpIncBuffer = byteBuf.alloc().compositeBuffer();
        }
        tcpIncBuffer.addComponent(byteBuf);
        tcpIncBuffer.writerIndex(tcpIncBuffer.capacity());

        while (true) {
            m3UAMessage = this.messageFactory.createMessage(tcpIncBuffer);
            if (m3UAMessage == null)
                break;

            if (this.isHeartBeatEnabled()) {
                this.heartBeatTimer.reset();
            }
            this.read(m3UAMessage);
        }
        tcpIncBuffer.discardReadBytes();
    }
}