1*9877b273SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9877b273SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9877b273SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9877b273SAndrew Rist  * distributed with this work for additional information
6*9877b273SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9877b273SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9877b273SAndrew Rist  * "License"); you may not use this file except in compliance
9*9877b273SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9877b273SAndrew Rist  *
11*9877b273SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9877b273SAndrew Rist  *
13*9877b273SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9877b273SAndrew Rist  * software distributed under the License is distributed on an
15*9877b273SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9877b273SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9877b273SAndrew Rist  * specific language governing permissions and limitations
18*9877b273SAndrew Rist  * under the License.
19*9877b273SAndrew Rist  *
20*9877b273SAndrew Rist  *************************************************************/
21*9877b273SAndrew Rist 
22*9877b273SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _COMPHELPER_STREAMSECTION_HXX_
25cdf0e10cSrcweir #define _COMPHELPER_STREAMSECTION_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <com/sun/star/io/XMarkableStream.hpp>
28cdf0e10cSrcweir #include <com/sun/star/io/XDataInputStream.hpp>
29cdf0e10cSrcweir #include <com/sun/star/io/XDataOutputStream.hpp>
30cdf0e10cSrcweir #include "comphelper/comphelperdllapi.h"
31cdf0e10cSrcweir 
32cdf0e10cSrcweir namespace comphelper
33cdf0e10cSrcweir {
34cdf0e10cSrcweir 
35cdf0e10cSrcweir 	namespace stario	= ::com::sun::star::io;
36cdf0e10cSrcweir 	namespace staruno	= ::com::sun::star::uno;
37cdf0e10cSrcweir 
38cdf0e10cSrcweir /** implements handling for compatibly reading/writing data from/into an input/output stream.
39cdf0e10cSrcweir 	data written in a block secured by this class should be readable by older versions which
40cdf0e10cSrcweir 	use the same mechanism.
41cdf0e10cSrcweir 
42cdf0e10cSrcweir 	@author	Frank Schoenheit
43cdf0e10cSrcweir 	@since	00/26/05
44cdf0e10cSrcweir */
45cdf0e10cSrcweir 
46cdf0e10cSrcweir class COMPHELPER_DLLPUBLIC OStreamSection
47cdf0e10cSrcweir {
48cdf0e10cSrcweir 	staruno::Reference< stario::XMarkableStream >		m_xMarkStream;
49cdf0e10cSrcweir 	staruno::Reference< stario::XDataInputStream >		m_xInStream;
50cdf0e10cSrcweir 	staruno::Reference< stario::XDataOutputStream >		m_xOutStream;
51cdf0e10cSrcweir 
52cdf0e10cSrcweir 	sal_Int32	m_nBlockStart;
53cdf0e10cSrcweir 	sal_Int32	m_nBlockLen;
54cdf0e10cSrcweir 
55cdf0e10cSrcweir public:
56cdf0e10cSrcweir 	/**	starts reading of a "skippable" section of data within the given input stream<BR>
57cdf0e10cSrcweir 		@param		_rxInput	the stream to read from. Must support the
58cdf0e10cSrcweir 								<type scope="com::sun::star::io">XMarkableStream</type> interface
59cdf0e10cSrcweir 	*/
60cdf0e10cSrcweir 	OStreamSection(const staruno::Reference< stario::XDataInputStream >& _rxInput);
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 	/**	starts writing of a "skippable" section of data into the given output stream
63cdf0e10cSrcweir 		@param		_rxOutput			the stream the stream to write to. Must support the
64cdf0e10cSrcweir 										<type scope="com::sun::star::io">XMarkableStream</type> interface
65cdf0e10cSrcweir 		@param		_nPresumedLength	estimation for the length of the upcoming section. If greater 0, this
66cdf0e10cSrcweir 										value will be written as section length and corrected (in the dtor) only if
67cdf0e10cSrcweir 										needed. If you know how much bytes you are about to write, you may
68cdf0e10cSrcweir 										want to use this param, saving some stream operations this way.
69cdf0e10cSrcweir 	*/
70cdf0e10cSrcweir 	OStreamSection(const staruno::Reference< stario::XDataOutputStream >& _rxOutput, sal_Int32 _nPresumedLength = 0);
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 	/** dtor. <BR>If constructed for writing, the section "opened" by this object will be "closed".<BR>
73cdf0e10cSrcweir 		If constructed for reading, any remaining bytes 'til the end of the section will be skipped.
74cdf0e10cSrcweir 	*/
75cdf0e10cSrcweir 	~OStreamSection();
76cdf0e10cSrcweir 	/**
77cdf0e10cSrcweir 		return the number of bytes which are still available
78cdf0e10cSrcweir 	*/
79cdf0e10cSrcweir 	sal_Int32 available();
80cdf0e10cSrcweir };
81cdf0e10cSrcweir 
82cdf0e10cSrcweir }	// namespace comphelper
83cdf0e10cSrcweir 
84cdf0e10cSrcweir #endif // _COMPHELPER_STREAMSECTION_HXX_
85