25#include <com/sun/star/lang/XServiceInfo.hpp>
26#include <com/sun/star/io/NotConnectedException.hpp>
27#include <com/sun/star/io/XSequenceOutputStream.hpp>
37class SequenceOutputStreamService:
38 public cppu::WeakImplHelper<lang::XServiceInfo, io::XSequenceOutputStream>
41 explicit SequenceOutputStreamService();
44 SequenceOutputStreamService(
const SequenceOutputStreamService&) =
delete;
45 const SequenceOutputStreamService& operator=(
const SequenceOutputStreamService&) =
delete;
53 virtual void SAL_CALL writeBytes(
const uno::Sequence< ::sal_Int8 > & aData )
override;
54 virtual void SAL_CALL flush()
override;
55 virtual void SAL_CALL closeOutput()
override;
58 virtual uno::Sequence< ::sal_Int8 > SAL_CALL getWrittenBytes( )
override;
61 virtual ~SequenceOutputStreamService()
override {};
66 uno::Sequence< ::sal_Int8 > m_aSequence;
67 uno::Reference< io::XOutputStream > m_xOutputStream;
69SequenceOutputStreamService::SequenceOutputStreamService()
71 m_xOutputStream.set(
static_cast < ::
cppu::OWeakObject*
>( new ::comphelper::OSequenceOutputStream( m_aSequence ) ), uno::UNO_QUERY_THROW );
75OUString SAL_CALL SequenceOutputStreamService::getImplementationName()
77 return "com.sun.star.comp.SequenceOutputStreamService";
80sal_Bool SAL_CALL SequenceOutputStreamService::supportsService( OUString
const & serviceName )
85uno::Sequence< OUString > SAL_CALL SequenceOutputStreamService::getSupportedServiceNames()
87 return {
"com.sun.star.io.SequenceOutputStream" };
91void SAL_CALL SequenceOutputStreamService::writeBytes(
const uno::Sequence< ::sal_Int8 > & aData )
94 if ( !m_xOutputStream.is() )
95 throw io::NotConnectedException();
97 m_xOutputStream->writeBytes( aData );
100void SAL_CALL SequenceOutputStreamService::flush()
102 std::scoped_lock aGuard(
m_aMutex );
103 if ( !m_xOutputStream.is() )
104 throw io::NotConnectedException();
106 m_xOutputStream->flush();
109void SAL_CALL SequenceOutputStreamService::closeOutput()
111 std::scoped_lock aGuard(
m_aMutex );
112 if ( !m_xOutputStream.is() )
113 throw io::NotConnectedException();
115 m_xOutputStream->flush();
116 m_xOutputStream->closeOutput();
117 m_xOutputStream.clear();
121uno::Sequence< ::sal_Int8 > SAL_CALL SequenceOutputStreamService::getWrittenBytes()
123 std::scoped_lock aGuard(
m_aMutex );
125 if (m_xOutputStream.is())
127 m_xOutputStream->flush();
136extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
138 css::uno::XComponentContext *,
139 css::uno::Sequence<css::uno::Any>
const &)
141 return cppu::acquire(
new SequenceOutputStreamService());
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_SequenceOutputStreamService(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)