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 :
10 : #include <sal/config.h>
11 :
12 : #include <sal/log.hxx>
13 :
14 : #include "ucbhelper/std_outputstream.hxx"
15 :
16 : using namespace std;
17 : using namespace com::sun::star;
18 :
19 : namespace ucbhelper
20 : {
21 0 : StdOutputStream::StdOutputStream( boost::shared_ptr< ostream > pStream ) :
22 0 : m_pStream( pStream )
23 : {
24 0 : }
25 :
26 0 : StdOutputStream::~StdOutputStream()
27 : {
28 0 : if ( m_pStream.get( ) )
29 0 : m_pStream->setstate( ios::eofbit );
30 0 : }
31 :
32 0 : uno::Any SAL_CALL StdOutputStream::queryInterface( const uno::Type& rType ) throw ( uno::RuntimeException, std::exception )
33 : {
34 0 : uno::Any aRet = ::cppu::queryInterface( rType, ( static_cast< XOutputStream* >( this ) ) );
35 :
36 0 : return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
37 : }
38 :
39 0 : void SAL_CALL StdOutputStream::acquire( ) throw( )
40 : {
41 0 : OWeakObject::acquire();
42 0 : }
43 :
44 0 : void SAL_CALL StdOutputStream::release( ) throw( )
45 : {
46 0 : OWeakObject::release();
47 0 : }
48 :
49 0 : void SAL_CALL StdOutputStream::writeBytes ( const uno::Sequence< sal_Int8 >& aData )
50 : throw ( io::NotConnectedException, io::BufferSizeExceededException,
51 : io::IOException, uno::RuntimeException, std::exception )
52 : {
53 0 : osl::MutexGuard aGuard( m_aMutex );
54 :
55 0 : if ( !m_pStream.get() )
56 0 : throw io::IOException( );
57 :
58 : try
59 : {
60 0 : m_pStream->write( reinterpret_cast< const char* >( aData.getConstArray( ) ), aData.getLength( ) );
61 : }
62 0 : catch ( const ios_base::failure& e )
63 : {
64 : SAL_INFO( "ucbhelper", "Exception caught when calling write: " << e.what() );
65 0 : throw io::IOException( );
66 0 : }
67 0 : }
68 :
69 0 : void SAL_CALL StdOutputStream::flush ( )
70 : throw ( io::NotConnectedException, io::BufferSizeExceededException,
71 : io::IOException, uno::RuntimeException, std::exception )
72 : {
73 0 : osl::MutexGuard aGuard( m_aMutex );
74 :
75 0 : if ( !m_pStream.get() )
76 0 : throw io::IOException( );
77 :
78 : try
79 : {
80 0 : m_pStream->flush( );
81 : }
82 0 : catch ( const ios_base::failure& e )
83 : {
84 : SAL_INFO( "ucbhelper", "Exception caught when calling flush: " << e.what() );
85 0 : throw io::IOException( );
86 0 : }
87 0 : }
88 :
89 0 : void SAL_CALL StdOutputStream::closeOutput ( )
90 : throw ( io::NotConnectedException, io::BufferSizeExceededException,
91 : io::IOException, uno::RuntimeException, std::exception )
92 : {
93 0 : osl::MutexGuard aGuard( m_aMutex );
94 :
95 0 : if ( !m_pStream.get() )
96 0 : throw io::IOException( );
97 :
98 0 : m_pStream->setstate( ios_base::eofbit );
99 0 : }
100 : }
101 :
102 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|