Example usage for io.netty.buffer ByteBuf readByte

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

Introduction

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

Prototype

public abstract byte readByte();

Source Link

Document

Gets a byte at the current readerIndex and increases the readerIndex by 1 in this buffer.

Usage

From source file:com.bluepowermod.part.tube.TubeStack.java

License:Open Source License

public static TubeStack loadFromPacket(ByteBuf buf) {

    TubeStack stack = new TubeStack(ByteBufUtils.readItemStack(buf),
            ForgeDirection.getOrientation(buf.readByte()), TubeColor.values()[buf.readByte()]);
    stack.speed = buf.readDouble();/*from w ww. j  av a 2 s  .  c o  m*/
    stack.progress = buf.readDouble();
    return stack;
}

From source file:com.builtbroken.icbm.content.crafting.station.small.TileSmallMissileWorkstationClient.java

@Override
public boolean read(ByteBuf buf, int id, EntityPlayer player, PacketType type) {
    if (isClient() && worldObj != null) {
        if (id == 1) {
            this.facing = ForgeDirection.getOrientation(buf.readByte());
            this.bounds = null;
            ItemStack stack = ByteBufUtils.readItemStack(buf);
            if (InventoryUtility.stacksMatch(stack, new ItemStack(Items.apple))) {
                this.setInventorySlotContents(INPUT_SLOT, null);
            } else {
                this.setInventorySlotContents(INPUT_SLOT, stack);
            }//from w w w .  j  a v  a  2s  . co  m
            worldObj.markBlockForUpdate(xi(), yi(), zi());
            return true;
        }
    }
    return false;
}

From source file:com.builtbroken.icbm.content.fragments.EntityFragment.java

@Override
public void readSpawnData(ByteBuf additionalData) {
    try {/*from w w w .ja  v a  2  s . c om*/
        byte i = additionalData.readByte();
        if (i >= 0 && i < FragmentType.values().length) {
            fragmentType = FragmentType.values()[i];
        }
        int blockID = additionalData.readInt();
        if (i > -1) {
            fragmentMaterial = Block.getBlockById(blockID);
        }
        if (additionalData.readBoolean()) {
            renderShape = new Cube(additionalData);
        }
    } catch (Exception e) {
        ICBM.INSTANCE.logger().error("Failed to read spawn data for " + this);
    }
}

From source file:com.builtbroken.icbm.content.launcher.launcher.standard.TileStandardLauncherClient.java

@Override
public void readDescPacket(ByteBuf buf) {
    byte type = buf.readByte();
    if (type == 0) {
        ItemStack missileStack = ByteBufUtils.readItemStack(buf);
        if (missileStack.getItem() instanceof IMissileItem) {
            missile = ((IMissileItem) missileStack.getItem()).toMissile(missileStack);
        } else {/*w  ww .ja  v  a2 s.c o  m*/
            missile = MissileModuleBuilder.INSTANCE.buildMissile(missileStack);
        }
    } else if (type == 1) {
        this.missile = null;
        if (recipe == null) {
            recipe = new StandardMissileCrafting();
        }
        recipe.readBytes(buf);
    } else if (type == 2 || type == 3) {
        this.missile = null;
        this.recipe = null;
        this.isCrafting = false;
    }

    if (missile != null || recipe != null) {
        //TODO modified to fit missile rotation
        renderBounds = new Cube(-1, 0, -1, 2, 10, 2).add(x(), y(), z()).toAABB();
    }
}

From source file:com.butor.netty.handler.codec.ftp.CrlfStringDecoder.java

License:Apache License

/**
 * {@inheritDoc}//from  w  w w .jav  a 2s . c om
 */
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf cb, List<Object> out) throws Exception {
    byte[] data = new byte[maxRequestLengthBytes];
    int lineLength = 0;
    while (cb.isReadable()) {
        byte nextByte = cb.readByte();
        if (nextByte == CR) {
            nextByte = cb.readByte();
            if (nextByte == LF) {
                out.add(new String(data, encoding));
            }
        } else if (nextByte == LF) {
            out.add(new String(data, encoding));
        } else {
            if (lineLength >= maxRequestLengthBytes)
                throw new IllegalArgumentException(
                        "Request size threshold exceeded: [" + maxRequestLengthBytes + "]");
            data[lineLength] = nextByte;
            lineLength += 1;
        }
    }
}

From source file:com.cdg.study.netty.discard.DiscardServerHandler.java

License:Open Source License

@Override
public void channelRead(ChannelHandlerContext context, Object msg) { // Netty? ?? 
    ByteBuf buf = (ByteBuf) msg; // ??   ?? ?
    try {/*  w w w .  j  a v  a 2  s.  c o m*/
        while (buf.isReadable()) { // (1)
            System.out.print((char) buf.readByte());
            System.out.flush();
        }
    } finally {
        buf.release(); //  ?  ? 
    }
}

From source file:com.chat.common.netty.handler.decode.ProtobufVarint32FrameDecoder.java

License:Apache License

/**
 * Reads variable length 32bit int from buffer
 *
 * @return decoded int if buffers readerIndex has been forwarded else nonsense value
 *///  w w w.  j av  a  2  s . c  o m
private static int readRawVarint32(ByteBuf buffer) {
    if (!buffer.isReadable()) {
        return 0;
    }
    buffer.markReaderIndex();
    byte tmp = buffer.readByte();
    if (tmp >= 0) {
        return tmp;
    } else {
        int result = tmp & 127;
        if (!buffer.isReadable()) {
            buffer.resetReaderIndex();
            return 0;
        }
        if ((tmp = buffer.readByte()) >= 0) {
            result |= tmp << 7;
        } else {
            result |= (tmp & 127) << 7;
            if (!buffer.isReadable()) {
                buffer.resetReaderIndex();
                return 0;
            }
            if ((tmp = buffer.readByte()) >= 0) {
                result |= tmp << 14;
            } else {
                result |= (tmp & 127) << 14;
                if (!buffer.isReadable()) {
                    buffer.resetReaderIndex();
                    return 0;
                }
                if ((tmp = buffer.readByte()) >= 0) {
                    result |= tmp << 21;
                } else {
                    result |= (tmp & 127) << 21;
                    if (!buffer.isReadable()) {
                        buffer.resetReaderIndex();
                        return 0;
                    }
                    result |= (tmp = buffer.readByte()) << 28;
                    if (tmp < 0) {
                        throw new CorruptedFrameException("malformed varint.");
                    }
                }
            }
        }
        return result;
    }
}

From source file:com.chen.opensourceframework.netty.copy.DiscardServerHandler.java

License:Apache License

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) { // (2)
    ByteBuf in = (ByteBuf) msg;
    try {// www  . ja va  2  s  .c o  m
        while (in.isReadable()) { // (1)
            System.out.print((char) in.readByte());
            System.out.flush();
        }
    } finally {
        ReferenceCountUtil.release(msg); // (2)
    }
    //
    //        System.out.println("?:...");
    //        ctx.write(msg); // (1)
    //        ctx.flush(); // (2)
}

From source file:com.chiorichan.factory.FileInterpreter.java

License:Mozilla Public License

public static String readLine(ByteBuf buf) {
    if (!buf.isReadable() || buf.readableBytes() < 1)
        return null;

    String op = "";
    while (buf.isReadable() && buf.readableBytes() > 0) {
        byte bb = buf.readByte();
        if (bb == '\n')
            break;
        op += (char) bb;
    }//from   w ww .  ja  v  a  2 s  .c  o  m
    return op;
}

From source file:com.cloudhopper.smpp.pdu.BaseBind.java

License:Apache License

@Override
public void readBody(ByteBuf buffer) throws UnrecoverablePduException, RecoverablePduException {
    this.systemId = ChannelBufferUtil.readNullTerminatedString(buffer);
    this.password = ChannelBufferUtil.readNullTerminatedString(buffer);
    this.systemType = ChannelBufferUtil.readNullTerminatedString(buffer);
    // at this point, we should have at least 3 bytes left
    if (buffer.readableBytes() < 3) {
        throw new NotEnoughDataInBufferException("After parsing systemId, password, and systemType",
                buffer.readableBytes(), 3);
    }//from w  w w .j  ava 2 s.co  m
    this.interfaceVersion = buffer.readByte();
    this.addressRange = ChannelBufferUtil.readAddress(buffer);
}