Line data Source code
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 <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
21 : #include <ucbhelper/cancelcommandexecution.hxx>
22 : #include <string.h>
23 :
24 : #include "gio_outputstream.hxx"
25 : #include "gio_content.hxx"
26 :
27 : using namespace com::sun::star;
28 :
29 : namespace gio
30 : {
31 :
32 0 : OutputStream::OutputStream(GFileOutputStream *pStream) : Seekable(G_SEEKABLE(pStream)), mpStream(pStream)
33 : {
34 0 : if (!mpStream)
35 0 : throw io::NotConnectedException();
36 0 : }
37 :
38 0 : OutputStream::~OutputStream( void )
39 : {
40 0 : closeOutput();
41 0 : }
42 :
43 0 : void SAL_CALL OutputStream::writeBytes( const com::sun::star::uno::Sequence< sal_Int8 >& rData )
44 : throw( io::NotConnectedException, io::BufferSizeExceededException,
45 : io::IOException, uno::RuntimeException, std::exception)
46 : {
47 0 : if (!mpStream)
48 0 : throw io::NotConnectedException();
49 :
50 0 : GError *pError=NULL;
51 0 : if (!g_output_stream_write_all(G_OUTPUT_STREAM(mpStream), rData.getConstArray(), rData.getLength(), NULL, NULL, &pError))
52 0 : convertToIOException(pError, static_cast< cppu::OWeakObject * >(this));
53 0 : }
54 :
55 0 : void SAL_CALL OutputStream::flush( void )
56 : throw( io::NotConnectedException, io::BufferSizeExceededException,
57 : io::IOException, uno::RuntimeException, std::exception )
58 : {
59 0 : if (!mpStream)
60 0 : throw io::NotConnectedException();
61 :
62 0 : GError *pError=NULL;
63 0 : if (!g_output_stream_flush(G_OUTPUT_STREAM(mpStream), NULL, &pError))
64 0 : convertToIOException(pError, static_cast< cppu::OWeakObject * >(this));
65 0 : }
66 :
67 0 : void SAL_CALL OutputStream::closeOutput( void )
68 : throw( io::NotConnectedException, io::IOException,
69 : uno::RuntimeException, std::exception )
70 : {
71 0 : if (mpStream)
72 0 : g_output_stream_close(G_OUTPUT_STREAM(mpStream), NULL, NULL);
73 0 : }
74 :
75 0 : uno::Any OutputStream::queryInterface( const uno::Type &type ) throw( uno::RuntimeException, std::exception )
76 : {
77 : uno::Any aRet = ::cppu::queryInterface ( type,
78 0 : static_cast< XOutputStream * >( this ) );
79 :
80 0 : return aRet.hasValue() ? aRet : Seekable::queryInterface( type );
81 : }
82 :
83 : }
84 :
85 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|