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