Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / dbaccess / source / core / recovery / storagestream.cxx
blob0c4d1165d1fb410a5ec9490cf4f97d58413f23b9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "storagestream.hxx"
23 #include <com/sun/star/embed/ElementModes.hpp>
25 #include <tools/diagnose_ex.h>
27 //........................................................................
28 namespace dbaccess
30 //........................................................................
32 /** === begin UNO using === **/
33 using ::com::sun::star::uno::Reference;
34 using ::com::sun::star::uno::XInterface;
35 using ::com::sun::star::uno::UNO_QUERY;
36 using ::com::sun::star::uno::UNO_QUERY_THROW;
37 using ::com::sun::star::uno::UNO_SET_THROW;
38 using ::com::sun::star::uno::Exception;
39 using ::com::sun::star::uno::RuntimeException;
40 using ::com::sun::star::uno::Any;
41 using ::com::sun::star::uno::makeAny;
42 using ::com::sun::star::uno::Sequence;
43 using ::com::sun::star::uno::Type;
44 using ::com::sun::star::embed::XStorage;
45 using ::com::sun::star::io::XStream;
46 /** === end UNO using === **/
47 namespace ElementModes = ::com::sun::star::embed::ElementModes;
49 //====================================================================
50 //= StorageOutputStream
51 //====================================================================
52 //--------------------------------------------------------------------
53 StorageOutputStream::StorageOutputStream( const ::comphelper::ComponentContext& i_rContext,
54 const Reference< XStorage >& i_rParentStorage,
55 const ::rtl::OUString& i_rStreamName
57 :m_rContext( i_rContext )
59 ENSURE_OR_THROW( i_rParentStorage.is(), "illegal stream" );
61 const Reference< XStream > xStream(
62 i_rParentStorage->openStreamElement( i_rStreamName, ElementModes::READWRITE ), UNO_QUERY_THROW );
63 m_xOutputStream.set( xStream->getOutputStream(), UNO_SET_THROW );
66 //--------------------------------------------------------------------
67 StorageOutputStream::~StorageOutputStream()
71 //--------------------------------------------------------------------
72 void StorageOutputStream::close()
74 ENSURE_OR_RETURN_VOID( m_xOutputStream.is(), "already closed" );
75 m_xOutputStream->closeOutput();
76 m_xOutputStream.clear();
78 // if you add additional functionality here, be aware that there are derived classes which
79 // (legitimately) do not call this method here.
82 //====================================================================
83 //= StorageInputStream
84 //====================================================================
85 //--------------------------------------------------------------------
86 StorageInputStream::StorageInputStream( const ::comphelper::ComponentContext& i_rContext,
87 const Reference< XStorage >& i_rParentStorage,
88 const ::rtl::OUString& i_rStreamName
90 :m_rContext( i_rContext )
92 ENSURE_OR_THROW( i_rParentStorage.is(), "illegal stream" );
94 const Reference< XStream > xStream(
95 i_rParentStorage->openStreamElement( i_rStreamName, ElementModes::READ ), UNO_QUERY_THROW );
96 m_xInputStream.set( xStream->getInputStream(), UNO_SET_THROW );
99 //--------------------------------------------------------------------
100 StorageInputStream::~StorageInputStream()
104 //--------------------------------------------------------------------
105 void StorageInputStream::close()
107 ENSURE_OR_RETURN_VOID( m_xInputStream.is(), "already closed" );
108 m_xInputStream->closeInput();
109 m_xInputStream.clear();
111 // if you add additional functionality here, be aware that there are derived classes which
112 // (legitimately) do not call this method here.
115 //........................................................................
116 } // namespace dbaccess
117 //........................................................................
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */