Java Code Examples for io.netty.buffer.ByteBuf.readChar()

The following are Jave code examples for showing how to use readChar() of the io.netty.buffer.ByteBuf class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: API   File: NetUtil.java   Source Code and License Vote up 5 votes
public static String readStringFromBuffer(ByteBuf buf){
    char[] chars = new char[buf.readInt()];

    for(int i = 0; i < chars.length; i++){
        chars[i] = buf.readChar();
    }

    return new String(chars);
}
 
Example 2
Project: SurvivalMMO   File: Packet.java   Source Code and License Vote up 5 votes
public static String readUTF16(ByteBuf in) {
    in = in.order(ByteOrder.BIG_ENDIAN);
    ByteBuf buffer = in.alloc().buffer();
    char chr;
    while (in.readableBytes() > 1 && (chr = in.readChar()) != 0) {
        buffer.writeChar(chr);
    }

    return buffer.toString(Charsets.UTF_16LE);
}