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