summaryrefslogtreecommitdiff
path: root/comphelper
diff options
context:
space:
mode:
Diffstat (limited to 'comphelper')
-rw-r--r--comphelper/source/streaming/memorystream.cxx25
-rw-r--r--comphelper/source/streaming/seekableinput.cxx17
2 files changed, 41 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 );
diff --git a/comphelper/source/streaming/seekableinput.cxx b/comphelper/source/streaming/seekableinput.cxx
index 6fd418df36ca..dceb16824c58 100644
--- a/comphelper/source/streaming/seekableinput.cxx
+++ b/comphelper/source/streaming/seekableinput.cxx
@@ -107,7 +107,11 @@ void OSeekableInputWrapper::PrepareCopy_Impl()
xTempSeek->seek( 0 );
m_xCopyInput.set( xTempOut, uno::UNO_QUERY );
if ( m_xCopyInput.is() )
+ {
m_xCopySeek = xTempSeek;
+ m_pCopyByteReader = dynamic_cast<comphelper::ByteReader*>(xTempOut.get());
+ assert(m_pCopyByteReader);
+ }
}
}
@@ -142,6 +146,18 @@ sal_Int32 SAL_CALL OSeekableInputWrapper::readSomeBytes( uno::Sequence< sal_Int8
return m_xCopyInput->readSomeBytes( aData, nMaxBytesToRead );
}
+sal_Int32 OSeekableInputWrapper::readSomeBytes( sal_Int8* aData, sal_Int32 nMaxBytesToRead )
+{
+ std::scoped_lock aGuard( m_aMutex );
+
+ if ( !m_xOriginalStream.is() )
+ throw io::NotConnectedException();
+
+ PrepareCopy_Impl();
+
+ return m_pCopyByteReader->readSomeBytes( aData, nMaxBytesToRead );
+}
+
void SAL_CALL OSeekableInputWrapper::skipBytes( sal_Int32 nBytesToSkip )
{
@@ -186,6 +202,7 @@ void SAL_CALL OSeekableInputWrapper::closeInput()
}
m_xCopySeek.clear();
+ m_pCopyByteReader = nullptr;
}