Search in sources :

Example 26 with ArrayInputStream

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

the class StoredPage method storeField.

/**
 *        storeField
 *
 *        @exception StandardException    Standard Derby error policy
 *        @exception IOException          RESOLVE
 */
public void storeField(LogInstant instant, int slot, int fieldNumber, ObjectInput in) throws StandardException, IOException {
    logAction(instant);
    int offset = getFieldOffset(slot, fieldNumber);
    // get the field header information, the input stream came from the log
    ArrayInputStream lrdi = rawDataIn;
    lrdi.setPosition(offset);
    int oldFieldStatus = StoredFieldHeader.readStatus(lrdi);
    int oldFieldDataLength = StoredFieldHeader.readFieldDataLength(lrdi, oldFieldStatus, slotFieldSize);
    int newFieldStatus = StoredFieldHeader.readStatus(in);
    int newFieldDataLength = StoredFieldHeader.readFieldDataLength(in, newFieldStatus, slotFieldSize);
    newFieldStatus = StoredFieldHeader.setFixed(newFieldStatus, false);
    int oldFieldLength = StoredFieldHeader.size(oldFieldStatus, oldFieldDataLength, slotFieldSize) + oldFieldDataLength;
    int newFieldLength = StoredFieldHeader.size(newFieldStatus, newFieldDataLength, slotFieldSize) + newFieldDataLength;
    createSpaceForUpdate(slot, offset, oldFieldLength, newFieldLength);
    rawDataOut.setPosition(offset);
    offset += StoredFieldHeader.write(rawDataOut, newFieldStatus, newFieldDataLength, slotFieldSize);
    if (newFieldDataLength != 0)
        in.readFully(pageData, offset, newFieldDataLength);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayInputStream(org.apache.derby.iapi.services.io.ArrayInputStream)

Example 27 with ArrayInputStream

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

the class StoredPage method logField.

/**
 *        Log a field to the ObjectOutput stream.
 *        <P>
 *        Find the field in the record and then write out the complete
 *        field, i.e. header and data.
 *
 *        @exception StandardException    Standard Derby error policy
 *        @exception IOException          RESOLVE
 *
 *        @see BasePage#logField
 */
public void logField(int slot, int fieldNumber, OutputStream out) throws StandardException, IOException {
    int offset = getFieldOffset(slot, fieldNumber);
    // these reads are always against the page array
    ArrayInputStream lrdi = rawDataIn;
    // now write out the field we are interested in ...
    lrdi.setPosition(offset);
    int fieldStatus = StoredFieldHeader.readStatus(lrdi);
    int fieldDataLength = StoredFieldHeader.readFieldDataLength(lrdi, fieldStatus, slotFieldSize);
    StoredFieldHeader.write(out, fieldStatus, fieldDataLength, slotFieldSize);
    if (fieldDataLength != 0) {
        // and then the data
        out.write(pageData, lrdi.getPosition(), fieldDataLength);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayInputStream(org.apache.derby.iapi.services.io.ArrayInputStream)

Example 28 with ArrayInputStream

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

the class StoredPage method readPageHeader.

/**
 ************************************************************************
 * Page header routines
 **************************************************************************
 */
/**
 * Read the page header from the page array.
 * <p>
 * Read the page header from byte form in the page array into in memory
 * variables.
 */
private void readPageHeader() throws IOException {
    // these reads are always against the page array
    ArrayInputStream lrdi = rawDataIn;
    lrdi.setPosition(PAGE_HEADER_OFFSET);
    long spare;
    isOverflowPage = lrdi.readBoolean();
    setPageStatus(lrdi.readByte());
    setPageVersion(lrdi.readLong());
    slotsInUse = lrdi.readUnsignedShort();
    nextId = lrdi.readInt();
    // page generation (Future Use)
    generation = lrdi.readInt();
    // previous generation (Future Use)
    prevGeneration = lrdi.readInt();
    // BIPage location (Future Use)
    bipLocation = lrdi.readLong();
    // number of deleted rows on page, we start to store this release 2.0.
    // for upgrade reasons, a 0 on disk means -1, so, we subtract one here.
    deletedRowCount = lrdi.readUnsignedShort() - 1;
    // the next 4 (total 22 bytes) are reserved for future
    spare = lrdi.readUnsignedShort();
    // used by encryption
    spare = lrdi.readInt();
    spare = lrdi.readLong();
    spare = lrdi.readLong();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayInputStream(org.apache.derby.iapi.services.io.ArrayInputStream)

Aggregations

ArrayInputStream (org.apache.derby.iapi.services.io.ArrayInputStream)28 ByteArrayInputStream (java.io.ByteArrayInputStream)16 IOException (java.io.IOException)11 StandardException (org.apache.derby.shared.common.error.StandardException)4 PageKey (org.apache.derby.iapi.store.raw.PageKey)3 LogRecord (org.apache.derby.impl.store.raw.log.LogRecord)3 EOFException (java.io.EOFException)2 InputStream (java.io.InputStream)2 ErrorObjectInput (org.apache.derby.iapi.services.io.ErrorObjectInput)2 FormatIdInputStream (org.apache.derby.iapi.services.io.FormatIdInputStream)2 StreamStorable (org.apache.derby.iapi.services.io.StreamStorable)2 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)2 LogCounter (org.apache.derby.impl.store.raw.log.LogCounter)2 StreamLogScan (org.apache.derby.impl.store.raw.log.StreamLogScan)2 CRC32 (java.util.zip.CRC32)1 Compensation (org.apache.derby.iapi.store.raw.Compensation)1 Loggable (org.apache.derby.iapi.store.raw.Loggable)1 RePreparable (org.apache.derby.iapi.store.raw.RePreparable)1 Undoable (org.apache.derby.iapi.store.raw.Undoable)1 LogInstant (org.apache.derby.iapi.store.raw.log.LogInstant)1