public int read(char[] buf, int n) {
        if (buf == null || n <= 0) return 0;

        char[] res = new char[4];
        for (int i = 0; i < n; i += 4) {
            int resLen = read4(res);
            int len = Math.min(resLen, n - i);
            for (int k = 0; k < len; ++k) buf[i + k] = res[k];
            // reach EOF
            if (resLen < 4) return i + len;
        }
        return n;
    }