Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #include <osl/diagnose.h>
21 : :
22 : : #include <comphelper/storagehelper.hxx>
23 : : #include <switchpersistencestream.hxx>
24 : :
25 : : using namespace ::com::sun::star;
26 : :
27 : : // ========================================================================
28 : 4755 : struct SPStreamData_Impl
29 : : {
30 : : uno::Reference< lang::XMultiServiceFactory > m_xFactory;
31 : :
32 : : sal_Bool m_bInStreamBased;
33 : :
34 : : // the streams below are not visible from outside so there is no need to remember position
35 : :
36 : : // original stream related members
37 : : uno::Reference< io::XStream > m_xOrigStream;
38 : : uno::Reference< io::XTruncate > m_xOrigTruncate;
39 : : uno::Reference< io::XSeekable > m_xOrigSeekable;
40 : : uno::Reference< io::XInputStream > m_xOrigInStream;
41 : : uno::Reference< io::XOutputStream > m_xOrigOutStream;
42 : :
43 : : sal_Bool m_bInOpen;
44 : : sal_Bool m_bOutOpen;
45 : :
46 : :
47 : 4871 : SPStreamData_Impl(
48 : : const uno::Reference< lang::XMultiServiceFactory >& xFactory,
49 : : sal_Bool bInStreamBased,
50 : : const uno::Reference< io::XStream >& xOrigStream,
51 : : const uno::Reference< io::XTruncate >& xOrigTruncate,
52 : : const uno::Reference< io::XSeekable >& xOrigSeekable,
53 : : const uno::Reference< io::XInputStream >& xOrigInStream,
54 : : const uno::Reference< io::XOutputStream >& xOrigOutStream,
55 : : sal_Bool bInOpen,
56 : : sal_Bool bOutOpen )
57 : : : m_xFactory( xFactory )
58 : : , m_bInStreamBased( bInStreamBased )
59 : : , m_xOrigStream( xOrigStream )
60 : : , m_xOrigTruncate( xOrigTruncate )
61 : : , m_xOrigSeekable( xOrigSeekable )
62 : : , m_xOrigInStream( xOrigInStream )
63 : : , m_xOrigOutStream( xOrigOutStream )
64 : : , m_bInOpen( bInOpen )
65 : 4871 : , m_bOutOpen( bOutOpen )
66 : : {
67 : 4871 : }
68 : : };
69 : :
70 : : // ========================================================================
71 : : // ------------------------------------------------------------------------
72 : 3390 : SwitchablePersistenceStream::SwitchablePersistenceStream(
73 : : const uno::Reference< lang::XMultiServiceFactory >& xFactory,
74 : : const uno::Reference< io::XStream >& xStream )
75 : : : m_xFactory( xFactory )
76 [ + - ]: 3390 : , m_pStreamData( NULL )
77 : : {
78 [ + - ]: 3390 : SwitchPersistenceTo( xStream );
79 : 3390 : }
80 : :
81 : : // ------------------------------------------------------------------------
82 : 1481 : SwitchablePersistenceStream::SwitchablePersistenceStream(
83 : : const uno::Reference< lang::XMultiServiceFactory >& xFactory,
84 : : const uno::Reference< io::XInputStream >& xInputStream )
85 : : : m_xFactory( xFactory )
86 [ + - ]: 1481 : , m_pStreamData( NULL )
87 : : {
88 [ + - ]: 1481 : SwitchPersistenceTo( xInputStream );
89 : 1481 : }
90 : :
91 : : // ------------------------------------------------------------------------
92 [ + - ]: 4755 : SwitchablePersistenceStream::~SwitchablePersistenceStream()
93 : : {
94 [ + - ]: 4755 : CloseAll_Impl();
95 [ - + ]: 9510 : }
96 : :
97 : : // ------------------------------------------------------------------------
98 : 3390 : void SwitchablePersistenceStream::SwitchPersistenceTo( const uno::Reference< io::XStream >& xStream )
99 : : {
100 [ + - ]: 3390 : uno::Reference< io::XTruncate > xNewTruncate( xStream, uno::UNO_QUERY_THROW );
101 [ + - ]: 3390 : uno::Reference< io::XSeekable > xNewSeekable( xStream, uno::UNO_QUERY_THROW );
102 [ + - ][ + - ]: 3390 : uno::Reference< io::XInputStream > xNewInStream = xStream->getInputStream();
103 [ + - ][ + - ]: 3390 : uno::Reference< io::XOutputStream > xNewOutStream = xStream->getOutputStream();
104 [ + - ][ - + ]: 3390 : if ( !xNewInStream.is() || !xNewOutStream.is() )
[ - + ]
105 [ # # ]: 0 : throw uno::RuntimeException();
106 : :
107 : 3390 : sal_Int64 nPos = 0;
108 : 3390 : sal_Bool bInOpen = sal_False;
109 : 3390 : sal_Bool bOutOpen = sal_False;
110 : :
111 [ - + ][ # # ]: 3390 : if ( m_pStreamData && m_pStreamData->m_xOrigSeekable.is() )
[ - + ]
112 : : {
113 : : // check that the length is the same
114 [ # # ][ # # ]: 0 : if ( m_pStreamData->m_xOrigSeekable->getLength() != xNewSeekable->getLength() )
[ # # ][ # # ]
[ # # ]
115 [ # # ]: 0 : throw uno::RuntimeException();
116 : :
117 : : // get the current position
118 [ # # ][ # # ]: 0 : nPos = m_pStreamData->m_xOrigSeekable->getPosition();
119 : 0 : bInOpen = m_pStreamData->m_bInOpen;
120 : 0 : bOutOpen = m_pStreamData->m_bOutOpen;
121 : : }
122 : :
123 [ + - ][ + - ]: 3390 : xNewSeekable->seek( nPos );
124 : :
125 [ + - ]: 3390 : CloseAll_Impl();
126 : :
127 : : m_pStreamData = new SPStreamData_Impl( m_xFactory, sal_False,
128 : : xStream, xNewTruncate, xNewSeekable, xNewInStream, xNewOutStream,
129 [ + - ][ + - ]: 3390 : bInOpen, bOutOpen );
130 : 3390 : }
131 : :
132 : : // ------------------------------------------------------------------------
133 : 1481 : void SwitchablePersistenceStream::SwitchPersistenceTo( const uno::Reference< io::XInputStream >& xInputStream )
134 : : {
135 : 1481 : uno::Reference< io::XStream > xNewStream;
136 : 1481 : uno::Reference< io::XTruncate > xNewTruncate;
137 [ + - ]: 1481 : uno::Reference< io::XSeekable > xNewSeekable( xInputStream, uno::UNO_QUERY_THROW );
138 : 1481 : uno::Reference< io::XOutputStream > xNewOutStream;
139 [ - + ]: 1481 : if ( !xInputStream.is() )
140 [ # # ]: 0 : throw uno::RuntimeException();
141 : :
142 : 1481 : sal_Int64 nPos = 0;
143 : 1481 : sal_Bool bInOpen = sal_False;
144 : 1481 : sal_Bool bOutOpen = sal_False;
145 : :
146 [ - + ][ # # ]: 1481 : if ( m_pStreamData && m_pStreamData->m_xOrigSeekable.is() )
[ - + ]
147 : : {
148 : : // check that the length is the same
149 [ # # ][ # # ]: 0 : if ( m_pStreamData->m_xOrigSeekable->getLength() != xNewSeekable->getLength() )
[ # # ][ # # ]
[ # # ]
150 [ # # ]: 0 : throw uno::RuntimeException();
151 : :
152 : : // get the current position
153 [ # # ][ # # ]: 0 : nPos = m_pStreamData->m_xOrigSeekable->getPosition();
154 : 0 : bInOpen = m_pStreamData->m_bInOpen;
155 : 0 : bOutOpen = m_pStreamData->m_bOutOpen;
156 : : }
157 : :
158 [ + - ][ + - ]: 1481 : xNewSeekable->seek( nPos );
159 : :
160 [ + - ]: 1481 : CloseAll_Impl();
161 : :
162 : : m_pStreamData = new SPStreamData_Impl( m_xFactory, sal_True,
163 : : xNewStream, xNewTruncate, xNewSeekable, xInputStream, xNewOutStream,
164 [ + - ][ + - ]: 1481 : bInOpen, bOutOpen );
165 : :
166 : 1481 : }
167 : :
168 : : // ------------------------------------------------------------------------
169 : 0 : void SwitchablePersistenceStream::CopyAndSwitchPersistenceTo( const uno::Reference< io::XStream >& xStream )
170 : : {
171 : 0 : uno::Reference< io::XStream > xTargetStream = xStream;
172 : 0 : uno::Reference< io::XSeekable > xTargetSeek;
173 : :
174 [ # # ]: 0 : if ( !xTargetStream.is() )
175 : : {
176 : : xTargetStream = uno::Reference < io::XStream >(
177 [ # # ]: 0 : m_xFactory->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.TempFile") ) ),
178 [ # # ][ # # ]: 0 : uno::UNO_QUERY_THROW );
[ # # ][ # # ]
179 : :
180 [ # # ][ # # ]: 0 : xTargetSeek = uno::Reference< io::XSeekable >( xTargetStream, uno::UNO_QUERY_THROW );
181 : : }
182 : : else
183 : : {
184 : : // the provided stream must be empty
185 [ # # ][ # # ]: 0 : xTargetSeek = uno::Reference< io::XSeekable >( xTargetStream, uno::UNO_QUERY_THROW );
186 [ # # ][ # # ]: 0 : if ( xTargetSeek->getLength() )
[ # # ]
187 [ # # ]: 0 : throw io::IOException();
188 : : }
189 : :
190 [ # # ]: 0 : uno::Reference< io::XTruncate > xTargetTruncate( xTargetStream, uno::UNO_QUERY_THROW );
191 [ # # ][ # # ]: 0 : uno::Reference< io::XInputStream > xTargetInStream = xTargetStream->getInputStream();
192 [ # # ][ # # ]: 0 : uno::Reference< io::XOutputStream > xTargetOutStream = xTargetStream->getOutputStream();
193 [ # # ][ # # ]: 0 : if ( !xTargetInStream.is() || !xTargetOutStream.is() )
[ # # ]
194 [ # # ]: 0 : throw uno::RuntimeException();
195 : :
196 [ # # ][ # # ]: 0 : if ( !m_pStreamData->m_xOrigInStream.is() || !m_pStreamData->m_xOrigSeekable.is() )
[ # # ]
197 [ # # ]: 0 : throw uno::RuntimeException();
198 : :
199 [ # # ][ # # ]: 0 : sal_Int64 nPos = m_pStreamData->m_xOrigSeekable->getPosition();
200 [ # # ][ # # ]: 0 : m_pStreamData->m_xOrigSeekable->seek( 0 );
201 [ # # ]: 0 : ::comphelper::OStorageHelper::CopyInputToOutput( m_pStreamData->m_xOrigInStream, xTargetOutStream );
202 [ # # ][ # # ]: 0 : xTargetOutStream->flush();
203 [ # # ][ # # ]: 0 : xTargetSeek->seek( nPos );
204 : :
205 : 0 : sal_Bool bInOpen = m_pStreamData->m_bInOpen;
206 : 0 : sal_Bool bOutOpen = m_pStreamData->m_bOutOpen;
207 : :
208 [ # # ]: 0 : CloseAll_Impl();
209 : :
210 : : m_pStreamData = new SPStreamData_Impl( m_xFactory, sal_False,
211 : : xTargetStream, xTargetTruncate, xTargetSeek, xTargetInStream, xTargetOutStream,
212 [ # # ][ # # ]: 0 : bInOpen, bOutOpen );
213 : 0 : }
214 : :
215 : : // ------------------------------------------------------------------------
216 : 9626 : void SwitchablePersistenceStream::CloseAll_Impl()
217 : : {
218 [ + + ]: 9626 : if ( m_pStreamData )
219 : : {
220 [ + - ]: 4755 : delete m_pStreamData;
221 : 4755 : m_pStreamData = NULL;
222 : : }
223 : 9626 : }
224 : :
225 : : // com::sun::star::io::XStream
226 : : // ------------------------------------------------------------------------
227 : 5890 : uno::Reference< io::XInputStream > SAL_CALL SwitchablePersistenceStream::getInputStream( )
228 : : throw (uno::RuntimeException)
229 : : {
230 [ + - ]: 5890 : ::osl::MutexGuard aGuard( m_aMutex );
231 : :
232 [ + - ]: 5890 : if ( m_pStreamData )
233 : 5890 : m_pStreamData->m_bInOpen = sal_True;
234 [ + - ][ + - ]: 5890 : return static_cast< io::XInputStream* >( this );
235 : : }
236 : :
237 : :
238 : : // ------------------------------------------------------------------------
239 : 338 : uno::Reference< io::XOutputStream > SAL_CALL SwitchablePersistenceStream::getOutputStream( )
240 : : throw (uno::RuntimeException)
241 : : {
242 [ + - ]: 338 : ::osl::MutexGuard aGuard( m_aMutex );
243 : :
244 [ + - ]: 338 : if ( m_pStreamData )
245 : 338 : m_pStreamData->m_bOutOpen = sal_True;
246 [ + - ][ + - ]: 338 : return static_cast< io::XOutputStream* >( this );
247 : : }
248 : :
249 : :
250 : :
251 : : // com::sun::star::io::XInputStream
252 : : // ------------------------------------------------------------------------
253 : 71386 : ::sal_Int32 SAL_CALL SwitchablePersistenceStream::readBytes( uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nBytesToRead )
254 : : throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException)
255 : : {
256 [ + - ]: 71386 : ::osl::MutexGuard aGuard( m_aMutex );
257 : :
258 [ - + ]: 71386 : if ( !m_pStreamData )
259 [ # # ]: 0 : throw io::NotConnectedException();
260 : :
261 : : // the original stream data should be provided
262 [ - + ]: 71386 : if ( !m_pStreamData->m_xOrigInStream.is() )
263 [ # # ]: 0 : throw uno::RuntimeException();
264 : :
265 [ + - ][ + - ]: 71386 : return m_pStreamData->m_xOrigInStream->readBytes( aData, nBytesToRead );
[ + - ]
266 : : }
267 : :
268 : :
269 : : // ------------------------------------------------------------------------
270 : 0 : ::sal_Int32 SAL_CALL SwitchablePersistenceStream::readSomeBytes( uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nMaxBytesToRead )
271 : : throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException)
272 : : {
273 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
274 : :
275 [ # # ]: 0 : if ( !m_pStreamData )
276 [ # # ]: 0 : throw io::NotConnectedException();
277 : :
278 : : // the original stream data should be provided
279 [ # # ]: 0 : if ( !m_pStreamData->m_xOrigInStream.is() )
280 [ # # ]: 0 : throw uno::RuntimeException();
281 : :
282 [ # # ][ # # ]: 0 : return m_pStreamData->m_xOrigInStream->readBytes( aData, nMaxBytesToRead );
[ # # ]
283 : : }
284 : :
285 : : // ------------------------------------------------------------------------
286 : 0 : void SAL_CALL SwitchablePersistenceStream::skipBytes( ::sal_Int32 nBytesToSkip )
287 : : throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException)
288 : : {
289 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
290 : :
291 [ # # ]: 0 : if ( !m_pStreamData )
292 [ # # ]: 0 : throw io::NotConnectedException();
293 : :
294 : : // the original stream data should be provided
295 [ # # ]: 0 : if ( !m_pStreamData->m_xOrigInStream.is() )
296 [ # # ]: 0 : throw uno::RuntimeException();
297 : :
298 [ # # ][ # # ]: 0 : m_pStreamData->m_xOrigInStream->skipBytes( nBytesToSkip );
[ # # ]
299 : 0 : }
300 : :
301 : :
302 : : // ------------------------------------------------------------------------
303 : 0 : ::sal_Int32 SAL_CALL SwitchablePersistenceStream::available( )
304 : : throw (io::NotConnectedException, io::IOException, uno::RuntimeException)
305 : : {
306 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
307 : :
308 [ # # ]: 0 : if ( !m_pStreamData )
309 [ # # ]: 0 : throw io::NotConnectedException();
310 : :
311 : : // the original stream data should be provided
312 [ # # ]: 0 : if ( !m_pStreamData->m_xOrigInStream.is() )
313 [ # # ]: 0 : throw uno::RuntimeException();
314 : :
315 [ # # ][ # # ]: 0 : return m_pStreamData->m_xOrigInStream->available();
[ # # ]
316 : : }
317 : :
318 : :
319 : : // ------------------------------------------------------------------------
320 : 0 : void SAL_CALL SwitchablePersistenceStream::closeInput()
321 : : throw (io::NotConnectedException, io::IOException, uno::RuntimeException)
322 : : {
323 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
324 : :
325 [ # # ]: 0 : if ( !m_pStreamData )
326 [ # # ]: 0 : throw io::NotConnectedException();
327 : :
328 : 0 : m_pStreamData->m_bInOpen = sal_False;
329 [ # # ]: 0 : if ( !m_pStreamData->m_bOutOpen )
330 [ # # ][ # # ]: 0 : CloseAll_Impl();
331 : 0 : }
332 : :
333 : :
334 : :
335 : : // com::sun::star::io::XOutputStream
336 : : // ------------------------------------------------------------------------
337 : 61590 : void SAL_CALL SwitchablePersistenceStream::writeBytes( const uno::Sequence< ::sal_Int8 >& aData )
338 : : throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException)
339 : : {
340 [ + - ]: 61590 : ::osl::MutexGuard aGuard( m_aMutex );
341 : :
342 [ - + ]: 61590 : if ( !m_pStreamData )
343 [ # # ]: 0 : throw io::NotConnectedException();
344 : :
345 [ - + ]: 61590 : if ( m_pStreamData->m_bInStreamBased )
346 [ # # ]: 0 : throw io::IOException();
347 : :
348 : : // the original stream data should be provided
349 [ - + ]: 61590 : if ( !m_pStreamData->m_xOrigOutStream.is() )
350 [ # # ]: 0 : throw uno::RuntimeException();
351 : :
352 [ + - ][ + - ]: 61590 : m_pStreamData->m_xOrigOutStream->writeBytes( aData );
[ + - ]
353 : 61590 : }
354 : :
355 : :
356 : : // ------------------------------------------------------------------------
357 : 628 : void SAL_CALL SwitchablePersistenceStream::flush( )
358 : : throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException)
359 : : {
360 [ + - ]: 628 : ::osl::MutexGuard aGuard( m_aMutex );
361 : :
362 [ + - ][ - + ]: 628 : if ( !m_pStreamData || m_pStreamData->m_bInStreamBased )
363 : : {
364 : : OSL_FAIL( "flush() is not acceptable!\n" );
365 : 628 : return;
366 : : // in future throw exception, for now some code might call flush() on closed stream
367 : : // since file ucp implementation allows it
368 : : // throw io::NotConnectedException();
369 : : }
370 : :
371 : : // the original stream data should be provided
372 [ - + ]: 628 : if ( !m_pStreamData->m_xOrigOutStream.is() )
373 [ # # ]: 0 : throw uno::RuntimeException();
374 : :
375 [ + - ][ + - ]: 628 : m_pStreamData->m_xOrigOutStream->flush();
[ + - ][ + - ]
376 : : }
377 : :
378 : :
379 : : // ------------------------------------------------------------------------
380 : 0 : void SAL_CALL SwitchablePersistenceStream::closeOutput( )
381 : : throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException)
382 : : {
383 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
384 : :
385 [ # # ]: 0 : if ( !m_pStreamData )
386 [ # # ]: 0 : throw io::NotConnectedException();
387 : :
388 : 0 : m_pStreamData->m_bOutOpen = sal_False;
389 [ # # ]: 0 : if ( !m_pStreamData->m_bInOpen )
390 [ # # ][ # # ]: 0 : CloseAll_Impl();
391 : 0 : }
392 : :
393 : :
394 : :
395 : : // com::sun::star::io::XTruncate
396 : : // ------------------------------------------------------------------------
397 : 48 : void SAL_CALL SwitchablePersistenceStream::truncate( )
398 : : throw (io::IOException, uno::RuntimeException)
399 : : {
400 [ + - ]: 48 : ::osl::MutexGuard aGuard( m_aMutex );
401 : :
402 [ - + ]: 48 : if ( !m_pStreamData )
403 [ # # ]: 0 : throw io::NotConnectedException();
404 : :
405 [ - + ]: 48 : if ( m_pStreamData->m_bInStreamBased )
406 [ # # ]: 0 : throw io::IOException();
407 : :
408 : : // the original stream data should be provided
409 [ - + ]: 48 : if ( !m_pStreamData->m_xOrigTruncate.is() )
410 [ # # ]: 0 : throw uno::RuntimeException();
411 : :
412 [ + - ][ + - ]: 48 : m_pStreamData->m_xOrigTruncate->truncate();
[ + - ]
413 : 48 : }
414 : :
415 : :
416 : : // com::sun::star::io::XSeekable
417 : : // ------------------------------------------------------------------------
418 : 15058 : void SAL_CALL SwitchablePersistenceStream::seek( ::sal_Int64 location )
419 : : throw (lang::IllegalArgumentException, io::IOException, uno::RuntimeException)
420 : : {
421 [ + - ]: 15058 : ::osl::MutexGuard aGuard( m_aMutex );
422 : :
423 [ - + ]: 15058 : if ( !m_pStreamData )
424 [ # # ]: 0 : throw io::NotConnectedException();
425 : :
426 : : // the original stream data should be provided
427 [ - + ]: 15058 : if ( !m_pStreamData->m_xOrigSeekable.is() )
428 [ # # ]: 0 : throw uno::RuntimeException();
429 : :
430 [ + - ][ + - ]: 15058 : m_pStreamData->m_xOrigSeekable->seek( location );
[ + - ]
431 : 15058 : }
432 : :
433 : :
434 : : // ------------------------------------------------------------------------
435 : 7840 : ::sal_Int64 SAL_CALL SwitchablePersistenceStream::getPosition( )
436 : : throw (io::IOException, uno::RuntimeException)
437 : : {
438 [ + - ]: 7840 : ::osl::MutexGuard aGuard( m_aMutex );
439 : :
440 [ - + ]: 7840 : if ( !m_pStreamData )
441 [ # # ]: 0 : throw io::NotConnectedException();
442 : :
443 : : // the original stream data should be provided
444 [ - + ]: 7840 : if ( !m_pStreamData->m_xOrigSeekable.is() )
445 [ # # ]: 0 : throw uno::RuntimeException();
446 : :
447 [ + - ][ + - ]: 7840 : return m_pStreamData->m_xOrigSeekable->getPosition();
[ + - ]
448 : : }
449 : :
450 : :
451 : : // ------------------------------------------------------------------------
452 : 15040 : ::sal_Int64 SAL_CALL SwitchablePersistenceStream::getLength( )
453 : : throw (io::IOException, uno::RuntimeException)
454 : : {
455 [ + - ]: 15040 : ::osl::MutexGuard aGuard( m_aMutex );
456 : :
457 [ - + ]: 15040 : if ( !m_pStreamData )
458 [ # # ]: 0 : throw io::NotConnectedException();
459 : :
460 : : // the original stream data should be provided
461 [ - + ]: 15040 : if ( !m_pStreamData->m_xOrigSeekable.is() )
462 [ # # ]: 0 : throw uno::RuntimeException();
463 : :
464 [ + - ][ + - ]: 15040 : return m_pStreamData->m_xOrigSeekable->getLength();
[ + - ]
465 : : }
466 : :
467 : : // ------------------------------------------------------------------------
468 : 338 : void SAL_CALL SwitchablePersistenceStream::waitForCompletion()
469 : : throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
470 : : {
471 [ - + ]: 338 : if ( !m_pStreamData )
472 [ # # ]: 0 : throw io::NotConnectedException();
473 : :
474 [ + - ]: 338 : uno::Reference< io::XAsyncOutputMonitor > asyncOutputMonitor( m_pStreamData->m_xOrigOutStream, uno::UNO_QUERY );
475 [ + + ]: 338 : if ( asyncOutputMonitor.is() )
476 [ + - ][ + - ]: 338 : asyncOutputMonitor->waitForCompletion();
477 : 338 : }
478 : :
479 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|