xref: /AOO41X/main/dbaccess/source/core/recovery/storagestream.cxx (revision 96de54900b79e13b861fbc62cbf36018b54e21b7)
1*96de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*96de5490SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*96de5490SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*96de5490SAndrew Rist  * distributed with this work for additional information
6*96de5490SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*96de5490SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*96de5490SAndrew Rist  * "License"); you may not use this file except in compliance
9*96de5490SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*96de5490SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*96de5490SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*96de5490SAndrew Rist  * software distributed under the License is distributed on an
15*96de5490SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*96de5490SAndrew Rist  * KIND, either express or implied.  See the License for the
17*96de5490SAndrew Rist  * specific language governing permissions and limitations
18*96de5490SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*96de5490SAndrew Rist  *************************************************************/
21*96de5490SAndrew Rist 
22*96de5490SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "storagestream.hxx"
27cdf0e10cSrcweir 
28cdf0e10cSrcweir /** === begin UNO includes === **/
29cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp>
30cdf0e10cSrcweir /** === end UNO includes === **/
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <tools/diagnose_ex.h>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir //........................................................................
35cdf0e10cSrcweir namespace dbaccess
36cdf0e10cSrcweir {
37cdf0e10cSrcweir //........................................................................
38cdf0e10cSrcweir 
39cdf0e10cSrcweir 	/** === begin UNO using === **/
40cdf0e10cSrcweir 	using ::com::sun::star::uno::Reference;
41cdf0e10cSrcweir 	using ::com::sun::star::uno::XInterface;
42cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_QUERY;
43cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_QUERY_THROW;
44cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_SET_THROW;
45cdf0e10cSrcweir 	using ::com::sun::star::uno::Exception;
46cdf0e10cSrcweir 	using ::com::sun::star::uno::RuntimeException;
47cdf0e10cSrcweir 	using ::com::sun::star::uno::Any;
48cdf0e10cSrcweir 	using ::com::sun::star::uno::makeAny;
49cdf0e10cSrcweir 	using ::com::sun::star::uno::Sequence;
50cdf0e10cSrcweir 	using ::com::sun::star::uno::Type;
51cdf0e10cSrcweir     using ::com::sun::star::embed::XStorage;
52cdf0e10cSrcweir     using ::com::sun::star::io::XStream;
53cdf0e10cSrcweir 	/** === end UNO using === **/
54cdf0e10cSrcweir     namespace ElementModes = ::com::sun::star::embed::ElementModes;
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 	//====================================================================
57cdf0e10cSrcweir 	//= StorageOutputStream
58cdf0e10cSrcweir 	//====================================================================
59cdf0e10cSrcweir 	//--------------------------------------------------------------------
StorageOutputStream(const::comphelper::ComponentContext & i_rContext,const Reference<XStorage> & i_rParentStorage,const::rtl::OUString & i_rStreamName)60cdf0e10cSrcweir     StorageOutputStream::StorageOutputStream(   const ::comphelper::ComponentContext& i_rContext,
61cdf0e10cSrcweir                                                 const Reference< XStorage >& i_rParentStorage,
62cdf0e10cSrcweir                                                 const ::rtl::OUString& i_rStreamName
63cdf0e10cSrcweir                                              )
64cdf0e10cSrcweir         :m_rContext( i_rContext )
65cdf0e10cSrcweir     {
66cdf0e10cSrcweir         ENSURE_OR_THROW( i_rParentStorage.is(), "illegal stream" );
67cdf0e10cSrcweir 
68cdf0e10cSrcweir         const Reference< XStream > xStream(
69cdf0e10cSrcweir             i_rParentStorage->openStreamElement( i_rStreamName, ElementModes::READWRITE ), UNO_QUERY_THROW );
70cdf0e10cSrcweir         m_xOutputStream.set( xStream->getOutputStream(), UNO_SET_THROW );
71cdf0e10cSrcweir     }
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 	//--------------------------------------------------------------------
~StorageOutputStream()74cdf0e10cSrcweir     StorageOutputStream::~StorageOutputStream()
75cdf0e10cSrcweir     {
76cdf0e10cSrcweir     }
77cdf0e10cSrcweir 
78cdf0e10cSrcweir 	//--------------------------------------------------------------------
close()79cdf0e10cSrcweir     void StorageOutputStream::close()
80cdf0e10cSrcweir     {
81cdf0e10cSrcweir         ENSURE_OR_RETURN_VOID( m_xOutputStream.is(), "already closed" );
82cdf0e10cSrcweir         m_xOutputStream->closeOutput();
83cdf0e10cSrcweir         m_xOutputStream.clear();
84cdf0e10cSrcweir 
85cdf0e10cSrcweir         // if you add additional functionality here, be aware that there are derived classes which
86cdf0e10cSrcweir         // (legitimately) do not call this method here.
87cdf0e10cSrcweir     }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 	//====================================================================
90cdf0e10cSrcweir 	//= StorageInputStream
91cdf0e10cSrcweir 	//====================================================================
92cdf0e10cSrcweir 	//--------------------------------------------------------------------
StorageInputStream(const::comphelper::ComponentContext & i_rContext,const Reference<XStorage> & i_rParentStorage,const::rtl::OUString & i_rStreamName)93cdf0e10cSrcweir     StorageInputStream::StorageInputStream( const ::comphelper::ComponentContext& i_rContext,
94cdf0e10cSrcweir                                             const Reference< XStorage >& i_rParentStorage,
95cdf0e10cSrcweir                                             const ::rtl::OUString& i_rStreamName
96cdf0e10cSrcweir                                           )
97cdf0e10cSrcweir         :m_rContext( i_rContext )
98cdf0e10cSrcweir     {
99cdf0e10cSrcweir         ENSURE_OR_THROW( i_rParentStorage.is(), "illegal stream" );
100cdf0e10cSrcweir 
101cdf0e10cSrcweir         const Reference< XStream > xStream(
102cdf0e10cSrcweir             i_rParentStorage->openStreamElement( i_rStreamName, ElementModes::READ ), UNO_QUERY_THROW );
103cdf0e10cSrcweir         m_xInputStream.set( xStream->getInputStream(), UNO_SET_THROW );
104cdf0e10cSrcweir     }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 	//--------------------------------------------------------------------
~StorageInputStream()107cdf0e10cSrcweir     StorageInputStream::~StorageInputStream()
108cdf0e10cSrcweir     {
109cdf0e10cSrcweir     }
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 	//--------------------------------------------------------------------
close()112cdf0e10cSrcweir     void StorageInputStream::close()
113cdf0e10cSrcweir     {
114cdf0e10cSrcweir         ENSURE_OR_RETURN_VOID( m_xInputStream.is(), "already closed" );
115cdf0e10cSrcweir         m_xInputStream->closeInput();
116cdf0e10cSrcweir         m_xInputStream.clear();
117cdf0e10cSrcweir 
118cdf0e10cSrcweir         // if you add additional functionality here, be aware that there are derived classes which
119cdf0e10cSrcweir         // (legitimately) do not call this method here.
120cdf0e10cSrcweir     }
121cdf0e10cSrcweir 
122cdf0e10cSrcweir //........................................................................
123cdf0e10cSrcweir } // namespace dbaccess
124cdf0e10cSrcweir //........................................................................
125