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 
24 #include <cppuhelper/weak.hxx>
25 #include <osl/mutex.hxx>
26 #include <com/sun/star/io/XInputStream.hpp>
27 #include <com/sun/star/io/XSeekable.hpp>
28 
29 
30 namespace chelp {
31 
32 	class BufferedInputStream
33 		: public cppu::OWeakObject,
34 		  public com::sun::star::io::XInputStream,
35 		  public com::sun::star::io::XSeekable
36 	{
37 	private:
38 
39 		sal_Int32      m_nBufferLocation;
40 		sal_Int32      m_nBufferSize;
41 		sal_Int8      *m_pBuffer;
42 		osl::Mutex     m_aMutex;
43 
44 	public:
45 
46 		BufferedInputStream(
47 			const com::sun::star::uno::Reference<com::sun::star::io::XInputStream>& xInputStream);
48 
49 		~BufferedInputStream();
50 
51 		virtual com::sun::star::uno::Any SAL_CALL
52 		queryInterface( const com::sun::star::uno::Type& rType )
53 			throw( com::sun::star::uno::RuntimeException );
54 
55 		virtual void SAL_CALL acquire( void ) throw();
56 
57 		virtual void SAL_CALL release( void ) throw();
58 
59 
60 		virtual sal_Int32 SAL_CALL readBytes( com::sun::star::uno::Sequence< sal_Int8 >& aData,
61 											  sal_Int32 nBytesToRead )
62 			throw( com::sun::star::io::NotConnectedException,
63 				   com::sun::star::io::BufferSizeExceededException,
64 				   com::sun::star::io::IOException,
65 				   com::sun::star::uno::RuntimeException );
66 
67 		virtual sal_Int32 SAL_CALL readSomeBytes( com::sun::star::uno::Sequence< sal_Int8 >& aData,
68 												  sal_Int32 nMaxBytesToRead )
69 			throw( com::sun::star::io::NotConnectedException,
70 				   com::sun::star::io::BufferSizeExceededException,
71 				   com::sun::star::io::IOException,
72 				   com::sun::star::uno::RuntimeException );
73 
74 		virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip )
75 			throw( com::sun::star::io::NotConnectedException,
76 				   com::sun::star::io::BufferSizeExceededException,
77 				   com::sun::star::io::IOException,
78 				   com::sun::star::uno::RuntimeException );
79 
80 		virtual sal_Int32 SAL_CALL available( void )
81 			throw( com::sun::star::io::NotConnectedException,
82 				   com::sun::star::io::IOException,
83 				   com::sun::star::uno::RuntimeException );
84 
85 		virtual void SAL_CALL closeInput( void )
86 			throw( com::sun::star::io::NotConnectedException,
87 				   com::sun::star::io::IOException,
88 				   com::sun::star::uno::RuntimeException );
89 
90 		virtual void SAL_CALL seek( sal_Int64 location )
91 			throw( com::sun::star::lang::IllegalArgumentException,
92 				   com::sun::star::io::IOException,
93 				   com::sun::star::uno::RuntimeException );
94 
95 		virtual sal_Int64 SAL_CALL getPosition( void )
96 			throw( com::sun::star::io::IOException,
97 				   com::sun::star::uno::RuntimeException );
98 
99 		virtual sal_Int64 SAL_CALL getLength( void )
100 			throw( com::sun::star::io::IOException,
101 				   com::sun::star::uno::RuntimeException );
102 	};
103 
104 
105 	extern com::sun::star::uno::Reference<com::sun::star::io::XInputStream>
106 	turnToSeekable(
107 		const com::sun::star::uno::Reference<com::sun::star::io::XInputStream>& xInputStream);
108 
109 }
110