1*7b6bd0c4SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*7b6bd0c4SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*7b6bd0c4SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*7b6bd0c4SAndrew Rist * distributed with this work for additional information 6*7b6bd0c4SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*7b6bd0c4SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*7b6bd0c4SAndrew Rist * "License"); you may not use this file except in compliance 9*7b6bd0c4SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*7b6bd0c4SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*7b6bd0c4SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*7b6bd0c4SAndrew Rist * software distributed under the License is distributed on an 15*7b6bd0c4SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*7b6bd0c4SAndrew Rist * KIND, either express or implied. See the License for the 17*7b6bd0c4SAndrew Rist * specific language governing permissions and limitations 18*7b6bd0c4SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*7b6bd0c4SAndrew Rist *************************************************************/ 21*7b6bd0c4SAndrew Rist 22*7b6bd0c4SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include <cppuhelper/weak.hxx> 25cdf0e10cSrcweir #include <osl/mutex.hxx> 26cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp> 27cdf0e10cSrcweir #include <com/sun/star/io/XSeekable.hpp> 28cdf0e10cSrcweir 29cdf0e10cSrcweir 30cdf0e10cSrcweir namespace chelp { 31cdf0e10cSrcweir 32cdf0e10cSrcweir class BufferedInputStream 33cdf0e10cSrcweir : public cppu::OWeakObject, 34cdf0e10cSrcweir public com::sun::star::io::XInputStream, 35cdf0e10cSrcweir public com::sun::star::io::XSeekable 36cdf0e10cSrcweir { 37cdf0e10cSrcweir private: 38cdf0e10cSrcweir 39cdf0e10cSrcweir sal_Int32 m_nBufferLocation; 40cdf0e10cSrcweir sal_Int32 m_nBufferSize; 41cdf0e10cSrcweir sal_Int8 *m_pBuffer; 42cdf0e10cSrcweir osl::Mutex m_aMutex; 43cdf0e10cSrcweir 44cdf0e10cSrcweir public: 45cdf0e10cSrcweir 46cdf0e10cSrcweir BufferedInputStream( 47cdf0e10cSrcweir const com::sun::star::uno::Reference<com::sun::star::io::XInputStream>& xInputStream); 48cdf0e10cSrcweir 49cdf0e10cSrcweir ~BufferedInputStream(); 50cdf0e10cSrcweir 51cdf0e10cSrcweir virtual com::sun::star::uno::Any SAL_CALL 52cdf0e10cSrcweir queryInterface( const com::sun::star::uno::Type& rType ) 53cdf0e10cSrcweir throw( com::sun::star::uno::RuntimeException ); 54cdf0e10cSrcweir 55cdf0e10cSrcweir virtual void SAL_CALL acquire( void ) throw(); 56cdf0e10cSrcweir 57cdf0e10cSrcweir virtual void SAL_CALL release( void ) throw(); 58cdf0e10cSrcweir 59cdf0e10cSrcweir 60cdf0e10cSrcweir virtual sal_Int32 SAL_CALL readBytes( com::sun::star::uno::Sequence< sal_Int8 >& aData, 61cdf0e10cSrcweir sal_Int32 nBytesToRead ) 62cdf0e10cSrcweir throw( com::sun::star::io::NotConnectedException, 63cdf0e10cSrcweir com::sun::star::io::BufferSizeExceededException, 64cdf0e10cSrcweir com::sun::star::io::IOException, 65cdf0e10cSrcweir com::sun::star::uno::RuntimeException ); 66cdf0e10cSrcweir 67cdf0e10cSrcweir virtual sal_Int32 SAL_CALL readSomeBytes( com::sun::star::uno::Sequence< sal_Int8 >& aData, 68cdf0e10cSrcweir sal_Int32 nMaxBytesToRead ) 69cdf0e10cSrcweir throw( com::sun::star::io::NotConnectedException, 70cdf0e10cSrcweir com::sun::star::io::BufferSizeExceededException, 71cdf0e10cSrcweir com::sun::star::io::IOException, 72cdf0e10cSrcweir com::sun::star::uno::RuntimeException ); 73cdf0e10cSrcweir 74cdf0e10cSrcweir virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) 75cdf0e10cSrcweir throw( com::sun::star::io::NotConnectedException, 76cdf0e10cSrcweir com::sun::star::io::BufferSizeExceededException, 77cdf0e10cSrcweir com::sun::star::io::IOException, 78cdf0e10cSrcweir com::sun::star::uno::RuntimeException ); 79cdf0e10cSrcweir 80cdf0e10cSrcweir virtual sal_Int32 SAL_CALL available( void ) 81cdf0e10cSrcweir throw( com::sun::star::io::NotConnectedException, 82cdf0e10cSrcweir com::sun::star::io::IOException, 83cdf0e10cSrcweir com::sun::star::uno::RuntimeException ); 84cdf0e10cSrcweir 85cdf0e10cSrcweir virtual void SAL_CALL closeInput( void ) 86cdf0e10cSrcweir throw( com::sun::star::io::NotConnectedException, 87cdf0e10cSrcweir com::sun::star::io::IOException, 88cdf0e10cSrcweir com::sun::star::uno::RuntimeException ); 89cdf0e10cSrcweir 90cdf0e10cSrcweir virtual void SAL_CALL seek( sal_Int64 location ) 91cdf0e10cSrcweir throw( com::sun::star::lang::IllegalArgumentException, 92cdf0e10cSrcweir com::sun::star::io::IOException, 93cdf0e10cSrcweir com::sun::star::uno::RuntimeException ); 94cdf0e10cSrcweir 95cdf0e10cSrcweir virtual sal_Int64 SAL_CALL getPosition( void ) 96cdf0e10cSrcweir throw( com::sun::star::io::IOException, 97cdf0e10cSrcweir com::sun::star::uno::RuntimeException ); 98cdf0e10cSrcweir 99cdf0e10cSrcweir virtual sal_Int64 SAL_CALL getLength( void ) 100cdf0e10cSrcweir throw( com::sun::star::io::IOException, 101cdf0e10cSrcweir com::sun::star::uno::RuntimeException ); 102cdf0e10cSrcweir }; 103cdf0e10cSrcweir 104cdf0e10cSrcweir 105cdf0e10cSrcweir extern com::sun::star::uno::Reference<com::sun::star::io::XInputStream> 106cdf0e10cSrcweir turnToSeekable( 107cdf0e10cSrcweir const com::sun::star::uno::Reference<com::sun::star::io::XInputStream>& xInputStream); 108cdf0e10cSrcweir 109cdf0e10cSrcweir } 110