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();
}
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;
}
Aggregations