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 OOX_OLE_VBAINPUTSTREAM_HXX 25 #define OOX_OLE_VBAINPUTSTREAM_HXX 26 27 #include <vector> 28 #include "oox/helper/binaryinputstream.hxx" 29 30 namespace oox { 31 namespace ole { 32 33 // ============================================================================ 34 35 /** A non-seekable input stream that implements run-length decompression. */ 36 class VbaInputStream : public BinaryInputStream 37 { 38 public: 39 explicit VbaInputStream( BinaryInputStream& rInStrm ); 40 41 /** Returns -1, stream size is not determinable. */ 42 virtual sal_Int64 size() const; 43 /** Returns -1, stream position is not tracked. */ 44 virtual sal_Int64 tell() const; 45 /** Does nothing, stream is not seekable. */ 46 virtual void seek( sal_Int64 nPos ); 47 /** Closes the input stream but not the wrapped stream. */ 48 virtual void close(); 49 50 /** Reads nBytes bytes to the passed sequence. 51 @return Number of bytes really read. */ 52 virtual sal_Int32 readData( StreamDataSequence& orData, sal_Int32 nBytes, size_t nAtomSize = 1 ); 53 /** Reads nBytes bytes to the (existing) buffer opMem. 54 @return Number of bytes really read. */ 55 virtual sal_Int32 readMemory( void* opMem, sal_Int32 nBytes, size_t nAtomSize = 1 ); 56 /** Seeks the stream forward by the passed number of bytes. */ 57 virtual void skip( sal_Int32 nBytes, size_t nAtomSize = 1 ); 58 59 private: 60 /** If no data left in chunk buffer, reads the next chunk from stream. */ 61 bool updateChunk(); 62 63 private: 64 typedef ::std::vector< sal_uInt8 > ChunkBuffer; 65 66 BinaryInputStream* mpInStrm; 67 ChunkBuffer maChunk; 68 size_t mnChunkPos; 69 }; 70 71 // ============================================================================ 72 73 } // namespace ole 74 } // namespace oox 75 76 #endif 77