Search in sources :

Example 6 with FormatIdInputStream

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

the class StreamFileContainer method open.

/**
 ************************************************************************
 * Private/Protected methods of This class:
 **************************************************************************
 */
/**
 * Open a stream file container.
 * <p>
 * Open a container. Open the file that maps to this container, if the
 * file does not exist then we assume the container was never created
 * and return.
 * If the file exists but we have trouble opening it then we throw some
 * exception.
 * <p>
 *
 * @return The opened StreamFileContainer.
 *
 * @param forUpdate     Currently only accepts false, updating and existing
 *                      stream file container is not currently supported.
 *
 * @exception  StandardException  Standard exception policy.
 */
protected StreamFileContainer open(boolean forUpdate) throws StandardException {
    file = getFileName(this.identity, false, true);
    if (!privExists(file))
        return null;
    try {
        if (!forUpdate) {
            fileIn = privGetInputStream(file);
            if (dataFactory.databaseEncrypted()) {
                // if the database is encrypted, when reading the data back
                // from the file stream, we need to used the decrypt stream
                // to buffer up the bytes for reading.  DecryptInputStream
                // also decrypts the data.
                MemByteHolder byteHolder = new MemByteHolder(RawStoreFactory.STREAM_FILE_BUFFER_SIZE_DEFAULT);
                decryptIn = new DecryptInputStream(fileIn, byteHolder, dataFactory);
                limitIn = new LimitInputStream(decryptIn);
            } else {
                bufferedIn = new BufferedInputStream(fileIn, RawStoreFactory.STREAM_FILE_BUFFER_SIZE_DEFAULT);
                limitIn = new LimitInputStream(bufferedIn);
            }
            // the logicalDataIn input stream is on top of a limit Input
            // stream, use a limit stream to make sure we don't read off
            // more then what each column says it contains
            logicalDataIn = new FormatIdInputStream(limitIn);
            // get the record header
            recordHeader = new StoredRecordHeader();
            recordHeader.read(logicalDataIn);
        } else {
            if (SanityManager.DEBUG)
                SanityManager.THROWASSERT("updating existing stream container not supported yet");
            return null;
        }
    } catch (IOException ioe) {
        throw StandardException.newException(SQLState.FILE_CREATE, ioe, file);
    }
    return this;
}
Also used : FormatIdInputStream(org.apache.derby.iapi.services.io.FormatIdInputStream) BufferedInputStream(java.io.BufferedInputStream) LimitInputStream(org.apache.derby.iapi.services.io.LimitInputStream) IOException(java.io.IOException)

Aggregations

FormatIdInputStream (org.apache.derby.iapi.services.io.FormatIdInputStream)6 IOException (java.io.IOException)5 EOFException (java.io.EOFException)3 ArrayInputStream (org.apache.derby.iapi.services.io.ArrayInputStream)3 ErrorObjectInput (org.apache.derby.iapi.services.io.ErrorObjectInput)3 StreamStorable (org.apache.derby.iapi.services.io.StreamStorable)3 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)3 StandardException (org.apache.derby.shared.common.error.StandardException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 BufferedInputStream (java.io.BufferedInputStream)1 PushbackInputStream (java.io.PushbackInputStream)1 SQLException (java.sql.SQLException)1 LimitInputStream (org.apache.derby.iapi.services.io.LimitInputStream)1