public byte[] filter(byte[] data) {
        int found = 0;
        for (int i=0; i<data.length; i++) {
            if (data[i] == UsbSerialPort.CHAR_XON || data[i] == UsbSerialPort.CHAR_XOFF)
                found++;
        }
        if(found == 0)
            return data;
        byte[] filtered = new byte[data.length - found];
        for (int i=0, j=0; i<data.length; i++) {
            if (data[i] == UsbSerialPort.CHAR_XON)
                xon = true;
            else if(data[i] == UsbSerialPort.CHAR_XOFF)
                xon = false;
            else
                filtered[j++] = data[i];
        }
        return filtered;
    }
Filter XON/XOFF from read() data and remember

@param data unfiltered data
@return filtered data
usbSerialForAndroid/src/main/java/com/hoho/android/usbserial/util/XonXoffFilter.java