update dev300-m58
[ooovba.git] / configmgr / source / localbe / localoutputstream.hxx
blob911e339fbd15266a0cc8b9f14e157f19467e334f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: localoutputstream.hxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef CONFIGMGR_LOCALBE_LOCALOUTPUTSTREAM_HXX_
32 #define CONFIGMGR_LOCALBE_LOCALOUTPUTSTREAM_HXX_
34 #include "oslstream.hxx"
35 #include "filehelper.hxx"
36 #include <com/sun/star/configuration/backend/BackendAccessException.hpp>
38 namespace configmgr { namespace localbe {
40 namespace css = com::sun::star ;
41 namespace uno = css::uno ;
42 namespace io = css::io ;
43 namespace backend = css::configuration::backend ;
45 /**
46 Class wrapping the use of the XOutputStream implementation on a file
47 to make it handle a temporary file and synch the contents to the
48 actual file being accessed only on successful completion of the output
49 process.
51 class LocalOutputStream : public cppu::WeakImplHelper1<io::XOutputStream>
53 public :
54 /**
55 Constructor using the URL of the file to access.
56 The actual writing will occur in a temporary file
57 whose name is derived from the URL, and the file
58 specified by the parameter will be overwritten
59 on closing the stream.
61 @param aFileUrl URL of the file to write
62 @throws com::sun::star::io::IOException
63 if access to the temporary file fails.
65 LocalOutputStream(const rtl::OUString& aFileUrl)
66 throw (backend::BackendAccessException, uno::RuntimeException) ;
67 /** Destructor */
68 ~LocalOutputStream(void) ;
70 // closeOutput and mark as successful
71 void finishOutput()
72 throw (backend::BackendAccessException, uno::RuntimeException) ;
73 protected :
74 // XOutputStream
75 virtual void SAL_CALL writeBytes(const uno::Sequence<sal_Int8>& aData)
76 throw (io::NotConnectedException,
77 io::BufferSizeExceededException,
78 io::IOException, uno::RuntimeException);
80 virtual void SAL_CALL flush(void)
81 throw (io::NotConnectedException,
82 io::BufferSizeExceededException,
83 io::IOException, uno::RuntimeException);
85 virtual void SAL_CALL closeOutput(void)
86 throw (io::NotConnectedException,
87 io::BufferSizeExceededException,
88 io::IOException, uno::RuntimeException) ;
91 private :
92 uno::Reference<io::XOutputStream> getOutputFile() ;
94 /** Temporary file used during access */
95 uno::Reference<io::XOutputStream> mTemporaryFile ;
96 /** URL of the target file */
97 rtl::OUString mFileUrl ;
98 /** URL of the temporary file */
99 rtl::OUString mTemporaryFileUrl ;
100 /** File being written */
101 osl::File *mWriteFile ;
104 } } // configmgr.localbe
106 #endif // CONFIGMGR_LOCALBE_LOCALOUTPUTSTREAM_HXX_