bump product version to 5.0.4.1
[LibreOffice.git] / xmlhelp / source / cxxhelp / provider / inputstream.cxx
blobaf845caacb2fdbcf250c091d09471238642ee6a1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
23 #include <cppuhelper/queryinterface.hxx>
26 using namespace chelp;
27 using namespace com::sun::star;
28 using namespace com::sun::star::ucb;
32 XInputStream_impl::XInputStream_impl( const OUString& aUncPath )
33 : m_bIsOpen( false ),
34 m_aFile( aUncPath )
36 m_bIsOpen = ( osl::FileBase::E_None == m_aFile.open( osl_File_OpenFlag_Read ) );
40 XInputStream_impl::~XInputStream_impl()
42 closeInput();
46 uno::Any SAL_CALL
47 XInputStream_impl::queryInterface(
48 const uno::Type& rType )
49 throw( uno::RuntimeException, std::exception)
51 uno::Any aRet = cppu::queryInterface( rType,
52 (static_cast< io::XInputStream* >(this)),
53 (static_cast< io::XSeekable* >(this)) );
54 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
58 void SAL_CALL
59 XInputStream_impl::acquire(
60 void )
61 throw()
63 OWeakObject::acquire();
67 void SAL_CALL
68 XInputStream_impl::release(
69 void )
70 throw()
72 OWeakObject::release();
77 sal_Int32 SAL_CALL
78 XInputStream_impl::readBytes(
79 uno::Sequence< sal_Int8 >& aData,
80 sal_Int32 nBytesToRead )
81 throw( io::NotConnectedException,
82 io::BufferSizeExceededException,
83 io::IOException,
84 uno::RuntimeException, std::exception)
86 if( ! m_bIsOpen )
87 throw io::IOException();
89 aData.realloc(nBytesToRead);
90 //TODO! translate memory exhaustion (if it were detectable...) into
91 // io::BufferSizeExceededException
93 sal_uInt64 nrc;
94 m_aFile.read( aData.getArray(),sal_uInt64(nBytesToRead),nrc );
96 // Shrink aData in case we read less than nBytesToRead (XInputStream
97 // documentation does not tell whether this is required, and I do not know
98 // if any code relies on this, so be conservative---SB):
99 if (nrc != sal::static_int_cast<sal_uInt64>( nBytesToRead) )
100 aData.realloc(sal_Int32(nrc));
101 return ( sal_Int32 ) nrc;
104 sal_Int32 SAL_CALL
105 XInputStream_impl::readSomeBytes(
106 uno::Sequence< sal_Int8 >& aData,
107 sal_Int32 nMaxBytesToRead )
108 throw( io::NotConnectedException,
109 io::BufferSizeExceededException,
110 io::IOException,
111 uno::RuntimeException, std::exception)
113 return readBytes( aData,nMaxBytesToRead );
117 void SAL_CALL
118 XInputStream_impl::skipBytes(
119 sal_Int32 nBytesToSkip )
120 throw( io::NotConnectedException,
121 io::BufferSizeExceededException,
122 io::IOException,
123 uno::RuntimeException, std::exception)
125 if (m_aFile.setPos(osl_Pos_Current, sal_uInt64(nBytesToSkip)) != osl::FileBase::E_None)
127 throw io::IOException("XInputStream_impl::skipBytes failed seek");
132 sal_Int32 SAL_CALL
133 XInputStream_impl::available(
134 void )
135 throw( io::NotConnectedException,
136 io::IOException,
137 uno::RuntimeException, std::exception)
139 return 0;
143 void SAL_CALL
144 XInputStream_impl::closeInput(
145 void )
146 throw( io::NotConnectedException,
147 io::IOException,
148 uno::RuntimeException, std::exception )
150 if( m_bIsOpen )
152 osl::FileBase::RC err = m_aFile.close();
153 if( err != osl::FileBase::E_None )
154 throw io::IOException();
155 m_bIsOpen = false;
160 void SAL_CALL
161 XInputStream_impl::seek(
162 sal_Int64 location )
163 throw( lang::IllegalArgumentException,
164 io::IOException,
165 uno::RuntimeException, std::exception )
167 if( location < 0 )
168 throw lang::IllegalArgumentException();
169 if( osl::FileBase::E_None != m_aFile.setPos( osl_Pos_Absolut, sal_uInt64( location ) ) )
170 throw io::IOException();
174 sal_Int64 SAL_CALL
175 XInputStream_impl::getPosition(
176 void )
177 throw( io::IOException,
178 uno::RuntimeException, std::exception )
180 sal_uInt64 uPos;
181 if( osl::FileBase::E_None != m_aFile.getPos( uPos ) )
182 throw io::IOException();
183 return sal_Int64( uPos );
186 sal_Int64 SAL_CALL
187 XInputStream_impl::getLength(
188 void )
189 throw( io::IOException,
190 uno::RuntimeException, std::exception )
192 osl::FileBase::RC err;
193 sal_uInt64 uCurrentPos, uEndPos;
195 err = m_aFile.getPos( uCurrentPos );
196 if( err != osl::FileBase::E_None )
197 throw io::IOException();
199 err = m_aFile.setPos( osl_Pos_End, 0 );
200 if( err != osl::FileBase::E_None )
201 throw io::IOException();
203 err = m_aFile.getPos( uEndPos );
204 if( err != osl::FileBase::E_None )
205 throw io::IOException();
207 err = m_aFile.setPos( osl_Pos_Absolut, uCurrentPos );
208 if( err != osl::FileBase::E_None )
209 throw io::IOException();
210 else
211 return sal_Int64( uEndPos );
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */