Example usage for io.netty.buffer ByteBufInputStream read

List of usage examples for io.netty.buffer ByteBufInputStream read

Introduction

In this page you can find the example usage for io.netty.buffer ByteBufInputStream read.

Prototype

@Override
    public int read(byte[] b, int off, int len) throws IOException 

Source Link

Usage

From source file:com.myseti.framework.monitor.net.DecodeProtocol.java

@Override
protected void decode(ChannelHandlerContext chc, ByteBuf bb, List<Object> list) throws Exception {

    if (bb.readableBytes() < Utility.PACKAGE_LENGTH) {
        return;/* ww w . j a v  a2 s .  c o m*/
    } else {

        bb.markReaderIndex();
        ByteBufInputStream stream = new ByteBufInputStream(bb);
        try {
            byte[] len = new byte[4];
            stream.read(len, 0, 4);
            int length = com.myseti.framework.core.HexTools.byte2Int(len);
            System.out.print("" + length + "\n");
            byte[] result = new byte[length - 4];
            stream.read(result, 0, length - 4);
            ProtocolEntity entity = new ProtocolEntity(result);
            list.add(entity);
            System.out.print("DecodeProtocol active! add a new entity \n");
        } catch (Exception ex) {
            System.out.print(ex.toString());
        }
    }

}