Package org.apache.derby.iapi.services.io

Examples of org.apache.derby.iapi.services.io.ArrayInputStream


                columnId >= recordHeader.getFirstField(),
                "first column on page > expected");
    }

    // these reads are always against the page array
    ArrayInputStream lrdi = rawDataIn;

        // set read position to data portion of record to check.
    int offset = getRecordOffset(slot);
    lrdi.setPosition(offset + recordHeader.size());

        // skip until you get to the record in question.
    for (int i = recordHeader.getFirstField(); i < columnId; i++)
      skipField(lrdi);
View Full Code Here


      if (numberFields != 2) // End of column chain.
        return null;

      // these reads are always against the page array
      ArrayInputStream lrdi = rawDataIn;

      // The 2nd field is the pointer to the next page in column chain.

      int offset = getRecordOffset(slot) + recordHeader.size();
      lrdi.setPosition(offset);

      // skip the first field
      skipField(lrdi);

      // the 2nd field should be <pageId, recordId> pair, return the
      // pageId part and skip over the length.
      int fieldStatus = StoredFieldHeader.readStatus(lrdi);
      int fieldLength = StoredFieldHeader.readFieldDataLength
        (lrdi, fieldStatus, slotFieldSize);

      long ovflowPage = CompressedNumber.readLong((InputStream) lrdi);
      int  ovflowRid  = CompressedNumber.readInt((InputStream) lrdi);

      if (SanityManager.DEBUG)
            {
        if (!StoredFieldHeader.isOverflow(fieldStatus))
                {
          // In version 1.5, the first field is overflow and the
          // second is not. In version 2.0 onwards, the first field
          // is not overflow and the second is overflow (the overflow
          // bit goes with the overflow pointer).  Check first field
          // to make sure its overflow bit is set on. 
          // Offset still points to the first column.
          lrdi.setPosition(offset);
          fieldStatus = StoredFieldHeader.readStatus(lrdi);
          SanityManager.ASSERT(
                            StoredFieldHeader.isOverflow(fieldStatus));
        }
      }
View Full Code Here

  {
        ErrorObjectInput    inUserCode = null;

        // Reads in this routine are always against the raw data in the
        // pageData array, thus it can assume array access to page data array.
        ArrayInputStream lrdi = rawDataIn;

    try
    {
            if (SanityManager.DEBUG)
            {
                if (colid >= row.length)
                    SanityManager.THROWASSERT(
                        "colid = " + colid +
                        ";row length = " + row.length);

                // currently this routine will not work on long rows.
                if (recordHeader.getFirstField() != 0)
                {
                    SanityManager.THROWASSERT(
                        "recordHeader.getFirstField() = " +
                        recordHeader.getFirstField());
                }
            }

            Object column     = row[colid];

            // if the column id exists on this page.
            if (colid <= (recordHeader.getNumberFields() - 1))
            {
                // skip the fields before colid, the column in question
                // existent on this page.

                for (int columnId = colid; columnId > 0; columnId--)
                {
                    offset_to_field_data +=
                        StoredFieldHeader.readTotalFieldLength(
                            pageData, offset_to_field_data);
                }



        // read the field header

                // read the status byte.
        int fieldStatus     =
                    StoredFieldHeader.readStatus(
                        pageData, offset_to_field_data);

                // read the field data length, and position on 1st byte of data.
        int fieldDataLength =
                    StoredFieldHeader.readFieldLengthAndSetStreamPosition(
                        pageData,
                        offset_to_field_data +
                            StoredFieldHeader.STORED_FIELD_HEADER_STATUS_SIZE,
                        fieldStatus,
                        slotFieldSize,
                        lrdi);

        if (SanityManager.DEBUG)
                {
          SanityManager.ASSERT(
                        !StoredFieldHeader.isExtensible(fieldStatus),
                        "extensible fields not supported yet");
        }

        // SRW-DJD code assumes non-extensible case ...

                if (!StoredFieldHeader.isNonexistent(fieldStatus))
                {
                    boolean isOverflow =
                        StoredFieldHeader.isOverflow(fieldStatus);

                    OverflowInputStream overflowIn = null;

                    if (isOverflow)
                    {
                        // A fetched long column is returned as a stream
                        long overflowPage   =
                            CompressedNumber.readLong((InputStream) lrdi);

                        int overflowId      =
                            CompressedNumber.readInt((InputStream) lrdi);

                        // Prepare the stream for results...
                        // create the byteHolder the size of a page, so, that it
                        // will fit the field Data that would fit on a page.
                        MemByteHolder byteHolder =
                            new MemByteHolder(pageData.length);

                        overflowIn = new OverflowInputStream(
                            byteHolder, owner, overflowPage,
                            overflowId, recordToLock);
                    }

                    // Deal with Storable columns
                    if (column instanceof DataValueDescriptor)
                    {
                        DataValueDescriptor sColumn =
                            (DataValueDescriptor) column;

                        // is the column null ?
                        if (StoredFieldHeader.isNull(fieldStatus))
                        {
                            sColumn.restoreToNull();
                        }
                        else
                        {
                            // set the limit for the user read
                            if (!isOverflow)
                            {
                                // normal, non-overflow column case.

                                lrdi.setLimit(fieldDataLength);
                                inUserCode = lrdi;
                                sColumn.readExternalFromArray(lrdi);
                                inUserCode = null;
                                int unread = lrdi.clearLimit();
                                if (unread != 0)
                                    DataInputUtil.skipFully(lrdi, unread);
                            }
                            else
                            {
                                // fetched column is a Storable long column.

                                FormatIdInputStream newIn =
                                    new FormatIdInputStream(overflowIn);

                                if ((sColumn instanceof StreamStorable))
                                {
                                    ((StreamStorable)sColumn).setStream(newIn);
                                }
                                else
                                {
                                    inUserCode = newIn;
                                    sColumn.readExternal(newIn);
                                    inUserCode = null;
                                }
                            }
                        }
                    }
                    else
                    {
                        // At this point only non-Storable columns.

                        if (StoredFieldHeader.isNull(fieldStatus))
                        {
                            // Only Storables can be null ...

                            throw StandardException.newException(
                                    SQLState.DATA_NULL_STORABLE_COLUMN,
                                    Integer.toString(colid));
                        }

                        // This is a non-extensible field, which means the
                        // caller must know the correct type and thus the
                        // element in row is the correct type or null. It must
                        // be Serializable.
                        //
                        // We do not support Externalizable here.

                        lrdi.setLimit(fieldDataLength);
                        inUserCode = lrdi;
                        // RESOLVE (no non-storables?)
                        row[colid] = (Object) lrdi.readObject();
                        inUserCode = null;
                        int unread = lrdi.clearLimit();
                        if (unread != 0)
                            DataInputUtil.skipFully(lrdi, unread);
                    }

                }
                else
                {
                    // column does not exist in the row, return null.

                    // field is non-existent

                    if (column instanceof DataValueDescriptor)
                    {
                        // RESOLVE - This is in place for 1.2. In the future
                        // we may want to return this column as non-existent
                        // even if it is a storable column, or maybe use a
                        // supplied default.

                        ((DataValueDescriptor) column).restoreToNull();
                    }
                    else
                    {
                        row[colid] = null;
                    }
                }
            }
            else
            {
                // field does not exist on this page.

                if (column instanceof DataValueDescriptor)
                {
                    // RESOLVE - This is in place for 1.2. In the future
                    // we may want to return this column as non-existent
                    // even if it is a storable column, or maybe use a
                    // supplied default.
                    ((DataValueDescriptor) column).restoreToNull();
                }
                else
                {
                    row[colid] = null;
                }
            }
    }
        catch (IOException ioe)
        {
      // an exception during the restore of a user column, this doesn't
      // make the database corrupt, just that this field is inaccessable

      if (inUserCode != null)
            {
        lrdi.clearLimit();

        if (ioe instanceof EOFException)
                {
                    if (SanityManager.DEBUG)
                    {
                        SanityManager.DEBUG_PRINT("DEBUG_TRACE",
                            "StoredPage.readOneColumnFromPage - EOF while restoring record: " +
                                recordHeader +
                            "Page dump = " + this);
                        SanityManager.showTrace(ioe);
                    }

          // going beyond the limit in a DataInput class results in
                    // an EOFException when it sees the -1 from a read
          throw StandardException.newException(
                            SQLState.DATA_STORABLE_READ_MISMATCH,
                            ioe, inUserCode.getErrorInfo());
        }

                // some SQLData error reporting
                Exception ne = inUserCode.getNestedException();
                if (ne != null)
                {
                    if (ne instanceof InstantiationException)
                    {
                        throw StandardException.newException(
                            SQLState.DATA_SQLDATA_READ_INSTANTIATION_EXCEPTION,
                            ne, inUserCode.getErrorInfo());
                    }

                    if (ne instanceof IllegalAccessException)
                    {
                        throw StandardException.newException(
                            SQLState.DATA_SQLDATA_READ_ILLEGAL_ACCESS_EXCEPTION,
                            ne, inUserCode.getErrorInfo());
                    }

                    if (ne instanceof StandardException)
                    {
                        throw (StandardException) ne;
                    }
                }

        throw StandardException.newException(
                        SQLState.DATA_STORABLE_READ_EXCEPTION,
                        ioe, inUserCode.getErrorInfo());
      }

      // re-throw to higher levels so they can put it in correct context.
      throw ioe;

    }
        catch (ClassNotFoundException cnfe)
        {
      lrdi.clearLimit();

      // an exception during the restore of a user column, this doesn't
      // make the database corrupt, just that this field is inaccessable
      throw StandardException.newException(
                    SQLState.DATA_STORABLE_READ_MISSING_CLASS,
                    cnfe, inUserCode.getErrorInfo());

    }
        catch (LinkageError le)
        {
      // Some error during the link of a user class
      if (inUserCode != null)
            {
        lrdi.clearLimit();

                throw StandardException.newException(
                        SQLState.DATA_STORABLE_READ_EXCEPTION,
                        le, inUserCode.getErrorInfo());
      }
View Full Code Here

    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);
    }
  }
View Full Code Here

    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);
View Full Code Here

          "fieldNumber: " + fieldNumber +
          " start field: " + startField +
          " number of fields " + numberFields);
    }

    ArrayInputStream lrdi = rawDataIn;

    // skip the record header
    lrdi.setPosition(offset + recordHeader.size());

    // skip any earlier fields ...
    for (int i = startField; i < fieldNumber; i++) {
      skipField(lrdi);
    }
View Full Code Here

    @exception IOException error in reading the header from file
  */
  private void readHeaderFromArray(byte[] a)
     throws StandardException, IOException
  {
    ArrayInputStream inStream = new ArrayInputStream(a);

    inStream.setLimit(CONTAINER_INFO_SIZE);
    int fid = inStream.readInt();
    if (fid != formatIdInteger)
        {
      throw StandardException.newException(
                SQLState.DATA_UNKNOWN_CONTAINER_FORMAT, getIdentity(),
                new Long(fid));
        }

    int status = inStream.readInt();
    pageSize = inStream.readInt();
    spareSpace = inStream.readInt();
    minimumRecordSize = inStream.readInt();
    initialPages = inStream.readShort();
    PreAllocSize = inStream.readShort();
    firstAllocPageNumber = inStream.readLong();
    firstAllocPageOffset = inStream.readLong();
    containerVersion = inStream.readLong();
    estimatedRowCount = inStream.readLong();
    reusableRecordIdSequenceNumber = inStream.readLong();
    lastLogInstant = null;

    if (PreAllocSize == 0// pre 2.0, we don't store this.
      PreAllocSize = DEFAULT_PRE_ALLOC_SIZE;

    long spare3 = inStream.readLong()// read spare long

    // upgrade - if this is a container that was created before
    // initialPages was stored, it will have a zero value.  Set it to the
    // default of 1.
    if (initialPages == 0
      initialPages = 1;

    // container read in from disk, reset preAllocation values
    PreAllocThreshold = PRE_ALLOC_THRESHOLD;

    // validate checksum
    long onDiskChecksum = inStream.readLong();
    checksum.reset();
    checksum.update(a, 0, CONTAINER_INFO_SIZE - CHECKSUM_SIZE);

    if (onDiskChecksum != checksum.getValue())
    {
View Full Code Here

  {
    super.initialize();

    if (rawDataIn == null)
        {
      rawDataIn            = new ArrayInputStream();
      checksum             = new CRC32();
    }

    if (pageData != null)
      rawDataIn.setData(pageData);
View Full Code Here

                    "restoreRecordFromSlot called on an overflow page.");
      }

            // position the array reading stream at beginning of row data just
            // past the record header.
      ArrayInputStream lrdi = rawDataIn;
      lrdi.setPosition(offset_to_row_data);

      if (!recordHeader.hasOverflow())
            {
                if (isHeadRow)
                {
                    if (fetchDesc != null &&
                        fetchDesc.getQualifierList() != null)
                    {
                        fetchDesc.reset();

                        if (!qualifyRecordFromSlot(
                                row,
                                offset_to_row_data,
                                fetchDesc,
                                recordHeader,
                                recordToLock))
                        {
                            return(false);
                        }
                        else
                        {
                            // reset position back for subsequent record read.
                            lrdi.setPosition(offset_to_row_data);
                        }
                    }
                }

                // call routine to do the real work.  Note that
View Full Code Here

    byte[] array = byteArray.getArray();
   
    // now extract the relavent information from array - basically
    // duplicate the code in readHeaderFromArray
    ArrayInputStream inStream = new ArrayInputStream(array);

    int status = 0;

    try
    {     
      inStream.setLimit(CONTAINER_INFO_SIZE);

      int fid = inStream.readInt();
      if (fid != formatIdInteger)
      {
        // RESOLVE: do something about this when we have > 1 container format
        throw StandardException.newException(
                    SQLState.DATA_UNKNOWN_CONTAINER_FORMAT,
                    getIdentity(), new Long(fid));
      }

      status = inStream.readInt();
      pageSize = inStream.readInt();
      spareSpace = inStream.readInt();
      minimumRecordSize = inStream.readInt();
      initialPages = inStream.readShort();

    }
    catch (IOException ioe)
    {
      throw StandardException.newException(
View Full Code Here

TOP

Related Classes of org.apache.derby.iapi.services.io.ArrayInputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.