1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: opostponedtruncationstream.hxx,v $
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 ************************************************************************/
30 #ifndef _SFX_OPOSTPONEDTRUNCATIONFILESTREAM_HXX
31 #define _SFX_OPOSTPONEDTRUNCATIONFILESTREAM_HXX
33 #include <com/sun/star/uno/Sequence.hxx>
34 #include <com/sun/star/uno/Reference.hxx>
35 #include <com/sun/star/io/XInputStream.hpp>
36 #include <com/sun/star/io/XOutputStream.hpp>
37 #include <com/sun/star/io/XSeekable.hpp>
38 #include <com/sun/star/io/XTruncate.hpp>
39 #include <com/sun/star/io/XStream.hpp>
40 #include <com/sun/star/embed/XTransactedObject.hpp>
41 #include <com/sun/star/beans/XPropertySetInfo.hpp>
42 #include <com/sun/star/beans/XPropertySet.hpp>
43 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
44 #include <com/sun/star/io/XAsyncOutputMonitor.hpp>
45 #include <osl/mutex.hxx>
46 #include <cppuhelper/implbase6.hxx>
47 #include "sfx2/dllapi.h"
49 //==================================================================
50 // OPostponedTruncationFileStream
52 // Allows to get stream access to a file, where the first truncation
53 // of the file is postponed till the first writing. If no writing happens
54 // after the first truncation/creation, it has no effect. ( The postponing of
55 // the creation can be switched off during initialization. Here the postponing
56 // of the creation means that the file will be created immediatelly, but
57 // if nothing is written into it, it will be removed during destruction
60 // On creation of this object the target file is scheduled for
61 // creation/truncation. But the action happens only during the first
62 // write access. After the first write access the object behaves
63 // itself as the original stream.
64 //==================================================================
66 struct PTFStreamData_Impl
;
67 class SFX2_DLLPUBLIC OPostponedTruncationFileStream
68 : public ::cppu::WeakImplHelper6
<
69 ::com::sun::star::io::XStream
,
70 ::com::sun::star::io::XInputStream
,
71 ::com::sun::star::io::XOutputStream
,
72 ::com::sun::star::io::XTruncate
,
73 ::com::sun::star::io::XSeekable
,
74 ::com::sun::star::io::XAsyncOutputMonitor
>
76 ::osl::Mutex m_aMutex
;
77 PTFStreamData_Impl
* m_pStreamData
;
81 void CheckScheduledTruncation_Impl();
85 OPostponedTruncationFileStream(
86 const ::rtl::OUString
& aURL
,
87 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& xFactory
,
88 const ::com::sun::star::uno::Reference
< ::com::sun::star::ucb::XSimpleFileAccess
>& xFileAccess
,
89 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XStream
>& xStream
,
92 ~OPostponedTruncationFileStream();
94 // com::sun::star::io::XStream
95 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
> SAL_CALL
getInputStream( ) throw (::com::sun::star::uno::RuntimeException
);
96 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::io::XOutputStream
> SAL_CALL
getOutputStream( ) throw (::com::sun::star::uno::RuntimeException
);
98 // com::sun::star::io::XInputStream
99 virtual ::sal_Int32 SAL_CALL
readBytes( ::com::sun::star::uno::Sequence
< ::sal_Int8
>& aData
, ::sal_Int32 nBytesToRead
) throw (::com::sun::star::io::NotConnectedException
, ::com::sun::star::io::BufferSizeExceededException
, ::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
);
100 virtual ::sal_Int32 SAL_CALL
readSomeBytes( ::com::sun::star::uno::Sequence
< ::sal_Int8
>& aData
, ::sal_Int32 nMaxBytesToRead
) throw (::com::sun::star::io::NotConnectedException
, ::com::sun::star::io::BufferSizeExceededException
, ::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
);
101 virtual void SAL_CALL
skipBytes( ::sal_Int32 nBytesToSkip
) throw (::com::sun::star::io::NotConnectedException
, ::com::sun::star::io::BufferSizeExceededException
, ::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
);
102 virtual ::sal_Int32 SAL_CALL
available( ) throw (::com::sun::star::io::NotConnectedException
, ::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
);
103 virtual void SAL_CALL
closeInput( ) throw (::com::sun::star::io::NotConnectedException
, ::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
);
105 // com::sun::star::io::XOutputStream
106 virtual void SAL_CALL
writeBytes( const ::com::sun::star::uno::Sequence
< ::sal_Int8
>& aData
) throw (::com::sun::star::io::NotConnectedException
, ::com::sun::star::io::BufferSizeExceededException
, ::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
);
107 virtual void SAL_CALL
flush( ) throw (::com::sun::star::io::NotConnectedException
, ::com::sun::star::io::BufferSizeExceededException
, ::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
);
108 virtual void SAL_CALL
closeOutput( ) throw (::com::sun::star::io::NotConnectedException
, ::com::sun::star::io::BufferSizeExceededException
, ::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
);
110 // com::sun::star::io::XTruncate
111 virtual void SAL_CALL
truncate( ) throw (::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
);
113 // com::sun::star::io::XSeekable
114 virtual void SAL_CALL
seek( ::sal_Int64 location
) throw (::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
);
115 virtual ::sal_Int64 SAL_CALL
getPosition( ) throw (::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
);
116 virtual ::sal_Int64 SAL_CALL
getLength( ) throw (::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
);
118 // ::com::sun::star::io::XAsyncOutputMonitor
119 virtual void SAL_CALL
waitForCompletion( ) throw (::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
);
123 #endif //_SFX_OPOSTPONEDTRUNCATIONFILESTREAM_HXX