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