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_SEEKABLEINPUT_HXX_
24 #define _COMPHELPER_STREAM_SEEKABLEINPUT_HXX_
25 
26 #include <osl/mutex.hxx>
27 #include <com/sun/star/uno/Reference.hxx>
28 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
29 #include <com/sun/star/io/XInputStream.hpp>
30 #include <com/sun/star/io/XSeekable.hpp>
31 #include <cppuhelper/implbase2.hxx>
32 #include "comphelper/comphelperdllapi.h"
33 
34 namespace comphelper
35 {
36 
37 class COMPHELPER_DLLPUBLIC OSeekableInputWrapper : public ::cppu::WeakImplHelper2< ::com::sun::star::io::XInputStream,
38 																::com::sun::star::io::XSeekable >
39 {
40 	::osl::Mutex	m_aMutex;
41 
42 	::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory;
43 
44 	::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > m_xOriginalStream;
45 
46 	::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > m_xCopyInput;
47 	::com::sun::star::uno::Reference< ::com::sun::star::io::XSeekable > m_xCopySeek;
48 
49 private:
50 	COMPHELPER_DLLPRIVATE void PrepareCopy_Impl();
51 
52 public:
53 	OSeekableInputWrapper(
54 				const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream,
55 				const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory );
56 
57 	virtual ~OSeekableInputWrapper();
58 
59 	static ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > CheckSeekableCanWrap(
60 						const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream,
61 						const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory );
62 
63 // XInputStream
64     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);
65     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);
66     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);
67     virtual sal_Int32 SAL_CALL available() throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
68     virtual void SAL_CALL closeInput() throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
69 
70 // XSeekable
71     virtual void SAL_CALL seek( sal_Int64 location ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
72     virtual sal_Int64 SAL_CALL getPosition() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
73     virtual sal_Int64 SAL_CALL getLength() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
74 
75 };
76 
77 }	// namespace comphelper
78 
79 #endif
80 
81