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