Code example for ByteBuffer

Methods: remaining, rewind

0
        int lenData;
 
        if (data == null) {
            lenData = 0;
        } else { 
            data.rewind();
            lenData = data.remaining();
        } 
        mh.setLengthData(lenData);
        sendHeader(rc, mh);
        if (lenData > 0) {
            rc.sendAll(data);
        } 
    } 
 
    /** 
     * Send a message with cmd, token, status followed by the data. 
     * 
     * The length data field will be filled in as appropriate 
     * @param cmd for the header 
     * @param token for the header