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 #ifndef _COMPHELPER_STREAM_OSLFILEWRAPPER_HXX_
24 #define _COMPHELPER_STREAM_OSLFILEWRAPPER_HXX_
25 
26 #include <osl/mutex.hxx>
27 #include <com/sun/star/io/XOutputStream.hpp>
28 #include <com/sun/star/io/XInputStream.hpp>
29 #include <cppuhelper/implbase1.hxx>
30 #include <osl/file.hxx>
31 #include "comphelper/comphelperdllapi.h"
32 
33 namespace comphelper
34 {
35 	namespace stario	= ::com::sun::star::io;
36 	namespace staruno	= ::com::sun::star::uno;
37 
38 //==================================================================
39 // FmUnoIOStream,
40 // stream zum schreiben un lesen von Daten, basieren  auf File
41 //==================================================================
42 struct InputStreamWrapper_Base : public ::cppu::WeakImplHelper1<stario::XInputStream>
43 {};
44 
45 class COMPHELPER_DLLPUBLIC OSLInputStreamWrapper : public InputStreamWrapper_Base
46 {
47 	::osl::Mutex	m_aMutex;
48 	::osl::File*	m_pFile;
49 	sal_Bool		m_bFileOwner : 1;
50 
51 public:
52 	OSLInputStreamWrapper(::osl::File& _rStream);
53 	OSLInputStreamWrapper(::osl::File* pStream, sal_Bool bOwner=sal_False);
54 	virtual ~OSLInputStreamWrapper();
55 
56 // stario::XInputStream
57 	virtual sal_Int32	SAL_CALL	readBytes(staruno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException);
58 	virtual sal_Int32	SAL_CALL	readSomeBytes(staruno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException);
59 	virtual void		SAL_CALL	skipBytes(sal_Int32 nBytesToSkip) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException);
60 	virtual sal_Int32	SAL_CALL	available() throw(stario::NotConnectedException, staruno::RuntimeException);
61 	virtual void		SAL_CALL	closeInput() throw(stario::NotConnectedException, staruno::RuntimeException);
62 };
63 
64 //==================================================================
65 // FmUnoOutStream,
66 // Datensenke fuer Files
67 //==================================================================
68 struct OutputStreamWrapper_Base : public ::cppu::WeakImplHelper1<stario::XOutputStream>
69 {};
70 
71 class COMPHELPER_DLLPUBLIC OSLOutputStreamWrapper : public OutputStreamWrapper_Base
72 {
73 	::osl::File&		rFile;
74 
75 public:
OSLOutputStreamWrapper(::osl::File & _rFile)76 	OSLOutputStreamWrapper(::osl::File& _rFile) :rFile(_rFile) { }
77 
78 // stario::XOutputStream
79 	virtual void SAL_CALL writeBytes(const staruno::Sequence< sal_Int8 >& aData) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException);
80 	virtual void SAL_CALL flush() throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException);
81 	virtual void SAL_CALL closeOutput() throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException);
82 };
83 
84 }	// namespace comphelper
85 
86 
87 #endif // _COMPHELPER_STREAM_OSLFILEWRAPPER_HXX_
88 
89