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 std;
19 using namespace com::sun::star;
20 
21 namespace cmis
22 {
23  StdOutputStream::StdOutputStream( boost::shared_ptr< ostream > const & pStream ) :
24  m_pStream( pStream )
25  {
26  }
27 
29  {
30  if (m_pStream)
31  m_pStream->setstate( 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( ) throw( )
42  {
43  OWeakObject::acquire();
44  }
45 
46  void SAL_CALL StdOutputStream::release( ) throw( )
47  {
48  OWeakObject::release();
49  }
50 
51  void SAL_CALL StdOutputStream::writeBytes ( const uno::Sequence< sal_Int8 >& aData )
52  {
53  osl::MutexGuard 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 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  osl::MutexGuard aGuard( m_aMutex );
72 
73  if (!m_pStream)
74  throw io::IOException( );
75 
76  try
77  {
78  m_pStream->flush( );
79  }
80  catch ( const 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  osl::MutexGuard aGuard( m_aMutex );
90 
91  if (!m_pStream)
92  throw io::IOException( );
93 
94  m_pStream->setstate( ios_base::eofbit );
95  }
96 }
97 
98 /* 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 acquire() override
virtual void SAL_CALL writeBytes(const css::uno::Sequence< sal_Int8 > &aData) override
virtual void SAL_CALL release() override
virtual ~StdOutputStream() override
boost::shared_ptr< std::ostream > m_pStream
#define SAL_INFO(area, stream)