update dev300-m58
[ooovba.git] / xmlhelp / source / cxxhelp / provider / inputstream.cxx
blobc5d00d83918a47b9e1aa238093b8b171df7d1c94
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: inputstream.cxx,v $
10 * $Revision: 1.5 $
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 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_xmlhelp.hxx"
34 #include "inputstream.hxx"
37 using namespace chelp;
38 using namespace com::sun::star;
39 using namespace com::sun::star::ucb;
43 XInputStream_impl::XInputStream_impl( const rtl::OUString& aUncPath )
44 : m_bIsOpen( false ),
45 m_aFile( aUncPath )
47 m_bIsOpen = ( osl::FileBase::E_None == m_aFile.open( OpenFlag_Read ) );
51 XInputStream_impl::~XInputStream_impl()
53 closeInput();
57 bool SAL_CALL XInputStream_impl::CtorSuccess()
59 return m_bIsOpen;
63 uno::Any SAL_CALL
64 XInputStream_impl::queryInterface(
65 const uno::Type& rType )
66 throw( uno::RuntimeException)
68 uno::Any aRet = cppu::queryInterface( rType,
69 SAL_STATIC_CAST( io::XInputStream*,this ),
70 SAL_STATIC_CAST( io::XSeekable*,this ) );
71 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
75 void SAL_CALL
76 XInputStream_impl::acquire(
77 void )
78 throw()
80 OWeakObject::acquire();
84 void SAL_CALL
85 XInputStream_impl::release(
86 void )
87 throw()
89 OWeakObject::release();
94 sal_Int32 SAL_CALL
95 XInputStream_impl::readBytes(
96 uno::Sequence< sal_Int8 >& aData,
97 sal_Int32 nBytesToRead )
98 throw( io::NotConnectedException,
99 io::BufferSizeExceededException,
100 io::IOException,
101 uno::RuntimeException)
103 if( ! m_bIsOpen )
104 throw io::IOException();
106 aData.realloc(nBytesToRead);
107 //TODO! translate memory exhaustion (if it were detectable...) into
108 // io::BufferSizeExceededException
110 sal_uInt64 nrc;
111 m_aFile.read( aData.getArray(),sal_uInt64(nBytesToRead),nrc );
113 // Shrink aData in case we read less than nBytesToRead (XInputStream
114 // documentation does not tell whether this is required, and I do not know
115 // if any code relies on this, so be conservative---SB):
116 if (nrc != sal::static_int_cast<sal_uInt64>( nBytesToRead) )
117 aData.realloc(sal_Int32(nrc));
118 return ( sal_Int32 ) nrc;
121 sal_Int32 SAL_CALL
122 XInputStream_impl::readSomeBytes(
123 uno::Sequence< sal_Int8 >& aData,
124 sal_Int32 nMaxBytesToRead )
125 throw( io::NotConnectedException,
126 io::BufferSizeExceededException,
127 io::IOException,
128 uno::RuntimeException)
130 return readBytes( aData,nMaxBytesToRead );
134 void SAL_CALL
135 XInputStream_impl::skipBytes(
136 sal_Int32 nBytesToSkip )
137 throw( io::NotConnectedException,
138 io::BufferSizeExceededException,
139 io::IOException,
140 uno::RuntimeException)
142 m_aFile.setPos( osl_Pos_Current, sal_uInt64( nBytesToSkip ) );
146 sal_Int32 SAL_CALL
147 XInputStream_impl::available(
148 void )
149 throw( io::NotConnectedException,
150 io::IOException,
151 uno::RuntimeException)
153 return 0;
157 void SAL_CALL
158 XInputStream_impl::closeInput(
159 void )
160 throw( io::NotConnectedException,
161 io::IOException,
162 uno::RuntimeException )
164 if( m_bIsOpen )
166 osl::FileBase::RC err = m_aFile.close();
167 if( err != osl::FileBase::E_None )
168 throw io::IOException();
169 m_bIsOpen = false;
174 void SAL_CALL
175 XInputStream_impl::seek(
176 sal_Int64 location )
177 throw( lang::IllegalArgumentException,
178 io::IOException,
179 uno::RuntimeException )
181 if( location < 0 )
182 throw lang::IllegalArgumentException();
183 if( osl::FileBase::E_None != m_aFile.setPos( Pos_Absolut, sal_uInt64( location ) ) )
184 throw io::IOException();
188 sal_Int64 SAL_CALL
189 XInputStream_impl::getPosition(
190 void )
191 throw( io::IOException,
192 uno::RuntimeException )
194 sal_uInt64 uPos;
195 if( osl::FileBase::E_None != m_aFile.getPos( uPos ) )
196 throw io::IOException();
197 return sal_Int64( uPos );
200 sal_Int64 SAL_CALL
201 XInputStream_impl::getLength(
202 void )
203 throw( io::IOException,
204 uno::RuntimeException )
206 osl::FileBase::RC err;
207 sal_uInt64 uCurrentPos, uEndPos;
209 err = m_aFile.getPos( uCurrentPos );
210 if( err != osl::FileBase::E_None )
211 throw io::IOException();
213 err = m_aFile.setPos( Pos_End, 0 );
214 if( err != osl::FileBase::E_None )
215 throw io::IOException();
217 err = m_aFile.getPos( uEndPos );
218 if( err != osl::FileBase::E_None )
219 throw io::IOException();
221 err = m_aFile.setPos( Pos_Absolut, uCurrentPos );
222 if( err != osl::FileBase::E_None )
223 throw io::IOException();
224 else
225 return sal_Int64( uEndPos );