summaryrefslogtreecommitdiff
path: root/xmlhelp
diff options
context:
space:
mode:
authorAndreas Bille <abi@openoffice.org>2001-10-01 11:07:02 +0000
committerAndreas Bille <abi@openoffice.org>2001-10-01 11:07:02 +0000
commitba2ea9813fcb472aef23825aab7e04acd036e93f (patch)
tree4399dd1dcb6c40dd2bdb534571812a5e7c51dfd2 /xmlhelp
parent7694a7273d17e283245b8b0a46dc4876b0d91887 (diff)
#91885#
Inputstream for package implementation
Diffstat (limited to 'xmlhelp')
-rw-r--r--xmlhelp/source/cxxhelp/provider/inputstream.cxx195
-rw-r--r--xmlhelp/source/cxxhelp/provider/inputstream.hxx131
2 files changed, 326 insertions, 0 deletions
diff --git a/xmlhelp/source/cxxhelp/provider/inputstream.cxx b/xmlhelp/source/cxxhelp/provider/inputstream.cxx
new file mode 100644
index 000000000000..a50ded7c0ddf
--- /dev/null
+++ b/xmlhelp/source/cxxhelp/provider/inputstream.cxx
@@ -0,0 +1,195 @@
+#ifndef _INPUSTREAM_HXX_
+#include "inputstream.hxx"
+#endif
+
+
+using namespace chelp;
+using namespace com::sun::star;
+using namespace com::sun::star::ucb;
+
+
+
+XInputStream_impl::XInputStream_impl( const rtl::OUString& aUncPath )
+ : m_aFile( aUncPath ),
+ m_bIsOpen( false )
+{
+ m_bIsOpen = ( osl::FileBase::E_None == m_aFile.open( OpenFlag_Read ) );
+}
+
+
+XInputStream_impl::~XInputStream_impl()
+{
+ closeInput();
+}
+
+
+bool SAL_CALL XInputStream_impl::CtorSuccess()
+{
+ return m_bIsOpen;
+};
+
+
+uno::Any SAL_CALL
+XInputStream_impl::queryInterface(
+ const uno::Type& rType )
+ throw( uno::RuntimeException)
+{
+ uno::Any aRet = cppu::queryInterface( rType,
+ SAL_STATIC_CAST( io::XInputStream*,this ),
+ SAL_STATIC_CAST( io::XSeekable*,this ) );
+ return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
+}
+
+
+void SAL_CALL
+XInputStream_impl::acquire(
+ void )
+ throw( uno::RuntimeException )
+{
+ OWeakObject::acquire();
+}
+
+
+void SAL_CALL
+XInputStream_impl::release(
+ void )
+ throw( uno::RuntimeException )
+{
+ OWeakObject::release();
+}
+
+
+
+sal_Int32 SAL_CALL
+XInputStream_impl::readBytes(
+ uno::Sequence< sal_Int8 >& aData,
+ sal_Int32 nBytesToRead )
+ throw( io::NotConnectedException,
+ io::BufferSizeExceededException,
+ io::IOException,
+ uno::RuntimeException)
+{
+ if( ! m_bIsOpen )
+ throw io::IOException();
+
+ aData.realloc(nBytesToRead);
+ //TODO! translate memory exhaustion (if it were detectable...) into
+ // io::BufferSizeExceededException
+
+ sal_uInt64 nrc;
+ m_aFile.read( aData.getArray(),sal_uInt64(nBytesToRead),nrc );
+
+ // Shrink aData in case we read less than nBytesToRead (XInputStream
+ // documentation does not tell whether this is required, and I do not know
+ // if any code relies on this, so be conservative---SB):
+ if (nrc != nBytesToRead)
+ aData.realloc(sal_Int32(nrc));
+ return ( sal_Int32 ) nrc;
+}
+
+sal_Int32 SAL_CALL
+XInputStream_impl::readSomeBytes(
+ uno::Sequence< sal_Int8 >& aData,
+ sal_Int32 nMaxBytesToRead )
+ throw( io::NotConnectedException,
+ io::BufferSizeExceededException,
+ io::IOException,
+ uno::RuntimeException)
+{
+ return readBytes( aData,nMaxBytesToRead );
+}
+
+
+void SAL_CALL
+XInputStream_impl::skipBytes(
+ sal_Int32 nBytesToSkip )
+ throw( io::NotConnectedException,
+ io::BufferSizeExceededException,
+ io::IOException,
+ uno::RuntimeException)
+{
+ m_aFile.setPos( osl_Pos_Current, sal_uInt64( nBytesToSkip ) );
+}
+
+
+sal_Int32 SAL_CALL
+XInputStream_impl::available(
+ void )
+ throw( io::NotConnectedException,
+ io::IOException,
+ uno::RuntimeException)
+{
+ return 0;
+}
+
+
+void SAL_CALL
+XInputStream_impl::closeInput(
+ void )
+ throw( io::NotConnectedException,
+ io::IOException,
+ uno::RuntimeException )
+{
+ if( m_bIsOpen )
+ {
+ osl::FileBase::RC err = m_aFile.close();
+ if( err != osl::FileBase::E_None )
+ throw io::IOException();
+ m_bIsOpen = false;
+ }
+}
+
+
+void SAL_CALL
+XInputStream_impl::seek(
+ sal_Int64 location )
+ throw( lang::IllegalArgumentException,
+ io::IOException,
+ uno::RuntimeException )
+{
+ if( location < 0 )
+ throw lang::IllegalArgumentException();
+ if( osl::FileBase::E_None != m_aFile.setPos( Pos_Absolut, sal_uInt64( location ) ) )
+ throw io::IOException();
+}
+
+
+sal_Int64 SAL_CALL
+XInputStream_impl::getPosition(
+ void )
+ throw( io::IOException,
+ uno::RuntimeException )
+{
+ sal_uInt64 uPos;
+ if( osl::FileBase::E_None != m_aFile.getPos( uPos ) )
+ throw io::IOException();
+ return sal_Int64( uPos );
+}
+
+sal_Int64 SAL_CALL
+XInputStream_impl::getLength(
+ void )
+ throw( io::IOException,
+ uno::RuntimeException )
+{
+ osl::FileBase::RC err;
+ sal_uInt64 uCurrentPos, uEndPos;
+
+ err = m_aFile.getPos( uCurrentPos );
+ if( err != osl::FileBase::E_None )
+ throw io::IOException();
+
+ err = m_aFile.setPos( Pos_End, 0 );
+ if( err != osl::FileBase::E_None )
+ throw io::IOException();
+
+ err = m_aFile.getPos( uEndPos );
+ if( err != osl::FileBase::E_None )
+ throw io::IOException();
+
+ err = m_aFile.setPos( Pos_Absolut, uCurrentPos );
+ if( err != osl::FileBase::E_None )
+ throw io::IOException();
+ else
+ return sal_Int64( uEndPos );
+}
diff --git a/xmlhelp/source/cxxhelp/provider/inputstream.hxx b/xmlhelp/source/cxxhelp/provider/inputstream.hxx
new file mode 100644
index 000000000000..adf066845ca3
--- /dev/null
+++ b/xmlhelp/source/cxxhelp/provider/inputstream.hxx
@@ -0,0 +1,131 @@
+#ifndef _INPUSTREAM_HXX_
+#define _INPUSTREAM_HXX_
+
+#ifndef _RTL_USTRING_HXX_
+#include <rtl/ustring.hxx>
+#endif
+#ifndef _OSL_FILE_HXX_
+#include <osl/file.hxx>
+#endif
+#ifndef _CPPUHELPER_WEAK_HXX_
+#include <cppuhelper/weak.hxx>
+#endif
+#ifndef _COM_SUN_STAR_UNO_XINTERFACE_HPP_
+#include <com/sun/star/uno/XInterface.hpp>
+#endif
+#ifndef _COM_SUN_STAR_IO_XSEEKABLE_HPP_
+#include <com/sun/star/io/XSeekable.hpp>
+#endif
+#ifndef _COM_SUN_STAR_IO_XINPUTSTREAM_HPP_
+#include <com/sun/star/io/XInputStream.hpp>
+#endif
+#ifndef _COM_SUN_STAR_UCB_XCONTENTPROVIDER_HPP_
+#include <com/sun/star/ucb/XContentProvider.hpp>
+#endif
+
+
+namespace chelp {
+
+ // forward declaration
+
+ class XInputStream_impl
+ : public cppu::OWeakObject,
+ public com::sun::star::io::XInputStream,
+ public com::sun::star::io::XSeekable
+ {
+ public:
+
+ XInputStream_impl( const rtl::OUString& aUncPath );
+
+ virtual ~XInputStream_impl();
+
+ /**
+ * Returns an error code as given by filerror.hxx
+ */
+
+ bool SAL_CALL CtorSuccess();
+
+ virtual com::sun::star::uno::Any SAL_CALL
+ queryInterface(
+ const com::sun::star::uno::Type& rType )
+ throw( com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL
+ acquire(
+ void )
+ throw( com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL
+ release(
+ void )
+ throw( com::sun::star::uno::RuntimeException );
+
+ virtual sal_Int32 SAL_CALL
+ readBytes(
+ com::sun::star::uno::Sequence< sal_Int8 >& aData,
+ sal_Int32 nBytesToRead )
+ throw( com::sun::star::io::NotConnectedException,
+ com::sun::star::io::BufferSizeExceededException,
+ com::sun::star::io::IOException,
+ com::sun::star::uno::RuntimeException);
+
+ virtual sal_Int32 SAL_CALL
+ readSomeBytes(
+ com::sun::star::uno::Sequence< sal_Int8 >& aData,
+ sal_Int32 nMaxBytesToRead )
+ throw( com::sun::star::io::NotConnectedException,
+ com::sun::star::io::BufferSizeExceededException,
+ com::sun::star::io::IOException,
+ com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL
+ skipBytes(
+ sal_Int32 nBytesToSkip )
+ throw( com::sun::star::io::NotConnectedException,
+ com::sun::star::io::BufferSizeExceededException,
+ com::sun::star::io::IOException,
+ com::sun::star::uno::RuntimeException );
+
+ virtual sal_Int32 SAL_CALL
+ available(
+ void )
+ throw( com::sun::star::io::NotConnectedException,
+ com::sun::star::io::IOException,
+ com::sun::star::uno::RuntimeException );
+
+ virtual void SAL_CALL
+ closeInput(
+ void )
+ throw( com::sun::star::io::NotConnectedException,
+ com::sun::star::io::IOException,
+ com::sun::star::uno::RuntimeException );
+
+ virtual void SAL_CALL
+ seek(
+ sal_Int64 location )
+ throw( com::sun::star::lang::IllegalArgumentException,
+ com::sun::star::io::IOException,
+ com::sun::star::uno::RuntimeException );
+
+ virtual sal_Int64 SAL_CALL
+ getPosition(
+ void )
+ throw( com::sun::star::io::IOException,
+ com::sun::star::uno::RuntimeException );
+
+ virtual sal_Int64 SAL_CALL
+ getLength(
+ void )
+ throw( com::sun::star::io::IOException,
+ com::sun::star::uno::RuntimeException );
+
+ private:
+
+ bool m_bIsOpen;
+ osl::File m_aFile;
+ };
+
+
+} // end namespace XInputStream_impl
+
+#endif