LibreOffice Module ucb (master)  1
gio_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  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <sal/config.h>
21 
22 #include <com/sun/star/io/NotConnectedException.hpp>
24 
25 #include "gio_outputstream.hxx"
26 #include "gio_content.hxx"
27 
28 namespace gio
29 {
30 
31 OutputStream::OutputStream(GFileOutputStream *pStream) : Seekable(G_SEEKABLE(pStream)), mpStream(pStream)
32 {
33  if (!mpStream)
34  throw css::io::NotConnectedException();
35 }
36 
38 {
39  closeOutput();
40 }
41 
42 void SAL_CALL OutputStream::writeBytes( const css::uno::Sequence< sal_Int8 >& rData )
43 {
44  if (!mpStream)
45  throw css::io::NotConnectedException();
46 
47  GError *pError=nullptr;
48  if (!g_output_stream_write_all(G_OUTPUT_STREAM(mpStream), rData.getConstArray(), rData.getLength(), nullptr, nullptr, &pError))
49  convertToIOException(pError, static_cast< cppu::OWeakObject * >(this));
50 }
51 
52 void SAL_CALL OutputStream::flush()
53 {
54  if (!mpStream)
55  throw css::io::NotConnectedException();
56 
57  GError *pError=nullptr;
58  if (!g_output_stream_flush(G_OUTPUT_STREAM(mpStream), nullptr, &pError))
59  convertToIOException(pError, static_cast< cppu::OWeakObject * >(this));
60 }
61 
63 {
64  if (mpStream)
65  g_output_stream_close(G_OUTPUT_STREAM(mpStream), nullptr, nullptr);
66 }
67 
68 css::uno::Any OutputStream::queryInterface( const css::uno::Type &type )
69 {
70  css::uno::Any aRet = ::cppu::queryInterface ( type,
71  static_cast< XOutputStream * >( this ) );
72 
73  return aRet.hasValue() ? aRet : Seekable::queryInterface( type );
74 }
75 
76 }
77 
78 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL closeOutput() override
virtual void SAL_CALL writeBytes(const css::uno::Sequence< sal_Int8 > &aData) override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &type) override
void convertToIOException(GError *pError, const css::uno::Reference< css::uno::XInterface > &rContext)
virtual void SAL_CALL flush() override
OutputStream(GFileOutputStream *pStream)
virtual ~OutputStream() override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &type) override
GFileOutputStream *const mpStream