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 {
50 if (!mpStream)
51 throw io::NotConnectedException();
52
53 GError *pError=NULL;
54 if (!g_output_stream_write_all(G_OUTPUT_STREAM(mpStream), rData.getConstArray(), rData.getLength(), NULL, NULL, &pError))
55 convertToException(pError, static_cast< cppu::OWeakObject * >(this));
56 }
57
flush(void)58 void SAL_CALL OutputStream::flush( void )
59 {
60 if (!mpStream)
61 throw io::NotConnectedException();
62
63 GError *pError=NULL;
64 if (!g_output_stream_flush(G_OUTPUT_STREAM(mpStream), NULL, &pError))
65 convertToException(pError, static_cast< cppu::OWeakObject * >(this));
66 }
67
closeOutput(void)68 void SAL_CALL OutputStream::closeOutput( void )
69 {
70 if (mpStream)
71 g_output_stream_close(G_OUTPUT_STREAM(mpStream), NULL, NULL);
72 }
73
queryInterface(const uno::Type & type)74 uno::Any OutputStream::queryInterface( const uno::Type &type )
75 {
76 uno::Any aRet = ::cppu::queryInterface ( type,
77 static_cast< XOutputStream * >( this ) );
78
79 return aRet.hasValue() ? aRet : Seekable::queryInterface( type );
80 }
81
82 }
83