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