xref: /AOO41X/main/dbaccess/source/core/recovery/storagestream.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3 *
4 * Copyright 2009 by Sun Microsystems, Inc.
5 *
6 * OpenOffice.org - a multi-platform office productivity suite
7 *
8 * This file is part of OpenOffice.org.
9 *
10 * OpenOffice.org is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License version 3
12 * only, as published by the Free Software Foundation.
13 *
14 * OpenOffice.org is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU Lesser General Public License version 3 for more details
18 * (a copy is included in the LICENSE file that accompanied this code).
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * version 3 along with OpenOffice.org.  If not, see
22 * <http://www.openoffice.org/license.html>
23 * for a copy of the LGPLv3 License.
24 ************************************************************************/
25 
26 #include "precompiled_dbaccess.hxx"
27 
28 #include "storagestream.hxx"
29 
30 /** === begin UNO includes === **/
31 #include <com/sun/star/embed/ElementModes.hpp>
32 /** === end UNO includes === **/
33 
34 #include <tools/diagnose_ex.h>
35 
36 //........................................................................
37 namespace dbaccess
38 {
39 //........................................................................
40 
41 	/** === begin UNO using === **/
42 	using ::com::sun::star::uno::Reference;
43 	using ::com::sun::star::uno::XInterface;
44 	using ::com::sun::star::uno::UNO_QUERY;
45 	using ::com::sun::star::uno::UNO_QUERY_THROW;
46 	using ::com::sun::star::uno::UNO_SET_THROW;
47 	using ::com::sun::star::uno::Exception;
48 	using ::com::sun::star::uno::RuntimeException;
49 	using ::com::sun::star::uno::Any;
50 	using ::com::sun::star::uno::makeAny;
51 	using ::com::sun::star::uno::Sequence;
52 	using ::com::sun::star::uno::Type;
53     using ::com::sun::star::embed::XStorage;
54     using ::com::sun::star::io::XStream;
55 	/** === end UNO using === **/
56     namespace ElementModes = ::com::sun::star::embed::ElementModes;
57 
58 	//====================================================================
59 	//= StorageOutputStream
60 	//====================================================================
61 	//--------------------------------------------------------------------
62     StorageOutputStream::StorageOutputStream(   const ::comphelper::ComponentContext& i_rContext,
63                                                 const Reference< XStorage >& i_rParentStorage,
64                                                 const ::rtl::OUString& i_rStreamName
65                                              )
66         :m_rContext( i_rContext )
67     {
68         ENSURE_OR_THROW( i_rParentStorage.is(), "illegal stream" );
69 
70         const Reference< XStream > xStream(
71             i_rParentStorage->openStreamElement( i_rStreamName, ElementModes::READWRITE ), UNO_QUERY_THROW );
72         m_xOutputStream.set( xStream->getOutputStream(), UNO_SET_THROW );
73     }
74 
75 	//--------------------------------------------------------------------
76     StorageOutputStream::~StorageOutputStream()
77     {
78     }
79 
80 	//--------------------------------------------------------------------
81     void StorageOutputStream::close()
82     {
83         ENSURE_OR_RETURN_VOID( m_xOutputStream.is(), "already closed" );
84         m_xOutputStream->closeOutput();
85         m_xOutputStream.clear();
86 
87         // if you add additional functionality here, be aware that there are derived classes which
88         // (legitimately) do not call this method here.
89     }
90 
91 	//====================================================================
92 	//= StorageInputStream
93 	//====================================================================
94 	//--------------------------------------------------------------------
95     StorageInputStream::StorageInputStream( const ::comphelper::ComponentContext& i_rContext,
96                                             const Reference< XStorage >& i_rParentStorage,
97                                             const ::rtl::OUString& i_rStreamName
98                                           )
99         :m_rContext( i_rContext )
100     {
101         ENSURE_OR_THROW( i_rParentStorage.is(), "illegal stream" );
102 
103         const Reference< XStream > xStream(
104             i_rParentStorage->openStreamElement( i_rStreamName, ElementModes::READ ), UNO_QUERY_THROW );
105         m_xInputStream.set( xStream->getInputStream(), UNO_SET_THROW );
106     }
107 
108 	//--------------------------------------------------------------------
109     StorageInputStream::~StorageInputStream()
110     {
111     }
112 
113 	//--------------------------------------------------------------------
114     void StorageInputStream::close()
115     {
116         ENSURE_OR_RETURN_VOID( m_xInputStream.is(), "already closed" );
117         m_xInputStream->closeInput();
118         m_xInputStream.clear();
119 
120         // if you add additional functionality here, be aware that there are derived classes which
121         // (legitimately) do not call this method here.
122     }
123 
124 //........................................................................
125 } // namespace dbaccess
126 //........................................................................
127