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 .
21 #include "inputstream.hxx"
24 using namespace chelp
;
25 using namespace com::sun::star
;
26 using namespace com::sun::star::ucb
;
30 XInputStream_impl::XInputStream_impl( const OUString
& aUncPath
)
34 m_bIsOpen
= ( osl::FileBase::E_None
== m_aFile
.open( osl_File_OpenFlag_Read
) );
38 XInputStream_impl::~XInputStream_impl()
44 bool SAL_CALL
XInputStream_impl::CtorSuccess()
51 XInputStream_impl::queryInterface(
52 const uno::Type
& rType
)
53 throw( uno::RuntimeException
)
55 uno::Any aRet
= cppu::queryInterface( rType
,
56 (static_cast< io::XInputStream
* >(this)),
57 (static_cast< io::XSeekable
* >(this)) );
58 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
);
63 XInputStream_impl::acquire(
67 OWeakObject::acquire();
72 XInputStream_impl::release(
76 OWeakObject::release();
82 XInputStream_impl::readBytes(
83 uno::Sequence
< sal_Int8
>& aData
,
84 sal_Int32 nBytesToRead
)
85 throw( io::NotConnectedException
,
86 io::BufferSizeExceededException
,
88 uno::RuntimeException
)
91 throw io::IOException();
93 aData
.realloc(nBytesToRead
);
94 //TODO! translate memory exhaustion (if it were detectable...) into
95 // io::BufferSizeExceededException
98 m_aFile
.read( aData
.getArray(),sal_uInt64(nBytesToRead
),nrc
);
100 // Shrink aData in case we read less than nBytesToRead (XInputStream
101 // documentation does not tell whether this is required, and I do not know
102 // if any code relies on this, so be conservative---SB):
103 if (nrc
!= sal::static_int_cast
<sal_uInt64
>( nBytesToRead
) )
104 aData
.realloc(sal_Int32(nrc
));
105 return ( sal_Int32
) nrc
;
109 XInputStream_impl::readSomeBytes(
110 uno::Sequence
< sal_Int8
>& aData
,
111 sal_Int32 nMaxBytesToRead
)
112 throw( io::NotConnectedException
,
113 io::BufferSizeExceededException
,
115 uno::RuntimeException
)
117 return readBytes( aData
,nMaxBytesToRead
);
122 XInputStream_impl::skipBytes(
123 sal_Int32 nBytesToSkip
)
124 throw( io::NotConnectedException
,
125 io::BufferSizeExceededException
,
127 uno::RuntimeException
)
129 if (m_aFile
.setPos(osl_Pos_Current
, sal_uInt64(nBytesToSkip
)) != osl::FileBase::E_None
)
131 throw io::IOException(OUString(
132 "XInputStream_impl::skipBytes failed seek"), uno::Reference
< uno::XInterface
>());
138 XInputStream_impl::available(
140 throw( io::NotConnectedException
,
142 uno::RuntimeException
)
149 XInputStream_impl::closeInput(
151 throw( io::NotConnectedException
,
153 uno::RuntimeException
)
157 osl::FileBase::RC err
= m_aFile
.close();
158 if( err
!= osl::FileBase::E_None
)
159 throw io::IOException();
166 XInputStream_impl::seek(
168 throw( lang::IllegalArgumentException
,
170 uno::RuntimeException
)
173 throw lang::IllegalArgumentException();
174 if( osl::FileBase::E_None
!= m_aFile
.setPos( osl_Pos_Absolut
, sal_uInt64( location
) ) )
175 throw io::IOException();
180 XInputStream_impl::getPosition(
182 throw( io::IOException
,
183 uno::RuntimeException
)
186 if( osl::FileBase::E_None
!= m_aFile
.getPos( uPos
) )
187 throw io::IOException();
188 return sal_Int64( uPos
);
192 XInputStream_impl::getLength(
194 throw( io::IOException
,
195 uno::RuntimeException
)
197 osl::FileBase::RC err
;
198 sal_uInt64 uCurrentPos
, uEndPos
;
200 err
= m_aFile
.getPos( uCurrentPos
);
201 if( err
!= osl::FileBase::E_None
)
202 throw io::IOException();
204 err
= m_aFile
.setPos( osl_Pos_End
, 0 );
205 if( err
!= osl::FileBase::E_None
)
206 throw io::IOException();
208 err
= m_aFile
.getPos( uEndPos
);
209 if( err
!= osl::FileBase::E_None
)
210 throw io::IOException();
212 err
= m_aFile
.setPos( osl_Pos_Absolut
, uCurrentPos
);
213 if( err
!= osl::FileBase::E_None
)
214 throw io::IOException();
216 return sal_Int64( uEndPos
);
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */