Branch libreoffice-5-0-4
[LibreOffice.git] / ucbhelper / source / provider / std_outputstream.cxx
blob390ddbe4b408a7cb837d95da2f7360933a5f4eae
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include <sal/config.h>
12 #include <sal/log.hxx>
14 #include "ucbhelper/std_outputstream.hxx"
16 using namespace std;
17 using namespace com::sun::star;
19 namespace ucbhelper
21 StdOutputStream::StdOutputStream( boost::shared_ptr< ostream > pStream ) :
22 m_pStream( pStream )
26 StdOutputStream::~StdOutputStream()
28 if ( m_pStream.get( ) )
29 m_pStream->setstate( ios::eofbit );
32 uno::Any SAL_CALL StdOutputStream::queryInterface( const uno::Type& rType ) throw ( uno::RuntimeException, std::exception )
34 uno::Any aRet = ::cppu::queryInterface( rType, ( static_cast< XOutputStream* >( this ) ) );
36 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
39 void SAL_CALL StdOutputStream::acquire( ) throw( )
41 OWeakObject::acquire();
44 void SAL_CALL StdOutputStream::release( ) throw( )
46 OWeakObject::release();
49 void SAL_CALL StdOutputStream::writeBytes ( const uno::Sequence< sal_Int8 >& aData )
50 throw ( io::NotConnectedException, io::BufferSizeExceededException,
51 io::IOException, uno::RuntimeException, std::exception )
53 osl::MutexGuard aGuard( m_aMutex );
55 if ( !m_pStream.get() )
56 throw io::IOException( );
58 try
60 m_pStream->write( reinterpret_cast< const char* >( aData.getConstArray( ) ), aData.getLength( ) );
62 catch ( const ios_base::failure& e )
64 SAL_INFO( "ucbhelper", "Exception caught when calling write: " << e.what() );
65 throw io::IOException( );
69 void SAL_CALL StdOutputStream::flush ( )
70 throw ( io::NotConnectedException, io::BufferSizeExceededException,
71 io::IOException, uno::RuntimeException, std::exception )
73 osl::MutexGuard aGuard( m_aMutex );
75 if ( !m_pStream.get() )
76 throw io::IOException( );
78 try
80 m_pStream->flush( );
82 catch ( const ios_base::failure& e )
84 SAL_INFO( "ucbhelper", "Exception caught when calling flush: " << e.what() );
85 throw io::IOException( );
89 void SAL_CALL StdOutputStream::closeOutput ( )
90 throw ( io::NotConnectedException, io::BufferSizeExceededException,
91 io::IOException, uno::RuntimeException, std::exception )
93 osl::MutexGuard aGuard( m_aMutex );
95 if ( !m_pStream.get() )
96 throw io::IOException( );
98 m_pStream->setstate( ios_base::eofbit );
102 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */