From 1a3b3eda6ca1c8e063ba6db9e9f34f999ec92c49 Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Mon, 4 Oct 2021 17:16:59 +0200 Subject: comphelper: fix SequenceOutputStreamService::getWrittenBytes() With com.sun.star.io.Pipe, you must call closeOutput() or reading from the other end will block forever. If you use com.sun.star.io.SequenceOutputStream, you can't read the output after calling closeOutput() on it because for no good reason it throws a NotConnectedException. Let's just fix it so that a sequence of closeOutput() then getWrittenBytes() returns the finished buffer. Change-Id: Ia6ce28ec05e00e5f1c703dea8669e0271c0b9c20 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123057 Tested-by: Jenkins Reviewed-by: Michael Stahl --- comphelper/source/streaming/seqoutputstreamserv.cxx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/comphelper/source/streaming/seqoutputstreamserv.cxx b/comphelper/source/streaming/seqoutputstreamserv.cxx index d1ffc4df2d42..84900014aad4 100644 --- a/comphelper/source/streaming/seqoutputstreamserv.cxx +++ b/comphelper/source/streaming/seqoutputstreamserv.cxx @@ -112,6 +112,7 @@ void SAL_CALL SequenceOutputStreamService::closeOutput() if ( !m_xOutputStream.is() ) throw io::NotConnectedException(); + m_xOutputStream->flush(); m_xOutputStream->closeOutput(); m_xOutputStream.clear(); } @@ -120,10 +121,13 @@ void SAL_CALL SequenceOutputStreamService::closeOutput() uno::Sequence< ::sal_Int8 > SAL_CALL SequenceOutputStreamService::getWrittenBytes() { std::scoped_lock aGuard( m_aMutex ); - if ( !m_xOutputStream.is() ) - throw io::NotConnectedException(); - m_xOutputStream->flush(); + if (m_xOutputStream.is()) + { + m_xOutputStream->flush(); + } + // else: no exception, just return the finished sequence + return m_aSequence; } -- cgit