1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include <rtl/memory.h> 29 #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp> 30 #include <ucbhelper/cancelcommandexecution.hxx> 31 #include <string.h> 32 33 #include "gio_outputstream.hxx" 34 #include "gio_content.hxx" 35 36 using namespace com::sun::star; 37 38 namespace gio 39 { 40 41 OutputStream::OutputStream(GFileOutputStream *pStream) : Seekable(G_SEEKABLE(pStream)), mpStream(pStream) 42 { 43 if (!mpStream) 44 throw io::NotConnectedException(); 45 } 46 47 OutputStream::~OutputStream( void ) 48 { 49 closeOutput(); 50 } 51 52 void SAL_CALL OutputStream::writeBytes( const com::sun::star::uno::Sequence< sal_Int8 >& rData ) 53 throw( io::NotConnectedException, io::BufferSizeExceededException, 54 io::IOException, uno::RuntimeException) 55 { 56 if (!mpStream) 57 throw io::NotConnectedException(); 58 59 GError *pError=NULL; 60 if (!g_output_stream_write_all(G_OUTPUT_STREAM(mpStream), rData.getConstArray(), rData.getLength(), NULL, NULL, &pError)) 61 convertToException(pError, static_cast< cppu::OWeakObject * >(this)); 62 } 63 64 void SAL_CALL OutputStream::flush( void ) 65 throw( io::NotConnectedException, io::BufferSizeExceededException, 66 io::IOException, uno::RuntimeException ) 67 { 68 if (!mpStream) 69 throw io::NotConnectedException(); 70 71 GError *pError=NULL; 72 if (!g_output_stream_flush(G_OUTPUT_STREAM(mpStream), NULL, &pError)) 73 convertToException(pError, static_cast< cppu::OWeakObject * >(this)); 74 } 75 76 void SAL_CALL OutputStream::closeOutput( void ) 77 throw( io::NotConnectedException, io::IOException, 78 uno::RuntimeException ) 79 { 80 if (mpStream) 81 g_output_stream_close(G_OUTPUT_STREAM(mpStream), NULL, NULL); 82 } 83 84 uno::Any OutputStream::queryInterface( const uno::Type &type ) throw( uno::RuntimeException ) 85 { 86 uno::Any aRet = ::cppu::queryInterface ( type, 87 static_cast< XOutputStream * >( this ) ); 88 89 return aRet.hasValue() ? aRet : Seekable::queryInterface( type ); 90 } 91 92 } 93