diff --git a/comphelper/source/streaming/memorystream.cxx b/comphelper/source/streaming/memorystream.cxx index 3afd9b555a84..9e209a01c581 100644 --- a/comphelper/source/streaming/memorystream.cxx +++ b/comphelper/source/streaming/memorystream.cxx @@ -35,15 +35,16 @@ #include #include +#include #include -#include +#include #include #include using ::rtl::OUString; using ::cppu::OWeakObject; -using ::cppu::WeakImplHelper3; +using ::cppu::WeakImplHelper4; using namespace ::com::sun::star::io; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::lang; @@ -52,7 +53,7 @@ using namespace ::osl; namespace comphelper { -class UNOMemoryStream : public WeakImplHelper3 < XStream, XSeekableInputStream, XOutputStream > +class UNOMemoryStream : public WeakImplHelper4 < XStream, XSeekableInputStream, XOutputStream, XTruncate > { public: UNOMemoryStream(); @@ -79,6 +80,9 @@ public: virtual void SAL_CALL flush() throw (NotConnectedException, BufferSizeExceededException, IOException, RuntimeException); virtual void SAL_CALL closeOutput() throw (NotConnectedException, BufferSizeExceededException, IOException, RuntimeException); + // XTruncate + virtual void SAL_CALL truncate() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + // XServiceInfo - static versions (used for component registration) static ::rtl::OUString SAL_CALL getImplementationName_static(); static Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_static(); @@ -116,8 +120,7 @@ sal_Int32 SAL_CALL UNOMemoryStream::readBytes( Sequence< sal_Int8 >& aData, sal_ throw IOException(); nBytesToRead = std::min( nBytesToRead, available() ); - if( aData.getLength() < nBytesToRead ) - aData.realloc( nBytesToRead ); + aData.realloc( nBytesToRead ); if( nBytesToRead ) { @@ -157,9 +160,12 @@ void SAL_CALL UNOMemoryStream::closeInput() throw (NotConnectedException, IOExce // XSeekable void SAL_CALL UNOMemoryStream::seek( sal_Int64 location ) throw (IllegalArgumentException, IOException, RuntimeException) { - if( (location < 0) || (location > SAL_MAX_INT32) || (location > static_cast< sal_Int64 >( maData.size() )) ) + if( (location < 0) || (location > SAL_MAX_INT32) ) throw IllegalArgumentException( OUString(RTL_CONSTASCII_USTRINGPARAM("this implementation does not support more than 2GB!")), Reference< XInterface >(static_cast(this)), 0 ); + if ( location > static_cast< sal_Int64 >( maData.size() ) ) + maData.resize( static_cast< sal_Int32 >( location ) ); + mnCursor = static_cast< sal_Int32 >( location ); } @@ -206,6 +212,13 @@ void SAL_CALL UNOMemoryStream::closeOutput() throw (NotConnectedException, Buffe mnCursor = 0; } +//XTruncate +void SAL_CALL UNOMemoryStream::truncate() throw (IOException, RuntimeException) +{ + maData.resize( 0 ); + mnCursor = 0; +} + ::rtl::OUString SAL_CALL UNOMemoryStream::getImplementationName_static() { static const OUString sImplName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.MemoryStream" ) );