20#include <osl/diagnose.h>
21#include <com/sun/star/io/IOException.hpp>
22#include <com/sun/star/io/NotConnectedException.hpp>
23#include <com/sun/star/io/TempFile.hpp>
48 uno::Reference< io::XTruncate > xOrigTruncate,
49 uno::Reference< io::XSeekable > xOrigSeekable,
50 uno::Reference< io::XInputStream > xOrigInStream,
51 uno::Reference< io::XOutputStream > xOrigOutStream,
66 const uno::Reference< io::XStream >& xStream )
72 const uno::Reference< io::XInputStream >& xInputStream )
84 uno::Reference< io::XTruncate > xNewTruncate( xStream, uno::UNO_QUERY_THROW );
85 uno::Reference< io::XSeekable > xNewSeekable( xStream, uno::UNO_QUERY_THROW );
86 uno::Reference< io::XInputStream > xNewInStream =
xStream->getInputStream();
87 uno::Reference< io::XOutputStream > xNewOutStream =
xStream->getOutputStream();
88 if ( !xNewInStream.is() || !xNewOutStream.is() )
89 throw uno::RuntimeException();
93 bool bOutOpen =
false;
98 if (
m_pStreamData->m_xOrigSeekable->getLength() != xNewSeekable->getLength() )
99 throw uno::RuntimeException();
107 xNewSeekable->seek( nPos );
112 xNewTruncate, xNewSeekable, xNewInStream, xNewOutStream,
113 bInOpen, bOutOpen ) );
118 uno::Reference< io::XTruncate > xNewTruncate;
119 uno::Reference< io::XSeekable > xNewSeekable( xInputStream, uno::UNO_QUERY_THROW );
120 uno::Reference< io::XOutputStream > xNewOutStream;
121 if ( !xInputStream.is() )
122 throw uno::RuntimeException();
125 bool bInOpen =
false;
126 bool bOutOpen =
false;
131 if (
m_pStreamData->m_xOrigSeekable->getLength() != xNewSeekable->getLength() )
132 throw uno::RuntimeException();
140 xNewSeekable->seek( nPos );
145 xNewTruncate, xNewSeekable, xInputStream, xNewOutStream,
146 bInOpen, bOutOpen ) );
152 uno::Reference< io::XStream > xTargetStream =
xStream;
153 uno::Reference< io::XSeekable > xTargetSeek;
155 if ( !xTargetStream.is() )
158 xTargetSeek.set( xTargetStream, uno::UNO_QUERY_THROW );
163 xTargetSeek.set( xTargetStream, uno::UNO_QUERY_THROW );
164 if ( xTargetSeek->getLength() )
165 throw io::IOException(
"provided stream not empty");
168 uno::Reference< io::XTruncate > xTargetTruncate( xTargetStream, uno::UNO_QUERY_THROW );
169 uno::Reference< io::XInputStream > xTargetInStream = xTargetStream->getInputStream();
170 uno::Reference< io::XOutputStream > xTargetOutStream = xTargetStream->getOutputStream();
171 if ( !xTargetInStream.is() || !xTargetOutStream.is() )
172 throw uno::RuntimeException();
175 throw uno::RuntimeException();
180 xTargetOutStream->flush();
181 xTargetSeek->seek(
nPos );
189 xTargetTruncate, xTargetSeek, xTargetInStream, xTargetOutStream,
190 bInOpen, bOutOpen ) );
201 std::scoped_lock aGuard(
m_aMutex );
205 return static_cast< io::XInputStream*
>( this );
210 std::scoped_lock aGuard(
m_aMutex );
214 return static_cast< io::XOutputStream*
>( this );
220 std::scoped_lock aGuard(
m_aMutex );
223 throw io::NotConnectedException();
227 throw uno::RuntimeException();
234 std::scoped_lock aGuard(
m_aMutex );
237 throw io::NotConnectedException();
241 throw uno::RuntimeException();
248 std::scoped_lock aGuard(
m_aMutex );
251 throw io::NotConnectedException();
255 throw uno::RuntimeException();
262 std::scoped_lock aGuard(
m_aMutex );
265 throw io::NotConnectedException();
269 throw uno::RuntimeException();
276 std::scoped_lock aGuard(
m_aMutex );
279 throw io::NotConnectedException();
289 std::scoped_lock aGuard(
m_aMutex );
292 throw io::NotConnectedException();
295 throw io::IOException();
299 throw uno::RuntimeException();
306 std::scoped_lock aGuard(
m_aMutex );
310 OSL_FAIL(
"flush() is not acceptable!" );
319 throw uno::RuntimeException();
326 std::scoped_lock aGuard(
m_aMutex );
329 throw io::NotConnectedException();
339 std::scoped_lock aGuard(
m_aMutex );
342 throw io::NotConnectedException();
345 throw io::IOException();
349 throw uno::RuntimeException();
357 std::scoped_lock aGuard(
m_aMutex );
360 throw io::NotConnectedException();
364 throw uno::RuntimeException();
371 std::scoped_lock aGuard(
m_aMutex );
374 throw io::NotConnectedException();
378 throw uno::RuntimeException();
385 std::scoped_lock aGuard(
m_aMutex );
388 throw io::NotConnectedException();
392 throw uno::RuntimeException();
400 throw io::NotConnectedException();
402 uno::Reference< io::XAsyncOutputMonitor > asyncOutputMonitor(
m_pStreamData->m_xOrigOutStream, uno::UNO_QUERY );
403 if ( asyncOutputMonitor.is() )
404 asyncOutputMonitor->waitForCompletion();
virtual ::sal_Int64 SAL_CALL getPosition() override
virtual void SAL_CALL closeInput() override
virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getInputStream() override
virtual void SAL_CALL writeBytes(const css::uno::Sequence< ::sal_Int8 > &aData) override
void SwitchPersistenceTo(const css::uno::Reference< css::io::XStream > &xStream)
virtual ::sal_Int32 SAL_CALL readSomeBytes(css::uno::Sequence< ::sal_Int8 > &aData, ::sal_Int32 nMaxBytesToRead) override
virtual ::sal_Int32 SAL_CALL available() override
virtual void SAL_CALL closeOutput() override
virtual void SAL_CALL truncate() override
void CopyAndSwitchPersistenceTo(const css::uno::Reference< css::io::XStream > &xStream)
virtual ::sal_Int64 SAL_CALL getLength() override
virtual void SAL_CALL flush() override
virtual css::uno::Reference< css::io::XOutputStream > SAL_CALL getOutputStream() override
virtual void SAL_CALL waitForCompletion() override
virtual ~SwitchablePersistenceStream() override
virtual void SAL_CALL seek(::sal_Int64 location) override
std::unique_ptr< SPStreamData_Impl > m_pStreamData
virtual ::sal_Int32 SAL_CALL readBytes(css::uno::Sequence< ::sal_Int8 > &aData, ::sal_Int32 nBytesToRead) override
virtual void SAL_CALL skipBytes(::sal_Int32 nBytesToSkip) override
SwitchablePersistenceStream(const css::uno::Reference< css::io::XStream > &xStream)
static void CopyInputToOutput(const css::uno::Reference< css::io::XInputStream > &xInput, const css::uno::Reference< css::io::XOutputStream > &xOutput)
constexpr OUStringLiteral aData
uno::Reference< io::XSeekable > m_xOrigSeekable
uno::Reference< io::XOutputStream > m_xOrigOutStream
SPStreamData_Impl(bool bInStreamBased, uno::Reference< io::XTruncate > xOrigTruncate, uno::Reference< io::XSeekable > xOrigSeekable, uno::Reference< io::XInputStream > xOrigInStream, uno::Reference< io::XOutputStream > xOrigOutStream, bool bInOpen, bool bOutOpen)
uno::Reference< io::XInputStream > m_xOrigInStream
uno::Reference< io::XTruncate > m_xOrigTruncate