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