update dev300-m58
[ooovba.git] / ucb / source / ucp / ftp / ftpinpstr.cxx
blob7600ddb6afc9f8e1b1a41608ba2533810767144d
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: ftpinpstr.cxx,v $
10 * $Revision: 1.10 $
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 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_ucb.hxx"
34 /**************************************************************************
35 TODO
36 **************************************************************************
38 *************************************************************************/
39 #include "ftpinpstr.hxx"
40 #ifndef _RTL_ALLOC_H
41 #include <rtl/alloc.h>
42 #endif
43 #ifndef STD_ALGORITHM
44 #include <algorithm>
45 #define STD_ALGORITHM
46 #endif
47 #include <stdio.h>
49 using namespace ftp;
50 using namespace com::sun::star::uno;
51 using namespace com::sun::star::lang;
52 using namespace com::sun::star::io;
55 FTPInputStream::FTPInputStream(FILE* tmpfl)
56 : m_tmpfl(tmpfl ? tmpfl : tmpfile())
58 fseek(m_tmpfl,0,SEEK_END);
59 // fpos_t pos;
60 // fgetpos(m_tmpfl,&pos);
61 long pos = ftell(m_tmpfl);
62 rewind(m_tmpfl);
63 m_nLength = sal_Int64(pos);
68 FTPInputStream::~FTPInputStream()
70 if ( 0 != m_tmpfl)
71 fclose(m_tmpfl);
75 Any SAL_CALL FTPInputStream::queryInterface(
76 const Type& rType
78 throw(
79 RuntimeException
82 Any aRet = ::cppu::queryInterface(rType,
83 SAL_STATIC_CAST( XInputStream*,this ),
84 SAL_STATIC_CAST( XSeekable*,this ) );
86 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
91 void SAL_CALL FTPInputStream::acquire( void ) throw() {
92 OWeakObject::acquire();
97 void SAL_CALL FTPInputStream::release( void ) throw() {
98 OWeakObject::release();
102 sal_Int32 SAL_CALL FTPInputStream::readBytes(Sequence< sal_Int8 >& aData,
103 sal_Int32 nBytesToRead)
104 throw(NotConnectedException,
105 BufferSizeExceededException,
106 IOException,
107 RuntimeException)
109 osl::MutexGuard aGuard(m_aMutex);
111 if(0 <= nBytesToRead && aData.getLength() < nBytesToRead)
112 aData.realloc(nBytesToRead);
114 // fpos_t bpos,epos;
116 // fgetpos(m_tmpfl,&bpos);
117 // fread(aData.getArray(),nBytesToRead,1,m_tmpfl);
118 // fgetpos(m_tmpfl,&epos);
119 long bpos,epos;
121 bpos = ftell(m_tmpfl);
122 fread(aData.getArray(),nBytesToRead,1,m_tmpfl);
123 epos = ftell(m_tmpfl);
125 return sal_Int32(epos-bpos);
129 sal_Int32 SAL_CALL FTPInputStream::readSomeBytes( Sequence< sal_Int8 >& aData,sal_Int32 nMaxBytesToRead )
130 throw( NotConnectedException,
131 BufferSizeExceededException,
132 IOException,
133 RuntimeException)
135 return readBytes(aData,nMaxBytesToRead);
140 void SAL_CALL FTPInputStream::skipBytes(sal_Int32 nBytesToSkip)
141 throw(NotConnectedException,
142 BufferSizeExceededException,
143 IOException,
144 RuntimeException)
146 osl::MutexGuard aGuard(m_aMutex);
147 if(!m_tmpfl)
148 throw IOException();
150 fseek(m_tmpfl,long(nBytesToSkip),SEEK_CUR);
155 sal_Int32 SAL_CALL FTPInputStream::available(void)
156 throw(NotConnectedException,
157 IOException,
158 RuntimeException)
160 return sal::static_int_cast<sal_Int32>(m_nLength - getPosition());
165 void SAL_CALL FTPInputStream::closeInput(void)
166 throw(NotConnectedException,
167 IOException,
168 RuntimeException)
170 osl::MutexGuard aGuard(m_aMutex);
171 if(m_tmpfl)
172 fclose(m_tmpfl),m_tmpfl = 0;
177 void SAL_CALL FTPInputStream::seek(sal_Int64 location)
178 throw( IllegalArgumentException,
179 IOException,
180 RuntimeException )
182 osl::MutexGuard aGuard(m_aMutex);
183 if(!m_tmpfl)
184 throw IOException();
186 fseek(m_tmpfl,long(location),SEEK_SET);
191 sal_Int64 SAL_CALL
192 FTPInputStream::getPosition(
193 void )
194 throw( IOException,
195 RuntimeException )
197 osl::MutexGuard aGuard(m_aMutex);
198 if(!m_tmpfl)
199 throw IOException();
201 // fpos_t pos;
202 // fgetpos(m_tmpfl,&pos);
203 long pos;
204 pos = ftell(m_tmpfl);
205 return sal_Int64(pos);
210 sal_Int64 SAL_CALL FTPInputStream::getLength(
211 void
212 ) throw(
213 IOException,RuntimeException
216 return m_nLength;