Search in sources :

Example 1 with CounterOutputStream

use of org.apache.derby.iapi.services.io.CounterOutputStream in project derby by apache.

the class SQLChar method getUTF8Length.

/**
 * Get the number of bytes needed to represent a string in modified
 * UTF-8, which is the encoding used by {@code writeExternal()} and
 * {@code writeUTF()}.
 *
 * @param string the string whose length to calculate
 * @param start start index (inclusive)
 * @param end end index (exclusive)
 */
private int getUTF8Length(String string, int start, int end) throws StandardException {
    CounterOutputStream cs = new CounterOutputStream();
    try {
        FormatIdOutputStream out = new FormatIdOutputStream(cs);
        for (int i = start; i < end; i++) {
            writeUTF(out, string.charAt(i));
        }
        out.close();
    } catch (IOException ioe) {
        throw StandardException.newException(SQLState.LANG_IO_EXCEPTION, ioe, ioe.toString());
    }
    return cs.getCount();
}
Also used : CounterOutputStream(org.apache.derby.iapi.services.io.CounterOutputStream) IOException(java.io.IOException) FormatIdOutputStream(org.apache.derby.iapi.services.io.FormatIdOutputStream)

Example 2 with CounterOutputStream

use of org.apache.derby.iapi.services.io.CounterOutputStream in project derby by apache.

the class D_StoredPage method checkSlotTable.

/**
 *		Checks the slot table.
 *        <p>
 *
 *		1) checks the number of slot entries matches the record count
 *		2) checks the slot table lengths match the field lengths
 *
 *	    @exception  StandardException  Standard exception policy.
 */
public boolean checkSlotTable(PrintStream out) throws StandardException, IOException {
    boolean ok = true;
    int slotCount = page.getSlotsInUse();
    int recordCount = page.recordCount();
    if (slotCount != recordCount) {
        out.println("CORRUPT PAGE: slot count mismatch: slot count " + slotCount + " record count " + recordCount);
        ok = false;
    }
    for (int slot = 0; slot < slotCount; slot++) {
        int recordLength = page.getRecordPortionLength(slot);
        CounterOutputStream counter = new CounterOutputStream();
        counter.setOutputStream(new NullOutputStream());
        int recordId = page.fetchFromSlot(null, slot, new DataValueDescriptor[0], (FetchDescriptor) null, true).getId();
        page.logRecord(slot, page.LOG_RECORD_DEFAULT, recordId, (FormatableBitSet) null, counter, (RecordHandle) null);
        int actualLength = counter.getCount();
        if (actualLength != recordLength) {
            out.println("CORRUPT PAGE: record length mismatch at slot " + slot);
            out.println("              slot entry length " + recordLength);
            out.println("              actual     length " + actualLength);
            ok = false;
        }
    }
    return ok;
}
Also used : CounterOutputStream(org.apache.derby.iapi.services.io.CounterOutputStream) FetchDescriptor(org.apache.derby.iapi.store.raw.FetchDescriptor) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) NullOutputStream(org.apache.derby.iapi.services.io.NullOutputStream)

Aggregations

CounterOutputStream (org.apache.derby.iapi.services.io.CounterOutputStream)2 IOException (java.io.IOException)1 FormatIdOutputStream (org.apache.derby.iapi.services.io.FormatIdOutputStream)1 NullOutputStream (org.apache.derby.iapi.services.io.NullOutputStream)1 FetchDescriptor (org.apache.derby.iapi.store.raw.FetchDescriptor)1 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)1