summaryrefslogtreecommitdiff
path: root/sot/source/sdstor
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2024-04-01 20:52:59 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2024-04-02 07:53:43 +0200
commit25b642fdd87da4d5ed556600d0eb69d72865f666 (patch)
treedbf08943be588a9e9e09f7aaa2f03d057649c14c /sot/source/sdstor
parent2ad14abcf790002ac6fe09afbc5a2cae46f62085 (diff)
simplify SotTempStream and lifetime
It is really just an SvStream instance, and the lifetime does not need reference counting Change-Id: Idb5ffd96f852aae0dc1a94cddc0a83fbcdf974ff Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165655 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sot/source/sdstor')
-rw-r--r--sot/source/sdstor/storage.cxx50
1 files changed, 3 insertions, 47 deletions
diff --git a/sot/source/sdstor/storage.cxx b/sot/source/sdstor/storage.cxx
index 766c339f497d..937681ee56ef 100644
--- a/sot/source/sdstor/storage.cxx
+++ b/sot/source/sdstor/storage.cxx
@@ -42,60 +42,16 @@
using namespace ::com::sun::star;
-static SvLockBytesRef MakeLockBytes_Impl( const OUString & rName, StreamMode nMode )
+std::unique_ptr<SvStream> SotTempStream::Create( const OUString & rName, StreamMode nMode )
{
- SvLockBytesRef xLB;
if( !rName.isEmpty() )
{
- SvStream * pFileStm = new SvFileStream( rName, nMode );
- xLB = new SvLockBytes( pFileStm, true );
+ return std::make_unique<SvFileStream>( rName, nMode );
}
else
{
- SvStream * pCacheStm = new SvMemoryStream();
- xLB = new SvLockBytes( pCacheStm, true );
+ return std::make_unique<SvMemoryStream>();
}
- return xLB;
-}
-
-SotTempStream::SotTempStream( const OUString & rName, StreamMode nMode )
- : SvStream( MakeLockBytes_Impl( rName, nMode ).get() )
-{
- if( nMode & StreamMode::WRITE )
- m_isWritable = true;
- else
- m_isWritable = false;
-}
-
-SotTempStream::~SotTempStream()
-{
- FlushBuffer();
-}
-
-void SotTempStream::CopyTo( SotTempStream * pDestStm )
-{
- FlushBuffer(); // write all data
-
- sal_uInt64 nPos = Tell(); // save position
- Seek( 0 );
- pDestStm->SetSize( 0 ); // empty target stream
-
- constexpr int BUFSIZE = 64 * 1024;
- std::unique_ptr<sal_uInt8[]> pMem(new sal_uInt8[ BUFSIZE ]);
- sal_Int32 nRead;
- while (0 != (nRead = ReadBytes(pMem.get(), BUFSIZE)))
- {
- if (nRead != static_cast<sal_Int32>(pDestStm->WriteBytes(pMem.get(), nRead)))
- {
- SetError( SVSTREAM_GENERALERROR );
- break;
- }
- }
- pMem.reset();
-
- // set position
- pDestStm->Seek( nPos );
- Seek( nPos );
}
SotStorageStream::SotStorageStream( BaseStorageStream * pStm )