ftpinpstr.cxx (2f86921c) | ftpinpstr.cxx (72cd26dd) |
---|---|
1/************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance --- 23 unchanged lines hidden (view full) --- 32#include "ftpinpstr.hxx" 33#ifndef _RTL_ALLOC_H 34#include <rtl/alloc.h> 35#endif 36#ifndef STD_ALGORITHM 37#include <algorithm> 38#define STD_ALGORITHM 39#endif | 1/************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance --- 23 unchanged lines hidden (view full) --- 32#include "ftpinpstr.hxx" 33#ifndef _RTL_ALLOC_H 34#include <rtl/alloc.h> 35#endif 36#ifndef STD_ALGORITHM 37#include <algorithm> 38#define STD_ALGORITHM 39#endif |
40#include <stdio.h> | |
41 42using namespace ftp; 43using namespace com::sun::star::uno; 44using namespace com::sun::star::lang; 45using namespace com::sun::star::io; 46 47 | 40 41using namespace ftp; 42using namespace com::sun::star::uno; 43using namespace com::sun::star::lang; 44using namespace com::sun::star::io; 45 46 |
48FTPInputStream::FTPInputStream(FILE* tmpfl) 49 : m_tmpfl(tmpfl ? tmpfl : tmpfile()) | 47FTPInputStream::FTPInputStream( oslFileHandle tmpfl ) 48 : m_tmpfl(tmpfl) 49 , m_nLength( 0 ) |
50{ | 50{ |
51 fseek(m_tmpfl,0,SEEK_END); 52// fpos_t pos; 53// fgetpos(m_tmpfl,&pos); 54 long pos = ftell(m_tmpfl); 55 rewind(m_tmpfl); 56 m_nLength = sal_Int64(pos); | 51 if ( !m_tmpfl ) 52 osl_createTempFile( NULL, &m_tmpfl, NULL ); 53 OSL_ENSURE( m_tmpfl, "input stream without tempfile!" ); 54 55 if ( osl_setFilePos( m_tmpfl, osl_Pos_End, 0 ) == osl_File_E_None ) 56 { 57 sal_uInt64 nFileSize = 0; 58 if ( osl_getFilePos( m_tmpfl, &nFileSize ) == osl_File_E_None ) 59 m_nLength = nFileSize; 60 osl_setFilePos( m_tmpfl, osl_Pos_Absolut, 0 ); 61 } |
57} 58 | 62} 63 |
59 60 | |
61FTPInputStream::~FTPInputStream() 62{ 63 if ( 0 != m_tmpfl) | 64FTPInputStream::~FTPInputStream() 65{ 66 if ( 0 != m_tmpfl) |
64 fclose(m_tmpfl); | 67 osl_closeFile(m_tmpfl); |
65} 66 | 68} 69 |
67 68Any SAL_CALL FTPInputStream::queryInterface( 69 const Type& rType 70) 71 throw( 72 RuntimeException 73 ) 74{ 75 Any aRet = ::cppu::queryInterface(rType, 76 SAL_STATIC_CAST( XInputStream*,this ), 77 SAL_STATIC_CAST( XSeekable*,this ) ); 78 79 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ); 80} 81 82 83 84void SAL_CALL FTPInputStream::acquire( void ) throw() { 85 OWeakObject::acquire(); 86} 87 88 89 90void SAL_CALL FTPInputStream::release( void ) throw() { 91 OWeakObject::release(); 92} 93 94 | |
95sal_Int32 SAL_CALL FTPInputStream::readBytes(Sequence< sal_Int8 >& aData, 96 sal_Int32 nBytesToRead) 97 throw(NotConnectedException, 98 BufferSizeExceededException, 99 IOException, 100 RuntimeException) 101{ 102 osl::MutexGuard aGuard(m_aMutex); 103 | 70sal_Int32 SAL_CALL FTPInputStream::readBytes(Sequence< sal_Int8 >& aData, 71 sal_Int32 nBytesToRead) 72 throw(NotConnectedException, 73 BufferSizeExceededException, 74 IOException, 75 RuntimeException) 76{ 77 osl::MutexGuard aGuard(m_aMutex); 78 |
104 if(0 <= nBytesToRead && aData.getLength() < nBytesToRead) 105 aData.realloc(nBytesToRead); | 79 sal_uInt64 nBeforePos( 0 ); 80 sal_uInt64 nBytesRequested( nBytesToRead ); 81 sal_uInt64 nBytesRead( 0 ); |
106 | 82 |
107// fpos_t bpos,epos; | 83 osl_getFilePos( m_tmpfl, &nBeforePos ); |
108 | 84 |
109// fgetpos(m_tmpfl,&bpos); 110// fread(aData.getArray(),nBytesToRead,1,m_tmpfl); 111// fgetpos(m_tmpfl,&epos); 112 long bpos,epos; | 85 if ( 0 == ( nBytesRequested = std::min< sal_uInt64 >( m_nLength - nBeforePos, nBytesRequested ) ) ) 86 return 0; |
113 | 87 |
114 bpos = ftell(m_tmpfl); 115 if (fread(aData.getArray(),nBytesToRead,1,m_tmpfl) != 1) | 88 if ( 0 <= nBytesToRead && aData.getLength() < nBytesToRead ) 89 aData.realloc( nBytesToRead ); 90 91 if ( osl_readFile( m_tmpfl, aData.getArray(), nBytesRequested, &nBytesRead ) != osl_File_E_None ) |
116 throw IOException(); 117 | 92 throw IOException(); 93 |
118 epos = ftell(m_tmpfl); 119 120 return sal_Int32(epos-bpos); | 94 return sal_Int32( nBytesRead ); |
121} 122 123 124sal_Int32 SAL_CALL FTPInputStream::readSomeBytes( Sequence< sal_Int8 >& aData, 125 sal_Int32 nMaxBytesToRead ) 126 throw( NotConnectedException, 127 BufferSizeExceededException, 128 IOException, --- 9 unchanged lines hidden (view full) --- 138 BufferSizeExceededException, 139 IOException, 140 RuntimeException) 141{ 142 osl::MutexGuard aGuard(m_aMutex); 143 if(!m_tmpfl) 144 throw IOException(); 145 | 95} 96 97 98sal_Int32 SAL_CALL FTPInputStream::readSomeBytes( Sequence< sal_Int8 >& aData, 99 sal_Int32 nMaxBytesToRead ) 100 throw( NotConnectedException, 101 BufferSizeExceededException, 102 IOException, --- 9 unchanged lines hidden (view full) --- 112 BufferSizeExceededException, 113 IOException, 114 RuntimeException) 115{ 116 osl::MutexGuard aGuard(m_aMutex); 117 if(!m_tmpfl) 118 throw IOException(); 119 |
146 fseek(m_tmpfl,long(nBytesToSkip),SEEK_CUR); | 120 osl_setFilePos( m_tmpfl, osl_Pos_Current, nBytesToSkip ); |
147} 148 149 150 151sal_Int32 SAL_CALL FTPInputStream::available(void) 152 throw(NotConnectedException, 153 IOException, 154 RuntimeException) --- 5 unchanged lines hidden (view full) --- 160 161void SAL_CALL FTPInputStream::closeInput(void) 162 throw(NotConnectedException, 163 IOException, 164 RuntimeException) 165{ 166 osl::MutexGuard aGuard(m_aMutex); 167 if(m_tmpfl) | 121} 122 123 124 125sal_Int32 SAL_CALL FTPInputStream::available(void) 126 throw(NotConnectedException, 127 IOException, 128 RuntimeException) --- 5 unchanged lines hidden (view full) --- 134 135void SAL_CALL FTPInputStream::closeInput(void) 136 throw(NotConnectedException, 137 IOException, 138 RuntimeException) 139{ 140 osl::MutexGuard aGuard(m_aMutex); 141 if(m_tmpfl) |
168 fclose(m_tmpfl),m_tmpfl = 0; | 142 osl_closeFile(m_tmpfl),m_tmpfl = 0; |
169} 170 171 172 173void SAL_CALL FTPInputStream::seek(sal_Int64 location) 174 throw( IllegalArgumentException, 175 IOException, 176 RuntimeException ) 177{ 178 osl::MutexGuard aGuard(m_aMutex); 179 if(!m_tmpfl) 180 throw IOException(); 181 | 143} 144 145 146 147void SAL_CALL FTPInputStream::seek(sal_Int64 location) 148 throw( IllegalArgumentException, 149 IOException, 150 RuntimeException ) 151{ 152 osl::MutexGuard aGuard(m_aMutex); 153 if(!m_tmpfl) 154 throw IOException(); 155 |
182 fseek(m_tmpfl,long(location),SEEK_SET); | 156 osl_setFilePos( m_tmpfl, osl_Pos_Absolut, location ); |
183} 184 185 186 187sal_Int64 SAL_CALL 188FTPInputStream::getPosition( 189 void ) 190 throw( IOException, 191 RuntimeException ) 192{ 193 osl::MutexGuard aGuard(m_aMutex); 194 if(!m_tmpfl) 195 throw IOException(); 196 | 157} 158 159 160 161sal_Int64 SAL_CALL 162FTPInputStream::getPosition( 163 void ) 164 throw( IOException, 165 RuntimeException ) 166{ 167 osl::MutexGuard aGuard(m_aMutex); 168 if(!m_tmpfl) 169 throw IOException(); 170 |
197// fpos_t pos; 198// fgetpos(m_tmpfl,&pos); 199 long pos; 200 pos = ftell(m_tmpfl); 201 return sal_Int64(pos); | 171 sal_uInt64 nFilePos = 0; 172 osl_getFilePos( m_tmpfl, &nFilePos ); 173 return nFilePos; |
202} 203 204 205 206sal_Int64 SAL_CALL FTPInputStream::getLength( 207 void 208) throw( 209 IOException,RuntimeException 210) 211{ 212 return m_nLength; 213} | 174} 175 176 177 178sal_Int64 SAL_CALL FTPInputStream::getLength( 179 void 180) throw( 181 IOException,RuntimeException 182) 183{ 184 return m_nLength; 185} |