1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "filinpstr.hxx"
21 #include "filerror.hxx"
26 using namespace fileaccess
;
27 using namespace com::sun::star
;
28 using namespace com::sun::star::ucb
;
32 XInputStream_impl::XInputStream_impl( shell
* pMyShell
,const rtl::OUString
& aUncPath
, sal_Bool bLock
)
33 : m_xProvider( pMyShell
->m_pProvider
),
35 m_nErrorCode( TASKHANDLER_NO_ERROR
),
36 m_nMinorErrorCode( TASKHANDLER_NO_ERROR
)
38 sal_uInt32 nFlags
= osl_File_OpenFlag_Read
;
40 nFlags
|= osl_File_OpenFlag_NoLock
;
42 osl::FileBase::RC err
= m_aFile
.open( nFlags
);
43 if( err
!= osl::FileBase::E_None
)
48 m_nErrorCode
= TASKHANDLING_OPEN_FOR_INPUTSTREAM
;
49 m_nMinorErrorCode
= err
;
56 XInputStream_impl::~XInputStream_impl()
62 catch (io::IOException
const &)
64 OSL_FAIL("unexpected situation");
66 catch (uno::RuntimeException
const &)
68 OSL_FAIL("unexpected situation");
73 sal_Int32 SAL_CALL
XInputStream_impl::CtorSuccess()
80 sal_Int32 SAL_CALL
XInputStream_impl::getMinorError()
82 return m_nMinorErrorCode
;
86 //////////////////////////////////////////////////////////////////////////////////////////
88 //////////////////////////////////////////////////////////////////////////////////////////
91 XTYPEPROVIDER_IMPL_3( XInputStream_impl
,
99 XInputStream_impl::queryInterface(
100 const uno::Type
& rType
)
101 throw( uno::RuntimeException
)
103 uno::Any aRet
= cppu::queryInterface( rType
,
104 (static_cast< io::XInputStream
* >(this)),
105 (static_cast< lang::XTypeProvider
* >(this)),
106 (static_cast< io::XSeekable
* >(this)) );
107 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
);
112 XInputStream_impl::acquire(
116 OWeakObject::acquire();
121 XInputStream_impl::release(
125 OWeakObject::release();
131 XInputStream_impl::readBytes(
132 uno::Sequence
< sal_Int8
>& aData
,
133 sal_Int32 nBytesToRead
)
134 throw( io::NotConnectedException
,
135 io::BufferSizeExceededException
,
137 uno::RuntimeException
)
139 if( ! m_nIsOpen
) throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX
) ), uno::Reference
< uno::XInterface
>() );
141 aData
.realloc(nBytesToRead
);
142 //TODO! translate memory exhaustion (if it were detectable...) into
143 // io::BufferSizeExceededException
146 if(m_aFile
.read( aData
.getArray(),sal_uInt64(nBytesToRead
),nrc
)
147 != osl::FileBase::E_None
)
148 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX
) ), uno::Reference
< uno::XInterface
>() );
150 // Shrink aData in case we read less than nBytesToRead (XInputStream
151 // documentation does not tell whether this is required, and I do not know
152 // if any code relies on this, so be conservative---SB):
153 if (sal::static_int_cast
<sal_Int32
>(nrc
) != nBytesToRead
)
154 aData
.realloc(sal_Int32(nrc
));
155 return ( sal_Int32
) nrc
;
159 XInputStream_impl::readSomeBytes(
160 uno::Sequence
< sal_Int8
>& aData
,
161 sal_Int32 nMaxBytesToRead
)
162 throw( io::NotConnectedException
,
163 io::BufferSizeExceededException
,
165 uno::RuntimeException
)
167 return readBytes( aData
,nMaxBytesToRead
);
172 XInputStream_impl::skipBytes(
173 sal_Int32 nBytesToSkip
)
174 throw( io::NotConnectedException
,
175 io::BufferSizeExceededException
,
177 uno::RuntimeException
)
179 m_aFile
.setPos( osl_Pos_Current
, sal_uInt64( nBytesToSkip
) );
184 XInputStream_impl::available(
186 throw( io::NotConnectedException
,
188 uno::RuntimeException
)
195 XInputStream_impl::closeInput(
197 throw( io::NotConnectedException
,
199 uno::RuntimeException
)
203 osl::FileBase::RC err
= m_aFile
.close();
204 if( err
!= osl::FileBase::E_None
)
205 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX
) ), uno::Reference
< uno::XInterface
>() );
212 XInputStream_impl::seek(
214 throw( lang::IllegalArgumentException
,
216 uno::RuntimeException
)
219 throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX
) ), uno::Reference
< uno::XInterface
>(), 0 );
220 if( osl::FileBase::E_None
!= m_aFile
.setPos( osl_Pos_Absolut
, sal_uInt64( location
) ) )
221 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX
) ), uno::Reference
< uno::XInterface
>() );
226 XInputStream_impl::getPosition(
228 throw( io::IOException
,
229 uno::RuntimeException
)
232 if( osl::FileBase::E_None
!= m_aFile
.getPos( uPos
) )
233 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX
) ), uno::Reference
< uno::XInterface
>() );
234 return sal_Int64( uPos
);
238 XInputStream_impl::getLength(
240 throw( io::IOException
,
241 uno::RuntimeException
)
244 if ( m_aFile
.getSize(uEndPos
) != osl::FileBase::E_None
)
245 throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX
) ), uno::Reference
< uno::XInterface
>() );
247 return sal_Int64( uEndPos
);
250 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */