From c09770917fdef1019a8e11615f3e9cb68c23cb69 Mon Sep 17 00:00:00 2001 From: Ivo Hinkelmann Date: Fri, 12 Jun 2009 19:36:52 +0000 Subject: CWS-TOOLING: integrate CWS mav54_P1 2009-06-12 16:28:38 +0200 mav r272930 : #i102701# adjust memory stream implementation --- comphelper/source/streaming/memorystream.cxx | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'comphelper/source/streaming/memorystream.cxx') 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" ) ); -- cgit