fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / xmlhelp / source / cxxhelp / provider / inputstream.cxx
blob33d8556ebdc64caa109ceb4f6793699f1b4ac17c
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"
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 )
31 : m_bIsOpen( false ),
32 m_aFile( aUncPath )
34 m_bIsOpen = ( osl::FileBase::E_None == m_aFile.open( osl_File_OpenFlag_Read ) );
38 XInputStream_impl::~XInputStream_impl()
40 closeInput();
44 bool SAL_CALL XInputStream_impl::CtorSuccess()
46 return m_bIsOpen;
50 uno::Any SAL_CALL
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 );
62 void SAL_CALL
63 XInputStream_impl::acquire(
64 void )
65 throw()
67 OWeakObject::acquire();
71 void SAL_CALL
72 XInputStream_impl::release(
73 void )
74 throw()
76 OWeakObject::release();
81 sal_Int32 SAL_CALL
82 XInputStream_impl::readBytes(
83 uno::Sequence< sal_Int8 >& aData,
84 sal_Int32 nBytesToRead )
85 throw( io::NotConnectedException,
86 io::BufferSizeExceededException,
87 io::IOException,
88 uno::RuntimeException)
90 if( ! m_bIsOpen )
91 throw io::IOException();
93 aData.realloc(nBytesToRead);
94 //TODO! translate memory exhaustion (if it were detectable...) into
95 // io::BufferSizeExceededException
97 sal_uInt64 nrc;
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;
108 sal_Int32 SAL_CALL
109 XInputStream_impl::readSomeBytes(
110 uno::Sequence< sal_Int8 >& aData,
111 sal_Int32 nMaxBytesToRead )
112 throw( io::NotConnectedException,
113 io::BufferSizeExceededException,
114 io::IOException,
115 uno::RuntimeException)
117 return readBytes( aData,nMaxBytesToRead );
121 void SAL_CALL
122 XInputStream_impl::skipBytes(
123 sal_Int32 nBytesToSkip )
124 throw( io::NotConnectedException,
125 io::BufferSizeExceededException,
126 io::IOException,
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 >());
137 sal_Int32 SAL_CALL
138 XInputStream_impl::available(
139 void )
140 throw( io::NotConnectedException,
141 io::IOException,
142 uno::RuntimeException)
144 return 0;
148 void SAL_CALL
149 XInputStream_impl::closeInput(
150 void )
151 throw( io::NotConnectedException,
152 io::IOException,
153 uno::RuntimeException )
155 if( m_bIsOpen )
157 osl::FileBase::RC err = m_aFile.close();
158 if( err != osl::FileBase::E_None )
159 throw io::IOException();
160 m_bIsOpen = false;
165 void SAL_CALL
166 XInputStream_impl::seek(
167 sal_Int64 location )
168 throw( lang::IllegalArgumentException,
169 io::IOException,
170 uno::RuntimeException )
172 if( location < 0 )
173 throw lang::IllegalArgumentException();
174 if( osl::FileBase::E_None != m_aFile.setPos( osl_Pos_Absolut, sal_uInt64( location ) ) )
175 throw io::IOException();
179 sal_Int64 SAL_CALL
180 XInputStream_impl::getPosition(
181 void )
182 throw( io::IOException,
183 uno::RuntimeException )
185 sal_uInt64 uPos;
186 if( osl::FileBase::E_None != m_aFile.getPos( uPos ) )
187 throw io::IOException();
188 return sal_Int64( uPos );
191 sal_Int64 SAL_CALL
192 XInputStream_impl::getLength(
193 void )
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();
215 else
216 return sal_Int64( uEndPos );
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */