Search in sources :

Example 1 with RowInputText

use of org.hsqldb_voltpatches.rowio.RowInputText in project voltdb by VoltDB.

the class TextCache method findNextUsedLinePos.

// fredt - new method
/**
     * Searches from file pointer, pos, and finds the beginning of the first
     * line that contains any non-space character. Increments the row counter
     * when a blank line is skipped.
     *
     * If none found return -1
     */
int findNextUsedLinePos(int pos) {
    try {
        int firstPos = pos;
        int currentPos = pos;
        boolean wasCR = false;
        dataFile.seek(pos);
        while (true) {
            int c = dataFile.read();
            currentPos++;
            switch(c) {
                case CR_CHAR:
                    wasCR = true;
                    break;
                case LF_CHAR:
                    wasCR = false;
                    ((RowInputText) rowIn).skippedLine();
                    firstPos = currentPos;
                    break;
                case ' ':
                    if (wasCR) {
                        wasCR = false;
                        ((RowInputText) rowIn).skippedLine();
                    }
                    break;
                case -1:
                    return -1;
                default:
                    return firstPos;
            }
        }
    } catch (IOException e) {
        throw new HsqlException(e.getMessage(), "", 0);
    }
}
Also used : RowInputText(org.hsqldb_voltpatches.rowio.RowInputText) IOException(java.io.IOException) HsqlException(org.hsqldb_voltpatches.HsqlException)

Example 2 with RowInputText

use of org.hsqldb_voltpatches.rowio.RowInputText in project voltdb by VoltDB.

the class TextCache method readObject.

protected synchronized RowInputInterface readObject(int pos) {
    try {
        ByteArray buffer = new ByteArray(80);
        boolean complete = false;
        boolean wasCR = false;
        int c;
        boolean hasQuote = false;
        boolean wasNormal = false;
        pos = findNextUsedLinePos(pos);
        if (pos == -1) {
            return null;
        }
        dataFile.seek(pos);
        while (!complete) {
            wasNormal = false;
            c = dataFile.read();
            if (c == -1) {
                if (buffer.length() == 0) {
                    return null;
                }
                complete = true;
                if (wasCR) {
                    break;
                }
                if (!cacheReadonly) {
                    dataFile.write(ScriptWriterText.BYTES_LINE_SEP, 0, ScriptWriterText.BYTES_LINE_SEP.length);
                }
                break;
            }
            switch(c) {
                case DOUBLE_QUOTE_CHAR:
                    wasNormal = true;
                    complete = wasCR;
                    wasCR = false;
                    if (isQuoted) {
                        hasQuote = !hasQuote;
                    }
                    break;
                case CR_CHAR:
                    wasCR = !hasQuote;
                    break;
                case LF_CHAR:
                    complete = !hasQuote;
                    break;
                default:
                    wasNormal = true;
                    complete = wasCR;
                    wasCR = false;
            }
            buffer.append(c);
        }
        if (complete) {
            int length = (int) dataFile.getFilePointer() - pos;
            if (wasNormal) {
                length--;
            }
            ((RowInputText) rowIn).setSource(buffer.toString(), pos, length);
            return rowIn;
        }
        return null;
    } catch (IOException e) {
        throw new HsqlException(e.getMessage(), "", 0);
    }
}
Also used : RowInputText(org.hsqldb_voltpatches.rowio.RowInputText) IOException(java.io.IOException) HsqlException(org.hsqldb_voltpatches.HsqlException)

Example 3 with RowInputText

use of org.hsqldb_voltpatches.rowio.RowInputText in project voltdb by VoltDB.

the class TextCache method initBuffers.

protected void initBuffers() {
    if (isQuoted || isAllQuoted) {
        rowIn = new RowInputTextQuoted(fs, vs, lvs, isAllQuoted);
        rowOut = new RowOutputTextQuoted(fs, vs, lvs, isAllQuoted, stringEncoding);
    } else {
        rowIn = new RowInputText(fs, vs, lvs, false);
        rowOut = new RowOutputText(fs, vs, lvs, false, stringEncoding);
    }
}
Also used : RowInputText(org.hsqldb_voltpatches.rowio.RowInputText) RowOutputText(org.hsqldb_voltpatches.rowio.RowOutputText) RowInputTextQuoted(org.hsqldb_voltpatches.rowio.RowInputTextQuoted) RowOutputTextQuoted(org.hsqldb_voltpatches.rowio.RowOutputTextQuoted)

Aggregations

RowInputText (org.hsqldb_voltpatches.rowio.RowInputText)3 IOException (java.io.IOException)2 HsqlException (org.hsqldb_voltpatches.HsqlException)2 RowInputTextQuoted (org.hsqldb_voltpatches.rowio.RowInputTextQuoted)1 RowOutputText (org.hsqldb_voltpatches.rowio.RowOutputText)1 RowOutputTextQuoted (org.hsqldb_voltpatches.rowio.RowOutputTextQuoted)1