merge the formfield patch from ooo-build
[ooovba.git] / ucb / source / ucp / file / filinpstr.cxx
bloba8cd3d8544100ada9eb09567cc034fe0ad165743
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: filinpstr.cxx,v $
10 * $Revision: 1.13 $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_ucb.hxx"
33 #include "filinpstr.hxx"
34 #ifndef _FILERROR_HXX_
35 #include "filerror.hxx"
36 #endif
37 #include "shell.hxx"
38 #include "prov.hxx"
41 using namespace fileaccess;
42 using namespace com::sun::star;
43 using namespace com::sun::star::ucb;
47 XInputStream_impl::XInputStream_impl( shell* pMyShell,const rtl::OUString& aUncPath, sal_Bool bLock )
48 : m_pMyShell( pMyShell ),
49 m_xProvider( pMyShell->m_pProvider ),
50 m_bLock( bLock ),
51 m_aFile( aUncPath ),
52 m_nErrorCode( TASKHANDLER_NO_ERROR ),
53 m_nMinorErrorCode( TASKHANDLER_NO_ERROR )
55 sal_uInt32 nFlags = OpenFlag_Read;
56 if ( !bLock )
57 nFlags |= OpenFlag_NoLock;
59 osl::FileBase::RC err = m_aFile.open( nFlags );
60 if( err != osl::FileBase::E_None )
62 m_nIsOpen = false;
63 m_aFile.close();
65 m_nErrorCode = TASKHANDLING_OPEN_FOR_INPUTSTREAM;
66 m_nMinorErrorCode = err;
68 else
69 m_nIsOpen = true;
73 XInputStream_impl::~XInputStream_impl()
75 try
77 closeInput();
79 catch (io::IOException const &)
81 OSL_ENSURE(false, "unexpected situation");
83 catch (uno::RuntimeException const &)
85 OSL_ENSURE(false, "unexpected situation");
90 sal_Int32 SAL_CALL XInputStream_impl::CtorSuccess()
92 return m_nErrorCode;
97 sal_Int32 SAL_CALL XInputStream_impl::getMinorError()
99 return m_nMinorErrorCode;
103 //////////////////////////////////////////////////////////////////////////////////////////
104 // XTypeProvider
105 //////////////////////////////////////////////////////////////////////////////////////////
108 XTYPEPROVIDER_IMPL_3( XInputStream_impl,
109 lang::XTypeProvider,
110 io::XSeekable,
111 io::XInputStream )
115 uno::Any SAL_CALL
116 XInputStream_impl::queryInterface(
117 const uno::Type& rType )
118 throw( uno::RuntimeException)
120 uno::Any aRet = cppu::queryInterface( rType,
121 SAL_STATIC_CAST( io::XInputStream*,this ),
122 SAL_STATIC_CAST( lang::XTypeProvider*,this ),
123 SAL_STATIC_CAST( io::XSeekable*,this ) );
124 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
128 void SAL_CALL
129 XInputStream_impl::acquire(
130 void )
131 throw()
133 OWeakObject::acquire();
137 void SAL_CALL
138 XInputStream_impl::release(
139 void )
140 throw()
142 OWeakObject::release();
147 sal_Int32 SAL_CALL
148 XInputStream_impl::readBytes(
149 uno::Sequence< sal_Int8 >& aData,
150 sal_Int32 nBytesToRead )
151 throw( io::NotConnectedException,
152 io::BufferSizeExceededException,
153 io::IOException,
154 uno::RuntimeException)
156 if( ! m_nIsOpen ) throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
158 aData.realloc(nBytesToRead);
159 //TODO! translate memory exhaustion (if it were detectable...) into
160 // io::BufferSizeExceededException
162 sal_uInt64 nrc(0);
163 if(m_aFile.read( aData.getArray(),sal_uInt64(nBytesToRead),nrc )
164 != osl::FileBase::E_None)
165 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
167 // Shrink aData in case we read less than nBytesToRead (XInputStream
168 // documentation does not tell whether this is required, and I do not know
169 // if any code relies on this, so be conservative---SB):
170 if (sal::static_int_cast<sal_Int32>(nrc) != nBytesToRead)
171 aData.realloc(sal_Int32(nrc));
172 return ( sal_Int32 ) nrc;
175 sal_Int32 SAL_CALL
176 XInputStream_impl::readSomeBytes(
177 uno::Sequence< sal_Int8 >& aData,
178 sal_Int32 nMaxBytesToRead )
179 throw( io::NotConnectedException,
180 io::BufferSizeExceededException,
181 io::IOException,
182 uno::RuntimeException)
184 return readBytes( aData,nMaxBytesToRead );
188 void SAL_CALL
189 XInputStream_impl::skipBytes(
190 sal_Int32 nBytesToSkip )
191 throw( io::NotConnectedException,
192 io::BufferSizeExceededException,
193 io::IOException,
194 uno::RuntimeException)
196 m_aFile.setPos( osl_Pos_Current, sal_uInt64( nBytesToSkip ) );
200 sal_Int32 SAL_CALL
201 XInputStream_impl::available(
202 void )
203 throw( io::NotConnectedException,
204 io::IOException,
205 uno::RuntimeException)
207 return 0;
211 void SAL_CALL
212 XInputStream_impl::closeInput(
213 void )
214 throw( io::NotConnectedException,
215 io::IOException,
216 uno::RuntimeException )
218 if( m_nIsOpen )
220 osl::FileBase::RC err = m_aFile.close();
221 if( err != osl::FileBase::E_None )
222 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
223 m_nIsOpen = false;
228 void SAL_CALL
229 XInputStream_impl::seek(
230 sal_Int64 location )
231 throw( lang::IllegalArgumentException,
232 io::IOException,
233 uno::RuntimeException )
235 if( location < 0 )
236 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 );
237 if( osl::FileBase::E_None != m_aFile.setPos( Pos_Absolut, sal_uInt64( location ) ) )
238 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
242 sal_Int64 SAL_CALL
243 XInputStream_impl::getPosition(
244 void )
245 throw( io::IOException,
246 uno::RuntimeException )
248 sal_uInt64 uPos;
249 if( osl::FileBase::E_None != m_aFile.getPos( uPos ) )
250 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
251 return sal_Int64( uPos );
254 sal_Int64 SAL_CALL
255 XInputStream_impl::getLength(
256 void )
257 throw( io::IOException,
258 uno::RuntimeException )
260 sal_uInt64 uEndPos;
261 if ( m_aFile.getSize(uEndPos) != osl::FileBase::E_None )
262 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
263 else
264 return sal_Int64( uEndPos );