1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ftpinpstr.cxx,v $
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 /**************************************************************************
36 **************************************************************************
38 *************************************************************************/
39 #include "ftpinpstr.hxx"
41 #include <rtl/alloc.h>
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
);
60 // fgetpos(m_tmpfl,&pos);
61 long pos
= ftell(m_tmpfl
);
63 m_nLength
= sal_Int64(pos
);
68 FTPInputStream::~FTPInputStream()
75 Any SAL_CALL
FTPInputStream::queryInterface(
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
,
109 osl::MutexGuard
aGuard(m_aMutex
);
111 if(0 <= nBytesToRead
&& aData
.getLength() < nBytesToRead
)
112 aData
.realloc(nBytesToRead
);
116 // fgetpos(m_tmpfl,&bpos);
117 // fread(aData.getArray(),nBytesToRead,1,m_tmpfl);
118 // fgetpos(m_tmpfl,&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
,
135 return readBytes(aData
,nMaxBytesToRead
);
140 void SAL_CALL
FTPInputStream::skipBytes(sal_Int32 nBytesToSkip
)
141 throw(NotConnectedException
,
142 BufferSizeExceededException
,
146 osl::MutexGuard
aGuard(m_aMutex
);
150 fseek(m_tmpfl
,long(nBytesToSkip
),SEEK_CUR
);
155 sal_Int32 SAL_CALL
FTPInputStream::available(void)
156 throw(NotConnectedException
,
160 return sal::static_int_cast
<sal_Int32
>(m_nLength
- getPosition());
165 void SAL_CALL
FTPInputStream::closeInput(void)
166 throw(NotConnectedException
,
170 osl::MutexGuard
aGuard(m_aMutex
);
172 fclose(m_tmpfl
),m_tmpfl
= 0;
177 void SAL_CALL
FTPInputStream::seek(sal_Int64 location
)
178 throw( IllegalArgumentException
,
182 osl::MutexGuard
aGuard(m_aMutex
);
186 fseek(m_tmpfl
,long(location
),SEEK_SET
);
192 FTPInputStream::getPosition(
197 osl::MutexGuard
aGuard(m_aMutex
);
202 // fgetpos(m_tmpfl,&pos);
204 pos
= ftell(m_tmpfl
);
205 return sal_Int64(pos
);
210 sal_Int64 SAL_CALL
FTPInputStream::getLength(
213 IOException
,RuntimeException