From 9ec8bf8f22fe74884185492ef2576ce79b41e4f1 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 11 Oct 2018 18:49:34 +0200 Subject: add SvStream::TellEnd and simplify callsites to use it instead of the current "seek to end, find pos, seek back to original pos" pattern Change-Id: Ib5828868f73c341891efc759af8bd4695ae2f33c Reviewed-on: https://gerrit.libreoffice.org/61738 Tested-by: Jenkins Reviewed-by: Noel Grandin --- svx/qa/unit/xoutdev.cxx | 4 +--- svx/source/dialog/compressgraphicdialog.cxx | 6 ++---- svx/source/gallery2/codec.cxx | 3 +-- svx/source/xml/xmlgrhlp.cxx | 9 +++------ svx/source/xoutdev/_xoutbmp.cxx | 3 +-- 5 files changed, 8 insertions(+), 17 deletions(-) (limited to 'svx') diff --git a/svx/qa/unit/xoutdev.cxx b/svx/qa/unit/xoutdev.cxx index c2f48fbbc5c6..90186df8e831 100644 --- a/svx/qa/unit/xoutdev.cxx +++ b/svx/qa/unit/xoutdev.cxx @@ -57,9 +57,7 @@ void XOutdevTest::testPdfGraphicExport() // Assert that the output looks like a PDF. SvStream* pStream = aTempFile.GetStream(StreamMode::READ); - pStream->Seek(STREAM_SEEK_TO_END); - CPPUNIT_ASSERT(pStream->Tell() > 5); - pStream->Seek(STREAM_SEEK_TO_BEGIN); + CPPUNIT_ASSERT(pStream->TellEnd() > 5); sal_uInt8 sFirstBytes[5]; pStream->ReadBytes(sFirstBytes, 5); CPPUNIT_ASSERT_EQUAL(static_cast('%'), sFirstBytes[0]); diff --git a/svx/source/dialog/compressgraphicdialog.cxx b/svx/source/dialog/compressgraphicdialog.cxx index 3c68d0f1d5b1..8a39d7cf5635 100644 --- a/svx/source/dialog/compressgraphicdialog.cxx +++ b/svx/source/dialog/compressgraphicdialog.cxx @@ -191,8 +191,7 @@ void CompressGraphicsDialog::Update() SvMemoryStream aMemStream; aMemStream.SetVersion( SOFFICE_FILEFORMAT_CURRENT ); m_aGraphic.ExportNative(aMemStream); - aMemStream.Seek( STREAM_SEEK_TO_END ); - sal_Int32 aNativeSize = aMemStream.Tell(); + sal_Int32 aNativeSize = aMemStream.TellEnd(); OUString aNativeSizeString = SvxResId(STR_IMAGE_CAPACITY); aNativeSizeString = aNativeSizeString.replaceAll("$(CAPACITY)", OUString::number(aNativeSize / 1024)); @@ -353,8 +352,7 @@ IMPL_LINK_NOARG( CompressGraphicsDialog, CalculateClickHdl, weld::Button&, void SvMemoryStream aMemStream; aMemStream.SetVersion( SOFFICE_FILEFORMAT_CURRENT ); Compress( aMemStream ); - aMemStream.Seek( STREAM_SEEK_TO_END ); - aSize = aMemStream.Tell(); + aSize = aMemStream.TellEnd(); } if ( aSize > 0 ) diff --git a/svx/source/gallery2/codec.cxx b/svx/source/gallery2/codec.cxx index 0149b4de5e97..773b769a2678 100644 --- a/svx/source/gallery2/codec.cxx +++ b/svx/source/gallery2/codec.cxx @@ -61,8 +61,7 @@ void GalleryCodec::Write( SvStream& rStmToWrite ) { sal_uInt32 nPos, nCompSize; - rStmToWrite.Seek( STREAM_SEEK_TO_END ); - const sal_uInt32 nSize = rStmToWrite.Tell(); + const sal_uInt32 nSize = rStmToWrite.TellEnd(); rStmToWrite.Seek( 0 ); rStm.WriteChar( 'S' ).WriteChar( 'V' ).WriteChar( 'R' ).WriteChar( 'L' ).WriteChar( 'E' ).WriteChar( '2' ); diff --git a/svx/source/xml/xmlgrhlp.cxx b/svx/source/xml/xmlgrhlp.cxx index cb6eb4d80e3a..b45954fdbd0d 100644 --- a/svx/source/xml/xmlgrhlp.cxx +++ b/svx/source/xml/xmlgrhlp.cxx @@ -306,8 +306,7 @@ Graphic SvXMLGraphicOutputStream::GetGraphic() sal_uInt8 sFirstBytes[ 2 ]; - mpOStm->Seek( STREAM_SEEK_TO_END ); - sal_uIntPtr nStreamLen = mpOStm->Tell(); + sal_uIntPtr nStreamLen = mpOStm->TellEnd(); mpOStm->Seek( 0 ); if ( !nStreamLen ) @@ -316,8 +315,7 @@ Graphic SvXMLGraphicOutputStream::GetGraphic() if ( pLockBytes ) pLockBytes->SetSynchronMode(); - mpOStm->Seek( STREAM_SEEK_TO_END ); - nStreamLen = mpOStm->Tell(); + nStreamLen = mpOStm->TellEnd(); mpOStm->Seek( 0 ); } if( nStreamLen >= 2 ) @@ -335,8 +333,7 @@ Graphic SvXMLGraphicOutputStream::GetGraphic() if (aZCodec.EndCompression() && pDest ) { - pDest->Seek( STREAM_SEEK_TO_END ); - sal_uIntPtr nStreamLen_ = pDest->Tell(); + sal_uIntPtr nStreamLen_ = pDest->TellEnd(); if (nStreamLen_) { pDest->Seek(0); diff --git a/svx/source/xoutdev/_xoutbmp.cxx b/svx/source/xoutdev/_xoutbmp.cxx index 718b73e3f412..640d7bb356f0 100644 --- a/svx/source/xoutdev/_xoutbmp.cxx +++ b/svx/source/xoutdev/_xoutbmp.cxx @@ -380,8 +380,7 @@ bool XOutBitmap::GraphicToBase64(const Graphic& rGraphic, OUString& rOUString, b SAL_WARN("svx", "XOutBitmap::GraphicToBase64() invalid Graphic? error: " << nErr ); return false; } - aOStm.Seek(STREAM_SEEK_TO_END); - css::uno::Sequence aOStmSeq( static_cast(aOStm.GetData()),aOStm.Tell() ); + css::uno::Sequence aOStmSeq( static_cast(aOStm.GetData()),aOStm.TellEnd() ); OUStringBuffer aStrBuffer; ::comphelper::Base64::encode(aStrBuffer,aOStmSeq); rOUString = aStrBuffer.makeStringAndClear(); -- cgit