/* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
String sTempFileURL = m_aTestHelper.CreateTempFile( m_xMSF ); if ( sTempFileURL == null || sTempFileURL == "" )
{
m_aTestHelper.Error( "No valid temporary file was created!" ); returnfalse;
}
// create temporary storage based on a previously created temporary file
Object pArgs[] = new Object[2];
pArgs[0] = (Object) sTempFileURL;
pArgs[1] = Integer.valueOf( ElementModes.WRITE );
// open a new substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes // and commit if ( !m_aTestHelper.WriteBytesToEncrStreamH( xTempFileStorage, aSubStream1Path, "MediaType1", true, pBytes1, sPass1, true ) ) returnfalse;
// open a new substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes // and commit if ( !m_aTestHelper.WriteBytesToEncrStreamH( xTempFileStorage, aSubStream2Path, "MediaType2", false, pBytes2, sPass2, true ) ) returnfalse;
// open a new substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes // and don't commit if ( !m_aTestHelper.WriteBytesToEncrStreamH( xTempFileStorage, aSubStream3Path, "MediaType2", false, pBytes2, sPass2, false ) ) returnfalse;
// set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempFileStorage, "MediaType3", true,
ElementModes.WRITE ) ) returnfalse;
// commit the root storage so the contents must be stored now if ( !m_aTestHelper.commitStorage( xTempFileStorage ) ) returnfalse;
// dispose used storages to free resources if ( !m_aTestHelper.disposeStorage( xTempFileStorage ) ) returnfalse;
// now reopen the storage, // check all the written and copied information // and change it
// the temporary file must not be locked any more after storage disposing
oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
xTempFileStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oTempFileStorage ); if ( xTempFileStorage == null )
{
m_aTestHelper.Error( "Can't create storage based on temporary file!" ); returnfalse;
}
if ( !m_aTestHelper.checkStorageProperties( xTempFileStorage, "MediaType3", true, ElementModes.WRITE ) ) returnfalse;
if ( !m_aTestHelper.cantOpenEncrStreamH( xTempFileStorage, aSubStream3Path, ElementModes.READ, sPass2 ) ) returnfalse;
// open existing substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes // and commit if ( !m_aTestHelper.WriteBytesToEncrStreamH( xTempFileStorage, aSubStream1Path, "MediaType3", true, pBytes2, sPass1, true ) ) returnfalse;
// open existing substream hierarchically, set "MediaType" and "Compressed" properties to it, write some bytes // and don't commit if ( !m_aTestHelper.WriteBytesToEncrStreamH( xTempFileStorage, aSubStream2Path, "MediaType3", true, pBytes1, sPass2, false ) ) returnfalse;
// commit the root storage so the contents must be stored now if ( !m_aTestHelper.commitStorage( xTempFileStorage ) ) returnfalse;
// dispose used storages to free resources if ( !m_aTestHelper.disposeStorage( xTempFileStorage ) ) returnfalse;
// now reopen the storage, // check all the written information
// the temporary file must not be locked any more after storage disposing
pArgs[1] = Integer.valueOf( ElementModes.READ );
Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pArgs );
XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage ); if ( xResultStorage == null )
{
m_aTestHelper.Error( "Can't reopen storage based on temporary file!" ); returnfalse;
}
if ( !m_aTestHelper.checkStorageProperties( xResultStorage, "MediaType3", true, ElementModes.READ ) ) returnfalse;
// the following stream was not committed last time, so the last change must be lost if ( !m_aTestHelper.checkEncrStreamH( xResultStorage, aSubStream2Path, "MediaType2", pBytes2, sPass2 ) ) returnfalse;
// dispose used storages to free resources if ( !m_aTestHelper.disposeStorage( xResultStorage ) ) returnfalse;
returntrue;
} catch( Exception e )
{
m_aTestHelper.Error( "Exception: " + e ); returnfalse;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.