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"
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
),
46 m_nErrorCode( TASKHANDLER_NO_ERROR
),
47 m_nMinorErrorCode( TASKHANDLER_NO_ERROR
)
49 sal_uInt32 nFlags
= osl_File_OpenFlag_Read
;
51 nFlags
|= osl_File_OpenFlag_NoLock
;
53 osl::FileBase::RC err
= m_aFile
.open( nFlags
);
54 if( err
!= osl::FileBase::E_None
)
59 m_nErrorCode
= TASKHANDLING_OPEN_FOR_INPUTSTREAM
;
60 m_nMinorErrorCode
= err
;
67 XInputStream_impl::~XInputStream_impl()
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()
91 sal_Int32 SAL_CALL
XInputStream_impl::getMinorError()
93 return m_nMinorErrorCode
;
97 //////////////////////////////////////////////////////////////////////////////////////////
99 //////////////////////////////////////////////////////////////////////////////////////////
102 XTYPEPROVIDER_IMPL_3( XInputStream_impl
,
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
);
123 XInputStream_impl::acquire(
127 OWeakObject::acquire();
132 XInputStream_impl::release(
136 OWeakObject::release();
142 XInputStream_impl::readBytes(
143 uno::Sequence
< sal_Int8
>& aData
,
144 sal_Int32 nBytesToRead
)
145 throw( io::NotConnectedException
,
146 io::BufferSizeExceededException
,
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
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
;
170 XInputStream_impl::readSomeBytes(
171 uno::Sequence
< sal_Int8
>& aData
,
172 sal_Int32 nMaxBytesToRead
)
173 throw( io::NotConnectedException
,
174 io::BufferSizeExceededException
,
176 uno::RuntimeException
)
178 return readBytes( aData
,nMaxBytesToRead
);
183 XInputStream_impl::skipBytes(
184 sal_Int32 nBytesToSkip
)
185 throw( io::NotConnectedException
,
186 io::BufferSizeExceededException
,
188 uno::RuntimeException
)
190 m_aFile
.setPos( osl_Pos_Current
, sal_uInt64( nBytesToSkip
) );
195 XInputStream_impl::available(
197 throw( io::NotConnectedException
,
199 uno::RuntimeException
)
206 XInputStream_impl::closeInput(
208 throw( io::NotConnectedException
,
210 uno::RuntimeException
)
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
>() );
223 XInputStream_impl::seek(
225 throw( lang::IllegalArgumentException
,
227 uno::RuntimeException
)
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
>() );
237 XInputStream_impl::getPosition(
239 throw( io::IOException
,
240 uno::RuntimeException
)
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
);
249 XInputStream_impl::getLength(
251 throw( io::IOException
,
252 uno::RuntimeException
)
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
>() );
258 return sal_Int64( uEndPos
);
261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */