1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: filinpstr.cxx,v $
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"
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
),
52 m_nErrorCode( TASKHANDLER_NO_ERROR
),
53 m_nMinorErrorCode( TASKHANDLER_NO_ERROR
)
55 sal_uInt32 nFlags
= OpenFlag_Read
;
57 nFlags
|= OpenFlag_NoLock
;
59 osl::FileBase::RC err
= m_aFile
.open( nFlags
);
60 if( err
!= osl::FileBase::E_None
)
65 m_nErrorCode
= TASKHANDLING_OPEN_FOR_INPUTSTREAM
;
66 m_nMinorErrorCode
= err
;
73 XInputStream_impl::~XInputStream_impl()
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()
97 sal_Int32 SAL_CALL
XInputStream_impl::getMinorError()
99 return m_nMinorErrorCode
;
103 //////////////////////////////////////////////////////////////////////////////////////////
105 //////////////////////////////////////////////////////////////////////////////////////////
108 XTYPEPROVIDER_IMPL_3( XInputStream_impl
,
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
);
129 XInputStream_impl::acquire(
133 OWeakObject::acquire();
138 XInputStream_impl::release(
142 OWeakObject::release();
148 XInputStream_impl::readBytes(
149 uno::Sequence
< sal_Int8
>& aData
,
150 sal_Int32 nBytesToRead
)
151 throw( io::NotConnectedException
,
152 io::BufferSizeExceededException
,
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
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
;
176 XInputStream_impl::readSomeBytes(
177 uno::Sequence
< sal_Int8
>& aData
,
178 sal_Int32 nMaxBytesToRead
)
179 throw( io::NotConnectedException
,
180 io::BufferSizeExceededException
,
182 uno::RuntimeException
)
184 return readBytes( aData
,nMaxBytesToRead
);
189 XInputStream_impl::skipBytes(
190 sal_Int32 nBytesToSkip
)
191 throw( io::NotConnectedException
,
192 io::BufferSizeExceededException
,
194 uno::RuntimeException
)
196 m_aFile
.setPos( osl_Pos_Current
, sal_uInt64( nBytesToSkip
) );
201 XInputStream_impl::available(
203 throw( io::NotConnectedException
,
205 uno::RuntimeException
)
212 XInputStream_impl::closeInput(
214 throw( io::NotConnectedException
,
216 uno::RuntimeException
)
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
>() );
229 XInputStream_impl::seek(
231 throw( lang::IllegalArgumentException
,
233 uno::RuntimeException
)
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
>() );
243 XInputStream_impl::getPosition(
245 throw( io::IOException
,
246 uno::RuntimeException
)
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
);
255 XInputStream_impl::getLength(
257 throw( io::IOException
,
258 uno::RuntimeException
)
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
>() );
264 return sal_Int64( uEndPos
);