diff options
Diffstat (limited to 'comphelper/source/streaming/memorystream.cxx')
-rw-r--r-- | comphelper/source/streaming/memorystream.cxx | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/comphelper/source/streaming/memorystream.cxx b/comphelper/source/streaming/memorystream.cxx index b457f4b42ca8..39ae66b51d07 100644 --- a/comphelper/source/streaming/memorystream.cxx +++ b/comphelper/source/streaming/memorystream.cxx @@ -55,7 +55,7 @@ namespace { class UNOMemoryStream : public WeakImplHelper<XServiceInfo, XStream, XSeekableInputStream, XOutputStream, XTruncate>, - public comphelper::ByteWriter + public comphelper::ByteWriter, public comphelper::ByteReader { public: UNOMemoryStream(); @@ -92,6 +92,9 @@ public: // comphelper::ByteWriter virtual void writeBytes(const sal_Int8* aData, sal_Int32 nBytesToWrite) override; + // comphelper::ByteReader + virtual sal_Int32 readSomeBytes(sal_Int8* aData, sal_Int32 nBytesToRead) override; + private: std::vector< sal_Int8, boost::noinit_adaptor<std::allocator<sal_Int8>> > maData; sal_Int32 mnCursor; @@ -153,6 +156,26 @@ sal_Int32 SAL_CALL UNOMemoryStream::readBytes( Sequence< sal_Int8 >& aData, sal_ return nBytesToRead; } +// ByteReader +sal_Int32 UNOMemoryStream::readSomeBytes( sal_Int8* aData, sal_Int32 nBytesToRead ) +{ + if( nBytesToRead < 0 ) + throw IOException(u"nBytesToRead < 0"_ustr); + + nBytesToRead = std::min( nBytesToRead, available() ); + + if( nBytesToRead ) + { + sal_Int8* pData = &(*maData.begin()); + sal_Int8* pCursor = &(pData[mnCursor]); + memcpy( aData, pCursor, nBytesToRead ); + + mnCursor += nBytesToRead; + } + + return nBytesToRead; +} + sal_Int32 SAL_CALL UNOMemoryStream::readSomeBytes( Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) { return readBytes( aData, nMaxBytesToRead ); |