LibreOffice Module ucb (master) 1
std_outputstream.cxx
Go to the documentation of this file.
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>
15#include <utility>
16
17#include "std_outputstream.hxx"
18
19using namespace com::sun::star;
20
21namespace cmis
22{
23 StdOutputStream::StdOutputStream( boost::shared_ptr< std::ostream > pStream ) :
24 m_pStream(std::move( pStream ))
25 {
26 }
27
29 {
30 if (m_pStream)
31 m_pStream->setstate( std::ios::eofbit );
32 }
33
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
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: */
virtual void SAL_CALL flush() override
virtual ~StdOutputStream() override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
virtual void SAL_CALL writeBytes(const css::uno::Sequence< sal_Int8 > &aData) override
StdOutputStream(boost::shared_ptr< std::ostream > pStream)
virtual void SAL_CALL closeOutput() override
boost::shared_ptr< std::ostream > m_pStream
virtual void SAL_CALL release() noexcept override
virtual void SAL_CALL acquire() noexcept override
GtkMediaStream * m_pStream
#define SAL_INFO(area, stream)
constexpr OUStringLiteral aData
bool hasValue()