private int getLengthFromByteArray(byte[] bin){
        ByteBuffer bb = ByteBuffer.wrap(bin);
        bb.order(ByteOrder.BIG_ENDIAN);
        return bb.getShort();
    }
private int getLengthFromByteArray ( byte [ ] bin ) { ByteBuffer bb = ByteBuffer . wrap ( bin ) ; bb . order ( ByteOrder . BIG_ENDIAN ) ; return bb . getShort ( ) ; }
Returns length of packet by reading byte array values.