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: inputstream.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 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_xmlhelp.hxx"
34 #include "inputstream.hxx"
37 using namespace chelp
;
38 using namespace com::sun::star
;
39 using namespace com::sun::star::ucb
;
43 XInputStream_impl::XInputStream_impl( const rtl::OUString
& aUncPath
)
47 m_bIsOpen
= ( osl::FileBase::E_None
== m_aFile
.open( OpenFlag_Read
) );
51 XInputStream_impl::~XInputStream_impl()
57 bool SAL_CALL
XInputStream_impl::CtorSuccess()
64 XInputStream_impl::queryInterface(
65 const uno::Type
& rType
)
66 throw( uno::RuntimeException
)
68 uno::Any aRet
= cppu::queryInterface( rType
,
69 SAL_STATIC_CAST( io::XInputStream
*,this ),
70 SAL_STATIC_CAST( io::XSeekable
*,this ) );
71 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
);
76 XInputStream_impl::acquire(
80 OWeakObject::acquire();
85 XInputStream_impl::release(
89 OWeakObject::release();
95 XInputStream_impl::readBytes(
96 uno::Sequence
< sal_Int8
>& aData
,
97 sal_Int32 nBytesToRead
)
98 throw( io::NotConnectedException
,
99 io::BufferSizeExceededException
,
101 uno::RuntimeException
)
104 throw io::IOException();
106 aData
.realloc(nBytesToRead
);
107 //TODO! translate memory exhaustion (if it were detectable...) into
108 // io::BufferSizeExceededException
111 m_aFile
.read( aData
.getArray(),sal_uInt64(nBytesToRead
),nrc
);
113 // Shrink aData in case we read less than nBytesToRead (XInputStream
114 // documentation does not tell whether this is required, and I do not know
115 // if any code relies on this, so be conservative---SB):
116 if (nrc
!= sal::static_int_cast
<sal_uInt64
>( nBytesToRead
) )
117 aData
.realloc(sal_Int32(nrc
));
118 return ( sal_Int32
) nrc
;
122 XInputStream_impl::readSomeBytes(
123 uno::Sequence
< sal_Int8
>& aData
,
124 sal_Int32 nMaxBytesToRead
)
125 throw( io::NotConnectedException
,
126 io::BufferSizeExceededException
,
128 uno::RuntimeException
)
130 return readBytes( aData
,nMaxBytesToRead
);
135 XInputStream_impl::skipBytes(
136 sal_Int32 nBytesToSkip
)
137 throw( io::NotConnectedException
,
138 io::BufferSizeExceededException
,
140 uno::RuntimeException
)
142 m_aFile
.setPos( osl_Pos_Current
, sal_uInt64( nBytesToSkip
) );
147 XInputStream_impl::available(
149 throw( io::NotConnectedException
,
151 uno::RuntimeException
)
158 XInputStream_impl::closeInput(
160 throw( io::NotConnectedException
,
162 uno::RuntimeException
)
166 osl::FileBase::RC err
= m_aFile
.close();
167 if( err
!= osl::FileBase::E_None
)
168 throw io::IOException();
175 XInputStream_impl::seek(
177 throw( lang::IllegalArgumentException
,
179 uno::RuntimeException
)
182 throw lang::IllegalArgumentException();
183 if( osl::FileBase::E_None
!= m_aFile
.setPos( Pos_Absolut
, sal_uInt64( location
) ) )
184 throw io::IOException();
189 XInputStream_impl::getPosition(
191 throw( io::IOException
,
192 uno::RuntimeException
)
195 if( osl::FileBase::E_None
!= m_aFile
.getPos( uPos
) )
196 throw io::IOException();
197 return sal_Int64( uPos
);
201 XInputStream_impl::getLength(
203 throw( io::IOException
,
204 uno::RuntimeException
)
206 osl::FileBase::RC err
;
207 sal_uInt64 uCurrentPos
, uEndPos
;
209 err
= m_aFile
.getPos( uCurrentPos
);
210 if( err
!= osl::FileBase::E_None
)
211 throw io::IOException();
213 err
= m_aFile
.setPos( Pos_End
, 0 );
214 if( err
!= osl::FileBase::E_None
)
215 throw io::IOException();
217 err
= m_aFile
.getPos( uEndPos
);
218 if( err
!= osl::FileBase::E_None
)
219 throw io::IOException();
221 err
= m_aFile
.setPos( Pos_Absolut
, uCurrentPos
);
222 if( err
!= osl::FileBase::E_None
)
223 throw io::IOException();
225 return sal_Int64( uEndPos
);