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 #ifndef _UNOTOOLS_STREAMSECTION_HXX_
25 #define _UNOTOOLS_STREAMSECTION_HXX_
26 
27 #include <com/sun/star/io/XMarkableStream.hpp>
28 #include <com/sun/star/io/XDataInputStream.hpp>
29 #include <com/sun/star/io/XDataOutputStream.hpp>
30 
31 namespace utl
32 {
33 
34 	namespace stario	= ::com::sun::star::io;
35 	namespace staruno	= ::com::sun::star::uno;
36 
37 /** implements handling for compatibly reading/writing data from/into an input/output stream.
38 	data written in a block secured by this class should be readable by older versions which
39 	use the same mechanism.
40 
41 	@author	Frank Schoenheit
42 	@since	00/26/05
43 */
44 
45 class OStreamSection
46 {
47 	staruno::Reference< stario::XMarkableStream >		m_xMarkStream;
48 	staruno::Reference< stario::XDataInputStream >		m_xInStream;
49 	staruno::Reference< stario::XDataOutputStream >		m_xOutStream;
50 
51 	sal_Int32	m_nBlockStart;
52 	sal_Int32	m_nBlockLen;
53 
54 public:
55 	/**	starts reading of a "skippable" section of data within the given input stream<BR>
56 		@param		_rxInput	the stream to read from. Must support the
57 								<type scope="com::sun::star::io">XMarkableStream</type> interface
58 	*/
59 	OStreamSection(const staruno::Reference< stario::XDataInputStream >& _rxInput);
60 
61 	/**	starts writing of a "skippable" section of data into the given output stream
62 		@param		_rxOutput			the stream the stream to write to. Must support the
63 										<type scope="com::sun::star::io">XMarkableStream</type> interface
64 		@param		_nPresumedLength	estimation for the length of the upcoming section. If greater 0, this
65 										value will be written as section length and corrected (in the dtor) only if
66 										needed. If you know how much bytes you are about to write, you may
67 										want to use this param, saving some stream operations this way.
68 	*/
69 	OStreamSection(const staruno::Reference< stario::XDataOutputStream >& _rxOutput, sal_Int32 _nPresumedLength = 0);
70 
71 	/** dtor. <BR>If constructed for writing, the section "opened" by this object will be "closed".<BR>
72 		If constructed for reading, any remaining bytes 'til the end of the section will be skipped.
73 	*/
74 	~OStreamSection();
75 };
76 
77 }	// namespace utl
78 
79 #endif // _UNOTOOLS_STREAMSECTION_HXX_
80 
81 
82