1*40df464eSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*40df464eSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*40df464eSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*40df464eSAndrew Rist * distributed with this work for additional information
6*40df464eSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*40df464eSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*40df464eSAndrew Rist * "License"); you may not use this file except in compliance
9*40df464eSAndrew Rist * with the License. You may obtain a copy of the License at
10*40df464eSAndrew Rist *
11*40df464eSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*40df464eSAndrew Rist *
13*40df464eSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*40df464eSAndrew Rist * software distributed under the License is distributed on an
15*40df464eSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*40df464eSAndrew Rist * KIND, either express or implied. See the License for the
17*40df464eSAndrew Rist * specific language governing permissions and limitations
18*40df464eSAndrew Rist * under the License.
19*40df464eSAndrew Rist *
20*40df464eSAndrew Rist *************************************************************/
21*40df464eSAndrew Rist
22*40df464eSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svl.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "ostreamcontainer.hxx"
28cdf0e10cSrcweir
29cdf0e10cSrcweir
30cdf0e10cSrcweir using namespace ::com::sun::star;
31cdf0e10cSrcweir
32cdf0e10cSrcweir //-----------------------------------------------
OFSStreamContainer(const uno::Reference<io::XStream> & xStream)33cdf0e10cSrcweir OFSStreamContainer::OFSStreamContainer( const uno::Reference < io::XStream >& xStream )
34cdf0e10cSrcweir : m_bDisposed( sal_False )
35cdf0e10cSrcweir , m_bInputClosed( sal_False )
36cdf0e10cSrcweir , m_bOutputClosed( sal_False )
37cdf0e10cSrcweir , m_pListenersContainer( NULL )
38cdf0e10cSrcweir , m_pTypeCollection( NULL )
39cdf0e10cSrcweir {
40cdf0e10cSrcweir try
41cdf0e10cSrcweir {
42cdf0e10cSrcweir m_xStream = xStream;
43cdf0e10cSrcweir if ( !m_xStream.is() )
44cdf0e10cSrcweir throw uno::RuntimeException();
45cdf0e10cSrcweir
46cdf0e10cSrcweir m_xSeekable = uno::Reference< io::XSeekable >( xStream, uno::UNO_QUERY );
47cdf0e10cSrcweir m_xInputStream = xStream->getInputStream();
48cdf0e10cSrcweir m_xOutputStream = xStream->getOutputStream();
49cdf0e10cSrcweir m_xTruncate = uno::Reference< io::XTruncate >( m_xOutputStream, uno::UNO_QUERY );
50cdf0e10cSrcweir m_xAsyncOutputMonitor = uno::Reference< io::XAsyncOutputMonitor >( m_xOutputStream, uno::UNO_QUERY );
51cdf0e10cSrcweir }
52cdf0e10cSrcweir catch( uno::Exception& )
53cdf0e10cSrcweir {
54cdf0e10cSrcweir m_xStream = uno::Reference< io::XStream >();
55cdf0e10cSrcweir m_xSeekable = uno::Reference< io::XSeekable >();
56cdf0e10cSrcweir m_xInputStream = uno::Reference< io::XInputStream >();
57cdf0e10cSrcweir m_xOutputStream = uno::Reference< io::XOutputStream >();
58cdf0e10cSrcweir m_xTruncate = uno::Reference< io::XTruncate >();
59cdf0e10cSrcweir m_xAsyncOutputMonitor = uno::Reference< io::XAsyncOutputMonitor >();
60cdf0e10cSrcweir }
61cdf0e10cSrcweir }
62cdf0e10cSrcweir
63cdf0e10cSrcweir //-----------------------------------------------
~OFSStreamContainer()64cdf0e10cSrcweir OFSStreamContainer::~OFSStreamContainer()
65cdf0e10cSrcweir {
66cdf0e10cSrcweir if ( m_pListenersContainer )
67cdf0e10cSrcweir {
68cdf0e10cSrcweir delete m_pListenersContainer;
69cdf0e10cSrcweir m_pListenersContainer = NULL;
70cdf0e10cSrcweir }
71cdf0e10cSrcweir }
72cdf0e10cSrcweir
73cdf0e10cSrcweir // XInterface
74cdf0e10cSrcweir //-----------------------------------------------
queryInterface(const uno::Type & rType)75cdf0e10cSrcweir uno::Any SAL_CALL OFSStreamContainer::queryInterface( const uno::Type& rType )
76cdf0e10cSrcweir throw( uno::RuntimeException )
77cdf0e10cSrcweir {
78cdf0e10cSrcweir uno::Any aReturn;
79cdf0e10cSrcweir
80cdf0e10cSrcweir aReturn <<= ::cppu::queryInterface
81cdf0e10cSrcweir ( rType
82cdf0e10cSrcweir , static_cast<lang::XTypeProvider*> ( this )
83cdf0e10cSrcweir , static_cast<io::XStream*> ( this )
84cdf0e10cSrcweir , static_cast<embed::XExtendedStorageStream*> ( this )
85cdf0e10cSrcweir , static_cast<lang::XComponent*> ( this ) );
86cdf0e10cSrcweir
87cdf0e10cSrcweir if ( aReturn.hasValue() == sal_True )
88cdf0e10cSrcweir return aReturn ;
89cdf0e10cSrcweir
90cdf0e10cSrcweir if ( m_xSeekable.is() )
91cdf0e10cSrcweir {
92cdf0e10cSrcweir aReturn <<= ::cppu::queryInterface
93cdf0e10cSrcweir ( rType
94cdf0e10cSrcweir , static_cast<io::XSeekable*> ( this ) );
95cdf0e10cSrcweir
96cdf0e10cSrcweir if ( aReturn.hasValue() == sal_True )
97cdf0e10cSrcweir return aReturn ;
98cdf0e10cSrcweir }
99cdf0e10cSrcweir
100cdf0e10cSrcweir if ( m_xInputStream.is() )
101cdf0e10cSrcweir {
102cdf0e10cSrcweir aReturn <<= ::cppu::queryInterface
103cdf0e10cSrcweir ( rType
104cdf0e10cSrcweir , static_cast<io::XInputStream*> ( this ) );
105cdf0e10cSrcweir
106cdf0e10cSrcweir if ( aReturn.hasValue() == sal_True )
107cdf0e10cSrcweir return aReturn ;
108cdf0e10cSrcweir }
109cdf0e10cSrcweir if ( m_xOutputStream.is() )
110cdf0e10cSrcweir {
111cdf0e10cSrcweir aReturn <<= ::cppu::queryInterface
112cdf0e10cSrcweir ( rType
113cdf0e10cSrcweir , static_cast<io::XOutputStream*> ( this ) );
114cdf0e10cSrcweir
115cdf0e10cSrcweir if ( aReturn.hasValue() == sal_True )
116cdf0e10cSrcweir return aReturn ;
117cdf0e10cSrcweir }
118cdf0e10cSrcweir if ( m_xTruncate.is() )
119cdf0e10cSrcweir {
120cdf0e10cSrcweir aReturn <<= ::cppu::queryInterface
121cdf0e10cSrcweir ( rType
122cdf0e10cSrcweir , static_cast<io::XTruncate*> ( this ) );
123cdf0e10cSrcweir
124cdf0e10cSrcweir if ( aReturn.hasValue() == sal_True )
125cdf0e10cSrcweir return aReturn ;
126cdf0e10cSrcweir }
127cdf0e10cSrcweir if ( m_xAsyncOutputMonitor.is() )
128cdf0e10cSrcweir {
129cdf0e10cSrcweir aReturn <<= ::cppu::queryInterface
130cdf0e10cSrcweir ( rType
131cdf0e10cSrcweir , static_cast<io::XAsyncOutputMonitor*> ( this ) );
132cdf0e10cSrcweir
133cdf0e10cSrcweir if ( aReturn.hasValue() == sal_True )
134cdf0e10cSrcweir return aReturn ;
135cdf0e10cSrcweir }
136cdf0e10cSrcweir
137cdf0e10cSrcweir return OWeakObject::queryInterface( rType );
138cdf0e10cSrcweir }
139cdf0e10cSrcweir
140cdf0e10cSrcweir //-----------------------------------------------
acquire()141cdf0e10cSrcweir void SAL_CALL OFSStreamContainer::acquire()
142cdf0e10cSrcweir throw()
143cdf0e10cSrcweir {
144cdf0e10cSrcweir OWeakObject::acquire();
145cdf0e10cSrcweir }
146cdf0e10cSrcweir
147cdf0e10cSrcweir //-----------------------------------------------
release()148cdf0e10cSrcweir void SAL_CALL OFSStreamContainer::release()
149cdf0e10cSrcweir throw()
150cdf0e10cSrcweir {
151cdf0e10cSrcweir OWeakObject::release();
152cdf0e10cSrcweir }
153cdf0e10cSrcweir
154cdf0e10cSrcweir // XTypeProvider
155cdf0e10cSrcweir //-----------------------------------------------
getTypes()156cdf0e10cSrcweir uno::Sequence< uno::Type > SAL_CALL OFSStreamContainer::getTypes()
157cdf0e10cSrcweir throw( uno::RuntimeException )
158cdf0e10cSrcweir {
159cdf0e10cSrcweir if ( m_pTypeCollection == NULL )
160cdf0e10cSrcweir {
161cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
162cdf0e10cSrcweir
163cdf0e10cSrcweir if ( m_pTypeCollection == NULL )
164cdf0e10cSrcweir {
165cdf0e10cSrcweir ::cppu::OTypeCollection aTypeCollection
166cdf0e10cSrcweir ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL )
167cdf0e10cSrcweir , ::getCppuType( ( const uno::Reference< embed::XExtendedStorageStream >* )NULL ) );
168cdf0e10cSrcweir
169cdf0e10cSrcweir if ( m_xSeekable.is() )
170cdf0e10cSrcweir aTypeCollection = ::cppu::OTypeCollection
171cdf0e10cSrcweir ( ::getCppuType( ( const uno::Reference< io::XSeekable >* )NULL ),
172cdf0e10cSrcweir aTypeCollection.getTypes() );
173cdf0e10cSrcweir if ( m_xInputStream.is() )
174cdf0e10cSrcweir aTypeCollection = ::cppu::OTypeCollection
175cdf0e10cSrcweir ( ::getCppuType( ( const uno::Reference< io::XInputStream >* )NULL ),
176cdf0e10cSrcweir aTypeCollection.getTypes() );
177cdf0e10cSrcweir
178cdf0e10cSrcweir if ( m_xOutputStream.is() )
179cdf0e10cSrcweir aTypeCollection = ::cppu::OTypeCollection
180cdf0e10cSrcweir ( ::getCppuType( ( const uno::Reference< io::XOutputStream >* )NULL ),
181cdf0e10cSrcweir aTypeCollection.getTypes() );
182cdf0e10cSrcweir if ( m_xTruncate.is() )
183cdf0e10cSrcweir aTypeCollection = ::cppu::OTypeCollection
184cdf0e10cSrcweir ( ::getCppuType( ( const uno::Reference< io::XTruncate >* )NULL ),
185cdf0e10cSrcweir aTypeCollection.getTypes() );
186cdf0e10cSrcweir if ( m_xAsyncOutputMonitor.is() )
187cdf0e10cSrcweir aTypeCollection = ::cppu::OTypeCollection
188cdf0e10cSrcweir ( ::getCppuType( ( const uno::Reference< io::XAsyncOutputMonitor >* )NULL ),
189cdf0e10cSrcweir aTypeCollection.getTypes() );
190cdf0e10cSrcweir
191cdf0e10cSrcweir m_pTypeCollection = new ::cppu::OTypeCollection( aTypeCollection );
192cdf0e10cSrcweir }
193cdf0e10cSrcweir }
194cdf0e10cSrcweir return m_pTypeCollection->getTypes() ;
195cdf0e10cSrcweir }
196cdf0e10cSrcweir
197cdf0e10cSrcweir //-----------------------------------------------
getImplementationId()198cdf0e10cSrcweir uno::Sequence< sal_Int8 > SAL_CALL OFSStreamContainer::getImplementationId()
199cdf0e10cSrcweir throw( uno::RuntimeException )
200cdf0e10cSrcweir {
201cdf0e10cSrcweir static ::cppu::OImplementationId* pID = NULL ;
202cdf0e10cSrcweir
203cdf0e10cSrcweir if ( pID == NULL )
204cdf0e10cSrcweir {
205cdf0e10cSrcweir ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ) ;
206cdf0e10cSrcweir
207cdf0e10cSrcweir if ( pID == NULL )
208cdf0e10cSrcweir {
209cdf0e10cSrcweir static ::cppu::OImplementationId aID( sal_False ) ;
210cdf0e10cSrcweir pID = &aID ;
211cdf0e10cSrcweir }
212cdf0e10cSrcweir }
213cdf0e10cSrcweir
214cdf0e10cSrcweir return pID->getImplementationId() ;
215cdf0e10cSrcweir }
216cdf0e10cSrcweir
217cdf0e10cSrcweir // XStream
218cdf0e10cSrcweir //-----------------------------------------------
getInputStream()219cdf0e10cSrcweir uno::Reference< io::XInputStream > SAL_CALL OFSStreamContainer::getInputStream()
220cdf0e10cSrcweir throw ( uno::RuntimeException )
221cdf0e10cSrcweir {
222cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
223cdf0e10cSrcweir
224cdf0e10cSrcweir if ( m_bDisposed )
225cdf0e10cSrcweir throw lang::DisposedException();
226cdf0e10cSrcweir
227cdf0e10cSrcweir if ( !m_xStream.is() )
228cdf0e10cSrcweir throw uno::RuntimeException();
229cdf0e10cSrcweir
230cdf0e10cSrcweir if ( m_xInputStream.is() )
231cdf0e10cSrcweir return uno::Reference< io::XInputStream >( static_cast< io::XInputStream* >( this ) );
232cdf0e10cSrcweir
233cdf0e10cSrcweir return uno::Reference< io::XInputStream >();
234cdf0e10cSrcweir }
235cdf0e10cSrcweir
236cdf0e10cSrcweir //-----------------------------------------------
getOutputStream()237cdf0e10cSrcweir uno::Reference< io::XOutputStream > SAL_CALL OFSStreamContainer::getOutputStream()
238cdf0e10cSrcweir throw ( uno::RuntimeException )
239cdf0e10cSrcweir {
240cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
241cdf0e10cSrcweir
242cdf0e10cSrcweir if ( m_bDisposed )
243cdf0e10cSrcweir throw lang::DisposedException();
244cdf0e10cSrcweir
245cdf0e10cSrcweir if ( !m_xStream.is() )
246cdf0e10cSrcweir throw uno::RuntimeException();
247cdf0e10cSrcweir
248cdf0e10cSrcweir if ( m_xOutputStream.is() )
249cdf0e10cSrcweir return uno::Reference< io::XOutputStream >( static_cast< io::XOutputStream* >( this ) );
250cdf0e10cSrcweir
251cdf0e10cSrcweir return uno::Reference< io::XOutputStream >();
252cdf0e10cSrcweir }
253cdf0e10cSrcweir
254cdf0e10cSrcweir // XComponent
255cdf0e10cSrcweir //-----------------------------------------------
dispose()256cdf0e10cSrcweir void SAL_CALL OFSStreamContainer::dispose()
257cdf0e10cSrcweir throw ( uno::RuntimeException )
258cdf0e10cSrcweir {
259cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
260cdf0e10cSrcweir
261cdf0e10cSrcweir if ( m_bDisposed )
262cdf0e10cSrcweir throw lang::DisposedException();
263cdf0e10cSrcweir
264cdf0e10cSrcweir if ( !m_xStream.is() )
265cdf0e10cSrcweir throw uno::RuntimeException();
266cdf0e10cSrcweir
267cdf0e10cSrcweir if ( m_xInputStream.is() && !m_bInputClosed )
268cdf0e10cSrcweir {
269cdf0e10cSrcweir m_xInputStream->closeInput();
270cdf0e10cSrcweir m_bInputClosed = sal_True;
271cdf0e10cSrcweir }
272cdf0e10cSrcweir
273cdf0e10cSrcweir if ( m_xOutputStream.is() && !m_bOutputClosed )
274cdf0e10cSrcweir {
275cdf0e10cSrcweir m_xOutputStream->closeOutput();
276cdf0e10cSrcweir m_bOutputClosed = sal_True;
277cdf0e10cSrcweir }
278cdf0e10cSrcweir
279cdf0e10cSrcweir if ( m_pListenersContainer )
280cdf0e10cSrcweir {
281cdf0e10cSrcweir lang::EventObject aSource( static_cast< ::cppu::OWeakObject*>( this ) );
282cdf0e10cSrcweir m_pListenersContainer->disposeAndClear( aSource );
283cdf0e10cSrcweir }
284cdf0e10cSrcweir
285cdf0e10cSrcweir m_bDisposed = sal_True;
286cdf0e10cSrcweir }
287cdf0e10cSrcweir
288cdf0e10cSrcweir //-----------------------------------------------
addEventListener(const uno::Reference<lang::XEventListener> & xListener)289cdf0e10cSrcweir void SAL_CALL OFSStreamContainer::addEventListener( const uno::Reference< lang::XEventListener >& xListener )
290cdf0e10cSrcweir throw ( uno::RuntimeException )
291cdf0e10cSrcweir {
292cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
293cdf0e10cSrcweir
294cdf0e10cSrcweir if ( m_bDisposed )
295cdf0e10cSrcweir throw lang::DisposedException();
296cdf0e10cSrcweir
297cdf0e10cSrcweir if ( !m_pListenersContainer )
298cdf0e10cSrcweir m_pListenersContainer = new ::cppu::OInterfaceContainerHelper( m_aMutex );
299cdf0e10cSrcweir
300cdf0e10cSrcweir m_pListenersContainer->addInterface( xListener );
301cdf0e10cSrcweir }
302cdf0e10cSrcweir
303cdf0e10cSrcweir //-----------------------------------------------
removeEventListener(const uno::Reference<lang::XEventListener> & xListener)304cdf0e10cSrcweir void SAL_CALL OFSStreamContainer::removeEventListener( const uno::Reference< lang::XEventListener >& xListener )
305cdf0e10cSrcweir throw ( uno::RuntimeException )
306cdf0e10cSrcweir {
307cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
308cdf0e10cSrcweir
309cdf0e10cSrcweir if ( m_bDisposed )
310cdf0e10cSrcweir throw lang::DisposedException();
311cdf0e10cSrcweir
312cdf0e10cSrcweir if ( m_pListenersContainer )
313cdf0e10cSrcweir m_pListenersContainer->removeInterface( xListener );
314cdf0e10cSrcweir }
315cdf0e10cSrcweir
316cdf0e10cSrcweir
317cdf0e10cSrcweir // XSeekable
318cdf0e10cSrcweir //-----------------------------------------------
seek(sal_Int64 location)319cdf0e10cSrcweir void SAL_CALL OFSStreamContainer::seek( sal_Int64 location )
320cdf0e10cSrcweir throw ( lang::IllegalArgumentException,
321cdf0e10cSrcweir io::IOException,
322cdf0e10cSrcweir uno::RuntimeException )
323cdf0e10cSrcweir {
324cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
325cdf0e10cSrcweir
326cdf0e10cSrcweir if ( m_bDisposed )
327cdf0e10cSrcweir throw lang::DisposedException();
328cdf0e10cSrcweir
329cdf0e10cSrcweir if ( !m_xStream.is() || !m_xSeekable.is() )
330cdf0e10cSrcweir throw uno::RuntimeException();
331cdf0e10cSrcweir
332cdf0e10cSrcweir m_xSeekable->seek( location );
333cdf0e10cSrcweir }
334cdf0e10cSrcweir
335cdf0e10cSrcweir //-----------------------------------------------
getPosition()336cdf0e10cSrcweir sal_Int64 SAL_CALL OFSStreamContainer::getPosition()
337cdf0e10cSrcweir throw ( io::IOException,
338cdf0e10cSrcweir uno::RuntimeException )
339cdf0e10cSrcweir {
340cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
341cdf0e10cSrcweir
342cdf0e10cSrcweir if ( m_bDisposed )
343cdf0e10cSrcweir throw lang::DisposedException();
344cdf0e10cSrcweir
345cdf0e10cSrcweir if ( !m_xStream.is() || !m_xSeekable.is() )
346cdf0e10cSrcweir throw uno::RuntimeException();
347cdf0e10cSrcweir
348cdf0e10cSrcweir return m_xSeekable->getPosition();
349cdf0e10cSrcweir }
350cdf0e10cSrcweir
351cdf0e10cSrcweir //-----------------------------------------------
getLength()352cdf0e10cSrcweir sal_Int64 SAL_CALL OFSStreamContainer::getLength()
353cdf0e10cSrcweir throw ( io::IOException,
354cdf0e10cSrcweir uno::RuntimeException )
355cdf0e10cSrcweir {
356cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
357cdf0e10cSrcweir
358cdf0e10cSrcweir if ( m_bDisposed )
359cdf0e10cSrcweir throw lang::DisposedException();
360cdf0e10cSrcweir
361cdf0e10cSrcweir if ( !m_xStream.is() || !m_xSeekable.is() )
362cdf0e10cSrcweir throw uno::RuntimeException();
363cdf0e10cSrcweir
364cdf0e10cSrcweir return m_xSeekable->getLength();
365cdf0e10cSrcweir }
366cdf0e10cSrcweir
367cdf0e10cSrcweir
368cdf0e10cSrcweir // XInputStream
369cdf0e10cSrcweir //-----------------------------------------------
readBytes(uno::Sequence<sal_Int8> & aData,sal_Int32 nBytesToRead)370cdf0e10cSrcweir sal_Int32 SAL_CALL OFSStreamContainer::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
371cdf0e10cSrcweir throw( io::NotConnectedException,
372cdf0e10cSrcweir io::BufferSizeExceededException,
373cdf0e10cSrcweir io::IOException,
374cdf0e10cSrcweir uno::RuntimeException )
375cdf0e10cSrcweir {
376cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
377cdf0e10cSrcweir
378cdf0e10cSrcweir if ( m_bDisposed )
379cdf0e10cSrcweir throw lang::DisposedException();
380cdf0e10cSrcweir
381cdf0e10cSrcweir if ( !m_xStream.is() || !m_xInputStream.is() )
382cdf0e10cSrcweir throw uno::RuntimeException();
383cdf0e10cSrcweir
384cdf0e10cSrcweir return m_xInputStream->readBytes( aData, nBytesToRead );
385cdf0e10cSrcweir }
386cdf0e10cSrcweir
387cdf0e10cSrcweir //-----------------------------------------------
readSomeBytes(uno::Sequence<sal_Int8> & aData,sal_Int32 nMaxBytesToRead)388cdf0e10cSrcweir sal_Int32 SAL_CALL OFSStreamContainer::readSomeBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
389cdf0e10cSrcweir throw( io::NotConnectedException,
390cdf0e10cSrcweir io::BufferSizeExceededException,
391cdf0e10cSrcweir io::IOException,
392cdf0e10cSrcweir uno::RuntimeException )
393cdf0e10cSrcweir {
394cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
395cdf0e10cSrcweir
396cdf0e10cSrcweir if ( m_bDisposed )
397cdf0e10cSrcweir throw lang::DisposedException();
398cdf0e10cSrcweir
399cdf0e10cSrcweir if ( !m_xStream.is() || !m_xInputStream.is() )
400cdf0e10cSrcweir throw uno::RuntimeException();
401cdf0e10cSrcweir
402cdf0e10cSrcweir return m_xInputStream->readSomeBytes( aData, nMaxBytesToRead );
403cdf0e10cSrcweir }
404cdf0e10cSrcweir
405cdf0e10cSrcweir //-----------------------------------------------
skipBytes(sal_Int32 nBytesToSkip)406cdf0e10cSrcweir void SAL_CALL OFSStreamContainer::skipBytes( sal_Int32 nBytesToSkip )
407cdf0e10cSrcweir throw( io::NotConnectedException,
408cdf0e10cSrcweir io::BufferSizeExceededException,
409cdf0e10cSrcweir io::IOException,
410cdf0e10cSrcweir uno::RuntimeException )
411cdf0e10cSrcweir {
412cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
413cdf0e10cSrcweir
414cdf0e10cSrcweir if ( m_bDisposed )
415cdf0e10cSrcweir throw lang::DisposedException();
416cdf0e10cSrcweir
417cdf0e10cSrcweir if ( !m_xStream.is() || !m_xInputStream.is() )
418cdf0e10cSrcweir throw uno::RuntimeException();
419cdf0e10cSrcweir
420cdf0e10cSrcweir m_xInputStream->skipBytes( nBytesToSkip );
421cdf0e10cSrcweir }
422cdf0e10cSrcweir
423cdf0e10cSrcweir //-----------------------------------------------
available()424cdf0e10cSrcweir sal_Int32 SAL_CALL OFSStreamContainer::available()
425cdf0e10cSrcweir throw( io::NotConnectedException,
426cdf0e10cSrcweir io::IOException,
427cdf0e10cSrcweir uno::RuntimeException )
428cdf0e10cSrcweir {
429cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
430cdf0e10cSrcweir
431cdf0e10cSrcweir if ( m_bDisposed )
432cdf0e10cSrcweir throw lang::DisposedException();
433cdf0e10cSrcweir
434cdf0e10cSrcweir if ( !m_xStream.is() || !m_xInputStream.is() )
435cdf0e10cSrcweir throw uno::RuntimeException();
436cdf0e10cSrcweir
437cdf0e10cSrcweir return m_xInputStream->available();
438cdf0e10cSrcweir }
439cdf0e10cSrcweir
440cdf0e10cSrcweir //-----------------------------------------------
closeInput()441cdf0e10cSrcweir void SAL_CALL OFSStreamContainer::closeInput()
442cdf0e10cSrcweir throw( io::NotConnectedException,
443cdf0e10cSrcweir io::IOException,
444cdf0e10cSrcweir uno::RuntimeException )
445cdf0e10cSrcweir {
446cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
447cdf0e10cSrcweir
448cdf0e10cSrcweir if ( m_bDisposed )
449cdf0e10cSrcweir throw lang::DisposedException();
450cdf0e10cSrcweir
451cdf0e10cSrcweir if ( !m_xStream.is() || !m_xInputStream.is() )
452cdf0e10cSrcweir throw uno::RuntimeException();
453cdf0e10cSrcweir
454cdf0e10cSrcweir if ( m_xInputStream.is() )
455cdf0e10cSrcweir {
456cdf0e10cSrcweir m_xInputStream->closeInput();
457cdf0e10cSrcweir m_bInputClosed = sal_True;
458cdf0e10cSrcweir }
459cdf0e10cSrcweir
460cdf0e10cSrcweir if ( m_bOutputClosed )
461cdf0e10cSrcweir dispose();
462cdf0e10cSrcweir }
463cdf0e10cSrcweir
464cdf0e10cSrcweir // XOutputStream
465cdf0e10cSrcweir //-----------------------------------------------
writeBytes(const uno::Sequence<sal_Int8> & aData)466cdf0e10cSrcweir void SAL_CALL OFSStreamContainer::writeBytes( const uno::Sequence< sal_Int8 >& aData )
467cdf0e10cSrcweir throw ( io::NotConnectedException,
468cdf0e10cSrcweir io::BufferSizeExceededException,
469cdf0e10cSrcweir io::IOException,
470cdf0e10cSrcweir uno::RuntimeException )
471cdf0e10cSrcweir {
472cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
473cdf0e10cSrcweir
474cdf0e10cSrcweir if ( m_bDisposed )
475cdf0e10cSrcweir throw lang::DisposedException();
476cdf0e10cSrcweir
477cdf0e10cSrcweir if ( !m_xStream.is() || !m_xOutputStream.is() )
478cdf0e10cSrcweir throw uno::RuntimeException();
479cdf0e10cSrcweir
480cdf0e10cSrcweir return m_xOutputStream->writeBytes( aData );
481cdf0e10cSrcweir }
482cdf0e10cSrcweir
483cdf0e10cSrcweir //-----------------------------------------------
flush()484cdf0e10cSrcweir void SAL_CALL OFSStreamContainer::flush()
485cdf0e10cSrcweir throw ( io::NotConnectedException,
486cdf0e10cSrcweir io::BufferSizeExceededException,
487cdf0e10cSrcweir io::IOException,
488cdf0e10cSrcweir uno::RuntimeException )
489cdf0e10cSrcweir {
490cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
491cdf0e10cSrcweir
492cdf0e10cSrcweir if ( m_bDisposed )
493cdf0e10cSrcweir throw lang::DisposedException();
494cdf0e10cSrcweir
495cdf0e10cSrcweir if ( !m_xStream.is() || !m_xOutputStream.is() )
496cdf0e10cSrcweir throw uno::RuntimeException();
497cdf0e10cSrcweir
498cdf0e10cSrcweir return m_xOutputStream->flush();
499cdf0e10cSrcweir }
500cdf0e10cSrcweir
501cdf0e10cSrcweir //-----------------------------------------------
closeOutput()502cdf0e10cSrcweir void SAL_CALL OFSStreamContainer::closeOutput()
503cdf0e10cSrcweir throw ( io::NotConnectedException,
504cdf0e10cSrcweir io::BufferSizeExceededException,
505cdf0e10cSrcweir io::IOException,
506cdf0e10cSrcweir uno::RuntimeException )
507cdf0e10cSrcweir {
508cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
509cdf0e10cSrcweir
510cdf0e10cSrcweir if ( m_bDisposed )
511cdf0e10cSrcweir throw lang::DisposedException();
512cdf0e10cSrcweir
513cdf0e10cSrcweir if ( !m_xStream.is() || !m_xOutputStream.is() )
514cdf0e10cSrcweir throw uno::RuntimeException();
515cdf0e10cSrcweir
516cdf0e10cSrcweir if ( m_xOutputStream.is() )
517cdf0e10cSrcweir {
518cdf0e10cSrcweir m_xOutputStream->closeOutput();
519cdf0e10cSrcweir m_bOutputClosed = sal_True;
520cdf0e10cSrcweir }
521cdf0e10cSrcweir
522cdf0e10cSrcweir if ( m_bInputClosed )
523cdf0e10cSrcweir dispose();
524cdf0e10cSrcweir }
525cdf0e10cSrcweir
526cdf0e10cSrcweir
527cdf0e10cSrcweir // XTruncate
528cdf0e10cSrcweir //-----------------------------------------------
truncate()529cdf0e10cSrcweir void SAL_CALL OFSStreamContainer::truncate()
530cdf0e10cSrcweir throw ( io::IOException,
531cdf0e10cSrcweir uno::RuntimeException )
532cdf0e10cSrcweir {
533cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
534cdf0e10cSrcweir
535cdf0e10cSrcweir if ( m_bDisposed )
536cdf0e10cSrcweir throw lang::DisposedException();
537cdf0e10cSrcweir
538cdf0e10cSrcweir if ( !m_xStream.is() || !m_xTruncate.is() )
539cdf0e10cSrcweir throw uno::RuntimeException();
540cdf0e10cSrcweir
541cdf0e10cSrcweir m_xTruncate->truncate();
542cdf0e10cSrcweir }
543cdf0e10cSrcweir
544cdf0e10cSrcweir
545cdf0e10cSrcweir // XAsyncOutputMonitor
546cdf0e10cSrcweir //-----------------------------------------------
waitForCompletion()547cdf0e10cSrcweir void SAL_CALL OFSStreamContainer::waitForCompletion()
548cdf0e10cSrcweir throw ( io::IOException,
549cdf0e10cSrcweir uno::RuntimeException )
550cdf0e10cSrcweir {
551cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
552cdf0e10cSrcweir
553cdf0e10cSrcweir if ( m_bDisposed )
554cdf0e10cSrcweir throw lang::DisposedException();
555cdf0e10cSrcweir
556cdf0e10cSrcweir if ( !m_xStream.is() || !m_xAsyncOutputMonitor.is() )
557cdf0e10cSrcweir throw uno::RuntimeException();
558cdf0e10cSrcweir
559cdf0e10cSrcweir m_xAsyncOutputMonitor->waitForCompletion();
560cdf0e10cSrcweir }
561cdf0e10cSrcweir
562cdf0e10cSrcweir
563cdf0e10cSrcweir
564