1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include <rtl/memory.h>
25 #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
26 #include <ucbhelper/cancelcommandexecution.hxx>
27 #include <string.h>
28 
29 #include "gio_outputstream.hxx"
30 #include "gio_content.hxx"
31 
32 using namespace com::sun::star;
33 
34 namespace gio
35 {
36 
OutputStream(GFileOutputStream * pStream)37 OutputStream::OutputStream(GFileOutputStream *pStream) : Seekable(G_SEEKABLE(pStream)), mpStream(pStream)
38 {
39     if (!mpStream)
40         throw io::NotConnectedException();
41 }
42 
~OutputStream(void)43 OutputStream::~OutputStream( void )
44 {
45     closeOutput();
46 }
47 
writeBytes(const com::sun::star::uno::Sequence<sal_Int8> & rData)48 void SAL_CALL OutputStream::writeBytes( const com::sun::star::uno::Sequence< sal_Int8 >& rData )
49     throw( io::NotConnectedException, io::BufferSizeExceededException,
50            io::IOException, uno::RuntimeException)
51 {
52     if (!mpStream)
53         throw io::NotConnectedException();
54 
55     GError *pError=NULL;
56     if (!g_output_stream_write_all(G_OUTPUT_STREAM(mpStream), rData.getConstArray(), rData.getLength(), NULL, NULL, &pError))
57         convertToException(pError, static_cast< cppu::OWeakObject * >(this));
58 }
59 
flush(void)60 void SAL_CALL OutputStream::flush( void )
61     throw( io::NotConnectedException, io::BufferSizeExceededException,
62            io::IOException, uno::RuntimeException )
63 {
64     if (!mpStream)
65         throw io::NotConnectedException();
66 
67     GError *pError=NULL;
68     if (!g_output_stream_flush(G_OUTPUT_STREAM(mpStream), NULL, &pError))
69         convertToException(pError, static_cast< cppu::OWeakObject * >(this));
70 }
71 
closeOutput(void)72 void SAL_CALL OutputStream::closeOutput( void )
73     throw( io::NotConnectedException, io::IOException,
74            uno::RuntimeException )
75 {
76     if (mpStream)
77         g_output_stream_close(G_OUTPUT_STREAM(mpStream), NULL, NULL);
78 }
79 
queryInterface(const uno::Type & type)80 uno::Any OutputStream::queryInterface( const uno::Type &type ) throw( uno::RuntimeException )
81 {
82     uno::Any aRet = ::cppu::queryInterface ( type,
83         static_cast< XOutputStream * >( this ) );
84 
85     return aRet.hasValue() ? aRet : Seekable::queryInterface( type );
86 }
87 
88 }
89