merge the formfield patch from ooo-build
[ooovba.git] / ucb / source / ucp / gio / gio_inputstream.cxx
blobb173b4724c63afceddac60d6be6419c70650a842
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: gio_inputstream.cxx,v $
10 * $Revision: 1.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <rtl/memory.h>
32 #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
33 #include <ucbhelper/cancelcommandexecution.hxx>
34 #include <string.h>
36 #include "gio_inputstream.hxx"
37 #include "gio_content.hxx"
39 using namespace com::sun::star;
41 namespace gio
44 InputStream::InputStream(GFileInputStream *pStream) : Seekable(G_SEEKABLE(pStream)), mpStream(pStream)
46 if (!mpStream)
47 throw io::NotConnectedException();
50 InputStream::~InputStream( void )
52 closeInput();
55 sal_Int32 SAL_CALL InputStream::available()
56 throw( io::NotConnectedException, io::IOException, uno::RuntimeException )
58 return 0;
61 void SAL_CALL InputStream::closeInput()
62 throw( io::NotConnectedException, io::IOException, uno::RuntimeException )
64 if (mpStream)
65 g_input_stream_close(G_INPUT_STREAM(mpStream), NULL, NULL);
68 void SAL_CALL InputStream::skipBytes( sal_Int32 nBytesToSkip )
69 throw( io::NotConnectedException, io::BufferSizeExceededException,
70 io::IOException, uno::RuntimeException )
72 if (!mpStream)
73 throw io::NotConnectedException();
75 if (!g_seekable_can_seek(G_SEEKABLE(mpStream)))
76 throw io::IOException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Seek unsupported")),
77 static_cast< cppu::OWeakObject * >(this));
79 GError *pError=NULL;
80 if (!g_seekable_seek(G_SEEKABLE(mpStream), nBytesToSkip, G_SEEK_CUR, NULL, &pError))
81 convertToException(pError, static_cast< cppu::OWeakObject * >(this));
84 sal_Int32 SAL_CALL InputStream::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead )
85 throw( io::NotConnectedException, io::BufferSizeExceededException,
86 io::IOException, uno::RuntimeException )
88 if (!mpStream)
89 throw io::NotConnectedException();
91 try
93 aData.realloc( nBytesToRead );
95 catch ( const uno::Exception &e )
97 throw io::BufferSizeExceededException();
100 gsize nBytesRead = 0;
101 GError *pError=NULL;
102 if (!g_input_stream_read_all(G_INPUT_STREAM(mpStream), aData.getArray(), nBytesToRead, &nBytesRead, NULL, &pError))
103 convertToException(pError, static_cast< cppu::OWeakObject * >(this));
104 aData.realloc(nBytesRead);
105 return nBytesRead;
108 sal_Int32 SAL_CALL InputStream::readSomeBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
109 throw( io::NotConnectedException, io::BufferSizeExceededException,
110 io::IOException, uno::RuntimeException )
112 return readBytes(aData, nMaxBytesToRead);
115 uno::Any InputStream::queryInterface( const uno::Type &type ) throw( uno::RuntimeException )
117 uno::Any aRet = ::cppu::queryInterface ( type,
118 static_cast< XInputStream * >( this ) );
120 return aRet.hasValue() ? aRet : Seekable::queryInterface( type );