@Override
    public int read(char[] cbuf, int off, int len) throws IOException {
        if (len > 0) {
            if (arrayOpenSent) {
                for (int i = 0; i < len; i++) {
                    int ch = inputReader.read();
                    if (ch == -1) {
                        if (i == 0) {
                            if (arrayCloseSent) {
                                return -1;
                            } else {
                                arrayCloseSent = true;
                                cbuf[off] = ']';
                                return 1;
                            }
                        } else {
                            return i;
                        }
                    } else {
                        if (ch == '\n') {
                            cbuf[off + i] = prevCharWasNewLine ? '\n' : ',';
                            prevCharWasNewLine = true;
                            return i + 1;
                        } else {
                            cbuf[off + i] = (char) ch;
                            prevCharWasNewLine = false;
                        }
                    }
                }
                return len;
            } else {
                arrayOpenSent = true;
                cbuf[off] = '[';
                return 1;
            }
        }
        return 0;
    }