Bump for 3.6-28
[LibreOffice.git] / ucb / source / ucp / file / filinpstr.cxx
blob289450b523b3690d3622656f83ef3b3bec7a52c5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "filinpstr.hxx"
30 #include "filerror.hxx"
31 #include "shell.hxx"
32 #include "prov.hxx"
35 using namespace fileaccess;
36 using namespace com::sun::star;
37 using namespace com::sun::star::ucb;
41 XInputStream_impl::XInputStream_impl( shell* pMyShell,const rtl::OUString& aUncPath, sal_Bool bLock )
42 : m_pMyShell( pMyShell ),
43 m_xProvider( pMyShell->m_pProvider ),
44 m_bLock( bLock ),
45 m_aFile( aUncPath ),
46 m_nErrorCode( TASKHANDLER_NO_ERROR ),
47 m_nMinorErrorCode( TASKHANDLER_NO_ERROR )
49 sal_uInt32 nFlags = osl_File_OpenFlag_Read;
50 if ( !bLock )
51 nFlags |= osl_File_OpenFlag_NoLock;
53 osl::FileBase::RC err = m_aFile.open( nFlags );
54 if( err != osl::FileBase::E_None )
56 m_nIsOpen = false;
57 m_aFile.close();
59 m_nErrorCode = TASKHANDLING_OPEN_FOR_INPUTSTREAM;
60 m_nMinorErrorCode = err;
62 else
63 m_nIsOpen = true;
67 XInputStream_impl::~XInputStream_impl()
69 try
71 closeInput();
73 catch (io::IOException const &)
75 OSL_FAIL("unexpected situation");
77 catch (uno::RuntimeException const &)
79 OSL_FAIL("unexpected situation");
84 sal_Int32 SAL_CALL XInputStream_impl::CtorSuccess()
86 return m_nErrorCode;
91 sal_Int32 SAL_CALL XInputStream_impl::getMinorError()
93 return m_nMinorErrorCode;
97 //////////////////////////////////////////////////////////////////////////////////////////
98 // XTypeProvider
99 //////////////////////////////////////////////////////////////////////////////////////////
102 XTYPEPROVIDER_IMPL_3( XInputStream_impl,
103 lang::XTypeProvider,
104 io::XSeekable,
105 io::XInputStream )
109 uno::Any SAL_CALL
110 XInputStream_impl::queryInterface(
111 const uno::Type& rType )
112 throw( uno::RuntimeException)
114 uno::Any aRet = cppu::queryInterface( rType,
115 (static_cast< io::XInputStream* >(this)),
116 (static_cast< lang::XTypeProvider* >(this)),
117 (static_cast< io::XSeekable* >(this)) );
118 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
122 void SAL_CALL
123 XInputStream_impl::acquire(
124 void )
125 throw()
127 OWeakObject::acquire();
131 void SAL_CALL
132 XInputStream_impl::release(
133 void )
134 throw()
136 OWeakObject::release();
141 sal_Int32 SAL_CALL
142 XInputStream_impl::readBytes(
143 uno::Sequence< sal_Int8 >& aData,
144 sal_Int32 nBytesToRead )
145 throw( io::NotConnectedException,
146 io::BufferSizeExceededException,
147 io::IOException,
148 uno::RuntimeException)
150 if( ! m_nIsOpen ) throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
152 aData.realloc(nBytesToRead);
153 //TODO! translate memory exhaustion (if it were detectable...) into
154 // io::BufferSizeExceededException
156 sal_uInt64 nrc(0);
157 if(m_aFile.read( aData.getArray(),sal_uInt64(nBytesToRead),nrc )
158 != osl::FileBase::E_None)
159 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
161 // Shrink aData in case we read less than nBytesToRead (XInputStream
162 // documentation does not tell whether this is required, and I do not know
163 // if any code relies on this, so be conservative---SB):
164 if (sal::static_int_cast<sal_Int32>(nrc) != nBytesToRead)
165 aData.realloc(sal_Int32(nrc));
166 return ( sal_Int32 ) nrc;
169 sal_Int32 SAL_CALL
170 XInputStream_impl::readSomeBytes(
171 uno::Sequence< sal_Int8 >& aData,
172 sal_Int32 nMaxBytesToRead )
173 throw( io::NotConnectedException,
174 io::BufferSizeExceededException,
175 io::IOException,
176 uno::RuntimeException)
178 return readBytes( aData,nMaxBytesToRead );
182 void SAL_CALL
183 XInputStream_impl::skipBytes(
184 sal_Int32 nBytesToSkip )
185 throw( io::NotConnectedException,
186 io::BufferSizeExceededException,
187 io::IOException,
188 uno::RuntimeException)
190 m_aFile.setPos( osl_Pos_Current, sal_uInt64( nBytesToSkip ) );
194 sal_Int32 SAL_CALL
195 XInputStream_impl::available(
196 void )
197 throw( io::NotConnectedException,
198 io::IOException,
199 uno::RuntimeException)
201 return 0;
205 void SAL_CALL
206 XInputStream_impl::closeInput(
207 void )
208 throw( io::NotConnectedException,
209 io::IOException,
210 uno::RuntimeException )
212 if( m_nIsOpen )
214 osl::FileBase::RC err = m_aFile.close();
215 if( err != osl::FileBase::E_None )
216 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
217 m_nIsOpen = false;
222 void SAL_CALL
223 XInputStream_impl::seek(
224 sal_Int64 location )
225 throw( lang::IllegalArgumentException,
226 io::IOException,
227 uno::RuntimeException )
229 if( location < 0 )
230 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 );
231 if( osl::FileBase::E_None != m_aFile.setPos( osl_Pos_Absolut, sal_uInt64( location ) ) )
232 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
236 sal_Int64 SAL_CALL
237 XInputStream_impl::getPosition(
238 void )
239 throw( io::IOException,
240 uno::RuntimeException )
242 sal_uInt64 uPos;
243 if( osl::FileBase::E_None != m_aFile.getPos( uPos ) )
244 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
245 return sal_Int64( uPos );
248 sal_Int64 SAL_CALL
249 XInputStream_impl::getLength(
250 void )
251 throw( io::IOException,
252 uno::RuntimeException )
254 sal_uInt64 uEndPos;
255 if ( m_aFile.getSize(uEndPos) != osl::FileBase::E_None )
256 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
257 else
258 return sal_Int64( uEndPos );
261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */