25#include <com/sun/star/lang/IllegalArgumentException.hpp>
26#include <com/sun/star/lang/XServiceInfo.hpp>
27#include <com/sun/star/io/NotConnectedException.hpp>
28#include <com/sun/star/io/XSeekableInputStream.hpp>
29#include <com/sun/star/lang/XInitialization.hpp>
30#include <com/sun/star/frame/DoubleInitializationException.hpp>
39class SequenceInputStreamService:
40 public ::cppu::WeakImplHelper<
42 io::XSeekableInputStream,
43 lang::XInitialization>
46 explicit SequenceInputStreamService();
49 SequenceInputStreamService(
const SequenceInputStreamService&) =
delete;
50 const SequenceInputStreamService& operator=(
const SequenceInputStreamService&) =
delete;
58 virtual ::sal_Int32 SAL_CALL readBytes( uno::Sequence< ::sal_Int8 > & aData, ::sal_Int32 nBytesToRead )
override;
59 virtual ::sal_Int32 SAL_CALL readSomeBytes( uno::Sequence< ::sal_Int8 > & aData, ::sal_Int32 nMaxBytesToRead )
override;
60 virtual void SAL_CALL skipBytes( ::sal_Int32 nBytesToSkip )
override;
61 virtual ::sal_Int32 SAL_CALL available()
override;
62 virtual void SAL_CALL closeInput()
override;
65 virtual void SAL_CALL seek( ::sal_Int64 location )
override;
66 virtual ::sal_Int64 SAL_CALL getPosition()
override;
67 virtual ::sal_Int64 SAL_CALL
getLength()
override;
70 virtual void SAL_CALL initialize(
const uno::Sequence< css::uno::Any > & aArguments )
override;
73 virtual ~SequenceInputStreamService()
override {}
78 uno::Reference< io::XInputStream > m_xInputStream;
82SequenceInputStreamService::SequenceInputStreamService()
83: m_bInitialized( false )
87OUString SAL_CALL SequenceInputStreamService::getImplementationName()
89 return "com.sun.star.comp.SequenceInputStreamService";
92sal_Bool SAL_CALL SequenceInputStreamService::supportsService( OUString
const & serviceName )
97uno::Sequence< OUString > SAL_CALL SequenceInputStreamService::getSupportedServiceNames()
99 return {
"com.sun.star.io.SequenceInputStream" };
103::sal_Int32 SAL_CALL SequenceInputStreamService::readBytes( uno::Sequence< ::sal_Int8 > & aData, ::sal_Int32 nBytesToRead )
105 std::scoped_lock aGuard(
m_aMutex );
106 if ( !m_xInputStream.is() )
107 throw io::NotConnectedException();
109 return m_xInputStream->readBytes( aData, nBytesToRead );
112::sal_Int32 SAL_CALL SequenceInputStreamService::readSomeBytes( uno::Sequence< ::sal_Int8 > & aData, ::sal_Int32 nMaxBytesToRead )
114 std::scoped_lock aGuard(
m_aMutex );
115 if ( !m_xInputStream.is() )
116 throw io::NotConnectedException();
118 return m_xInputStream->readSomeBytes( aData, nMaxBytesToRead );
121void SAL_CALL SequenceInputStreamService::skipBytes( ::sal_Int32 nBytesToSkip )
123 std::scoped_lock aGuard(
m_aMutex );
124 if ( !m_xInputStream.is() )
125 throw io::NotConnectedException();
127 return m_xInputStream->skipBytes( nBytesToSkip );
130::sal_Int32 SAL_CALL SequenceInputStreamService::available()
132 std::scoped_lock aGuard(
m_aMutex );
133 if ( !m_xInputStream.is() )
134 throw io::NotConnectedException();
136 return m_xInputStream->available();
139void SAL_CALL SequenceInputStreamService::closeInput()
141 std::scoped_lock aGuard(
m_aMutex );
142 if ( !m_xInputStream.is() )
143 throw io::NotConnectedException();
145 m_xInputStream->closeInput();
146 m_xInputStream.clear();
151void SAL_CALL SequenceInputStreamService::seek( ::sal_Int64 location )
153 std::scoped_lock aGuard(
m_aMutex );
155 throw io::NotConnectedException();
160::sal_Int64 SAL_CALL SequenceInputStreamService::getPosition()
162 std::scoped_lock aGuard(
m_aMutex );
164 throw io::NotConnectedException();
169::sal_Int64 SAL_CALL SequenceInputStreamService::getLength()
171 std::scoped_lock aGuard(
m_aMutex );
173 throw io::NotConnectedException();
179void SAL_CALL SequenceInputStreamService::initialize(
const uno::Sequence< css::uno::Any > & aArguments )
181 std::scoped_lock aGuard(
m_aMutex );
182 if ( m_bInitialized )
183 throw frame::DoubleInitializationException();
186 throw lang::IllegalArgumentException(
"Wrong number of arguments!",
190 uno::Sequence< sal_Int8 >
aSeq;
191 if ( !(aArguments[0] >>= aSeq) )
192 throw lang::IllegalArgumentException(
"Unexpected type of argument!",
196 uno::Reference< io::XInputStream > xInputStream(
197 static_cast< ::
cppu::OWeakObject*
>( new ::comphelper::SequenceInputStream( aSeq ) ),
198 uno::UNO_QUERY_THROW );
199 uno::Reference< io::XSeekable > xSeekable( xInputStream, uno::UNO_QUERY_THROW );
200 m_xInputStream = xInputStream;
202 m_bInitialized =
true;
207extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
209 css::uno::XComponentContext *,
210 css::uno::Sequence<css::uno::Any>
const &)
212 return cppu::acquire(
new SequenceInputStreamService());
uno::Reference< io::XSeekable > m_xSeekable
Sequence< PropertyValue > aArguments
Sequence< sal_Int8 > aSeq
double getLength(const B2DPolygon &rCandidate)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)