Example usage for io.netty.buffer ByteBuf readChar

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

Introduction

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

Prototype

public abstract char readChar();

Source Link

Document

Gets a 2-byte UTF-16 character at the current readerIndex and increases the readerIndex by 2 in this buffer.

Usage

From source file:buildcraft.core.network.RPCHandler.java

License:Minecraft Mod Public

private void internalRpcReceive(Object o, RPCMessageInfo info, ByteBuf data) {
    try {//from w ww  .  j  a  v a 2 s  .  c  o m
        short methodIndex = data.readShort();

        MethodMapping m = methods[methodIndex];
        Class[] formals = m.parameters;

        Object[] actuals = new Object[formals.length];

        int expectedParameters = m.hasInfo ? formals.length - 1 : formals.length;

        SerializationContext context = new SerializationContext();

        for (int i = 0; i < expectedParameters; ++i) {
            if (int.class.equals(formals[i])) {
                actuals[i] = data.readInt();
            } else if (float.class.equals(formals[i])) {
                actuals[i] = data.readFloat();
            } else if (char.class.equals(formals[i])) {
                actuals[i] = data.readChar();
            } else {
                actuals[i] = m.mappings[i].read(data, actuals[i], context);
            }
        }

        if (m.hasInfo) {
            actuals[actuals.length - 1] = info;
        }

        m.method.invoke(o, actuals);
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }

}

From source file:buildcraftAdditions.networking.MessageKEBT1.java

License:GNU General Public License

@Override
public void fromBytes(ByteBuf buf) {
    x = buf.readInt();//from w  w w.ja va  2 s  .c o m
    y = buf.readInt();
    z = buf.readInt();
    energy = buf.readInt();
    configuration = new int[6];
    for (int teller = 0; teller < 6; teller++)
        configuration[teller] = buf.readInt();
    length = buf.readInt();
    owner = "";
    for (int teller = 0; teller < length; teller++)
        owner += buf.readChar();
}

From source file:buildcraftAdditions.networking.MessageKEBT2.java

License:GNU General Public License

@Override
public void fromBytes(ByteBuf buf) {
    x = buf.readInt();/*from   w ww .  j a v  a  2s. co m*/
    y = buf.readInt();
    z = buf.readInt();
    configuration = new int[6];
    for (int teller = 0; teller < 6; teller++)
        configuration[teller] = buf.readInt();
    partOfMultiBlock = buf.readBoolean();
    isMaster = buf.readBoolean();
    energy = buf.readInt();
    masterX = buf.readInt();
    masterY = buf.readInt();
    masterZ = buf.readInt();
    energyState = buf.readInt();
    length = buf.readInt();
    owner = "";
    for (int teller = 0; teller < length; teller++)
        owner += buf.readChar();
}

From source file:buildcraftAdditions.utils.PlayerUtils.java

License:GNU General Public License

public static UUID readFromByteBuff(ByteBuf buf) {
    String s = "";
    int length = buf.readInt();
    for (int i = 0; i < length; i++)
        s += buf.readChar();
    return getUUID(s);
}

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

License:Apache License

@Override
public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
    // discard//from   w ww  .j av  a 2 s . c o  m
    ByteBuf in = (ByteBuf) msg;
    try {
        while (in.isReadable()) { // (1)
            System.out.print((char) in.readChar());
            System.out.flush();
        }
    } finally {
        ReferenceCountUtil.release(msg); // (2)
    }
}

From source file:com.chen.opensourceframework.netty.echo.EchoServerHandler.java

License:Apache License

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
    //        ctx.write(msg);
    ByteBuf in = (ByteBuf) msg;
    try {//from  w ww.  ja  va  2 s  . c om
        while (in.isReadable()) { // (1)
            System.out.print(in.readChar());
            System.out.flush();
        }
    } finally {
        ReferenceCountUtil.release(msg); // (2)
    }
}

From source file:com.crowsofwar.gorecore.util.GoreCoreByteBufUtil.java

License:Open Source License

public static String readString(ByteBuf buf) {
    String res = "";
    int length = buf.readInt();
    for (int i = 0; i < length; i++) {
        res += buf.readChar();
    }//from ww  w .j  a va  2s.  c om
    return res;
}

From source file:com.grandhunterman.dnvm.common.Message.java

License:Creative Commons License

private static char readChar(ByteBuf buf) {
    return buf.readChar();
}

From source file:com.kradac.karview.netty.MyDecoder.java

@Override
protected void decode(ChannelHandlerContext chc, ByteBuf bb, List<Object> list) throws Exception {
    if (bb.readableBytes() < 2) {
        return;// w  w w  .j a  v  a2s  .co  m
    }
    bb.markReaderIndex();
    int length = bb.readChar();
    if (length > 150) {
        String data = "";
        while (bb.isReadable()) {
            data += (char) bb.readByte();
        }
        bb.clear();
        if (data.contains("OK") || data.contains("handshake")) {
            if (data.contains("handshake")) {
                chc.channel().write("0%%at");
            }
            if (data.contains("OK")) {
                System.out.println("Respuesta de Comando AT [" + data + "]");
            }
        } else {
            System.err.println("Datos incorrectos enviados al Servidor [" + data + "]");
            chc.channel().disconnect();
        }
    }
    if (bb.readableBytes() < length - 2) {
        bb.resetReaderIndex();
        return;
    }
    in.writeBytes(bb);//Escribimos los bytes
    in.discardReadBytes();//
    in.retain();
    list.add(in);
    bb.clear();//vaciamos el byteBuf
}

From source file:com.ogarproject.ogar.server.net.packet.Packet.java

License:Open Source License

public static String readUTF16(ByteBuf in) {
    in = in.order(ByteOrder.BIG_ENDIAN);
    ByteBuf buffer = in.alloc().buffer();
    char chr;/*  ww  w.  j a v a 2s  .  c  om*/
    while (in.readableBytes() > 1 && (chr = in.readChar()) != 0) {
        buffer.writeChar(chr);
    }

    return buffer.toString(Charsets.UTF_16LE);
}