#85437# +OSeekableInputStreamWrapper

This commit is contained in:
Frank Schönheit 2001-05-15 06:44:56 +00:00
parent 947ccdea2e
commit ed4d769a62
2 changed files with 148 additions and 28 deletions

View file

@ -2,9 +2,9 @@
*
* $RCSfile: streamwrap.hxx,v $
*
* $Revision: 1.2 $
* $Revision: 1.3 $
*
* last change: $Author: hr $ $Date: 2000-11-07 09:53:22 $
* last change: $Author: fs $ $Date: 2001-05-15 07:44:17 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@ -71,6 +71,9 @@
#ifndef _COM_SUN_STAR_IO_XINPUTSTREAM_HPP_
#include <com/sun/star/io/XInputStream.hpp>
#endif
#ifndef _COM_SUN_STAR_IO_XSEEKABLE_HPP_
#include <com/sun/star/io/XSeekable.hpp>
#endif
#ifndef _CPPUHELPER_IMPLBASE1_HXX_
#include <cppuhelper/implbase1.hxx>
@ -88,13 +91,15 @@ namespace utl
namespace staruno = ::com::sun::star::uno;
//==================================================================
// FmUnoIOStream,
// stream zum schreiben un lesen von Daten, basieren auf svstream
//= OInputStreamWrapper
//==================================================================
typedef ::cppu::WeakImplHelper1<stario::XInputStream> InputStreamWrapper_Base;
typedef ::cppu::WeakImplHelper1 < stario::XInputStream
> InputStreamWrapper_Base;
// needed for some compilers
/// helper class for wrapping an SvStream into an <type scope="com.sun.star.io">XInputStream</type>
class OInputStreamWrapper : public InputStreamWrapper_Base
{
protected:
::osl::Mutex m_aMutex;
SvStream* m_pSvStream;
sal_Bool m_bSvStreamOwner : 1;
@ -113,11 +118,41 @@ public:
virtual void SAL_CALL skipBytes(sal_Int32 nBytesToSkip) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException);
virtual sal_Int32 SAL_CALL available() throw(stario::NotConnectedException, staruno::RuntimeException);
virtual void SAL_CALL closeInput() throw(stario::NotConnectedException, staruno::RuntimeException);
protected:
/// throws an exception according to the error flag of m_pSvStream
void checkError();
};
//==================================================================
// FmUnoOutStream,
// Datensenke fuer SvStreams
//= OSeekableInputStreamWrapper
//==================================================================
typedef ::cppu::ImplHelper1 < ::com::sun::star::io::XSeekable
> OSeekableInputStreamWrapper_Base;
/** helper class for wrapping an SvStream into an <type scope="com.sun.star.io">XInputStream</type>
which is seekable (i.e. supports the <type scope="com.sun.star.io">XSeekable</type> interface).
*/
class OSeekableInputStreamWrapper
:public OInputStreamWrapper
,public OSeekableInputStreamWrapper_Base
{
public:
OSeekableInputStreamWrapper(SvStream& _rStream);
OSeekableInputStreamWrapper(SvStream* _pStream, sal_Bool _bOwner = sal_False);
// disambiguate XInterface
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( ) throw ();
virtual void SAL_CALL release( ) throw ();
// XSeekable
virtual void SAL_CALL seek( sal_Int64 _nLocation ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
virtual sal_Int64 SAL_CALL getPosition( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
virtual sal_Int64 SAL_CALL getLength( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
};
//==================================================================
//= OOutputStreamWrapper
//==================================================================
typedef ::cppu::WeakImplHelper1<stario::XOutputStream> OutputStreamWrapper_Base;
// needed for some compilers

View file

@ -2,9 +2,9 @@
*
* $RCSfile: streamwrap.cxx,v $
*
* $Revision: 1.1.1.1 $
* $Revision: 1.2 $
*
* last change: $Author: hr $ $Date: 2000-09-18 17:03:55 $
* last change: $Author: fs $ $Date: 2001-05-15 07:44:56 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@ -73,6 +73,13 @@
namespace utl
{
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::io;
using namespace ::com::sun::star::lang;
//==================================================================
//= OInputStreamWrapper
//==================================================================
DBG_NAME(OInputStreamWrapper)
//------------------------------------------------------------------
OInputStreamWrapper::OInputStreamWrapper( SvStream& _rStream )
@ -116,8 +123,7 @@ sal_Int32 SAL_CALL OInputStreamWrapper::readBytes(staruno::Sequence< sal_Int8 >&
aData.realloc(nBytesToRead);
sal_uInt32 nRead = m_pSvStream->Read((void*)aData.getArray(), nBytesToRead);
if (m_pSvStream->SvStream::GetError() != ERRCODE_NONE)
throw stario::BufferSizeExceededException(::rtl::OUString(),static_cast<staruno::XWeak*>(this));
checkError();
// Wenn gelesene Zeichen < MaxLength, staruno::Sequence anpassen
if (nRead < (sal_uInt32)nBytesToRead)
@ -129,8 +135,7 @@ sal_Int32 SAL_CALL OInputStreamWrapper::readBytes(staruno::Sequence< sal_Int8 >&
//------------------------------------------------------------------------------
sal_Int32 SAL_CALL OInputStreamWrapper::readSomeBytes(staruno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead) throw( stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException )
{
if (!m_pSvStream)
throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this));
checkError();
if (nMaxBytesToRead < 0)
throw stario::BufferSizeExceededException(::rtl::OUString(),static_cast<staruno::XWeak*>(this));
@ -148,18 +153,14 @@ sal_Int32 SAL_CALL OInputStreamWrapper::readSomeBytes(staruno::Sequence< sal_Int
void SAL_CALL OInputStreamWrapper::skipBytes(sal_Int32 nBytesToSkip) throw( stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException )
{
::osl::MutexGuard aGuard( m_aMutex );
if (!m_pSvStream)
throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this));
checkError();
#ifdef DBG_UTIL
sal_uInt32 nCurrentPos = m_pSvStream->Tell();
#endif
m_pSvStream->SeekRel(nBytesToSkip);
if (m_pSvStream->SvStream::GetError() != ERRCODE_NONE)
{
throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this));
}
checkError();
#ifdef DBG_UTIL
nCurrentPos = m_pSvStream->Tell();
@ -174,17 +175,15 @@ sal_Int32 SAL_CALL OInputStreamWrapper::available() throw( stario::NotConnectedE
throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this));
sal_uInt32 nPos = m_pSvStream->Tell();
if (m_pSvStream->SvStream::GetError())
throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this));
checkError();
m_pSvStream->Seek(STREAM_SEEK_TO_END);
if (m_pSvStream->SvStream::GetError())
throw stario::NotConnectedException(::rtl::OUString(),static_cast<staruno::XWeak*>(this));
checkError();
sal_Int32 nAvailable = (sal_Int32)m_pSvStream->Tell() - nPos;
m_pSvStream->Seek(nPos);
if (m_pSvStream->SvStream::GetError())
throw stario::NotConnectedException(::rtl::OUString(),static_cast<staruno::XWeak*>(this));
checkError();
return nAvailable;
}
@ -200,14 +199,100 @@ void SAL_CALL OInputStreamWrapper::closeInput() throw( stario::NotConnectedExcep
m_pSvStream = NULL;
}
/*************************************************************************/
// stario::XOutputStream
//------------------------------------------------------------------------------
void OInputStreamWrapper::checkError()
{
if (!m_pSvStream)
throw stario::NotConnectedException(::rtl::OUString(),static_cast<staruno::XWeak*>(this));
if (m_pSvStream->SvStream::GetError() != ERRCODE_NONE)
// TODO: really evaluate the error
throw stario::NotConnectedException(::rtl::OUString(),static_cast<staruno::XWeak*>(this));
}
//==================================================================
//= OSeekableInputStreamWrapper
//==================================================================
//------------------------------------------------------------------------------
OSeekableInputStreamWrapper::OSeekableInputStreamWrapper(SvStream& _rStream)
:OInputStreamWrapper(_rStream)
{
}
//------------------------------------------------------------------------------
OSeekableInputStreamWrapper::OSeekableInputStreamWrapper(SvStream* _pStream, sal_Bool _bOwner)
:OInputStreamWrapper(_pStream, _bOwner)
{
}
//------------------------------------------------------------------------------
Any SAL_CALL OSeekableInputStreamWrapper::queryInterface( const Type& _rType ) throw (RuntimeException)
{
Any aReturn = OInputStreamWrapper::queryInterface(_rType);
if (!aReturn.hasValue())
aReturn = OSeekableInputStreamWrapper_Base::queryInterface(_rType);
return aReturn;
}
//------------------------------------------------------------------------------
void SAL_CALL OSeekableInputStreamWrapper::acquire( ) throw ()
{
OInputStreamWrapper::acquire();
}
//------------------------------------------------------------------------------
void SAL_CALL OSeekableInputStreamWrapper::release( ) throw ()
{
OInputStreamWrapper::release();
}
//------------------------------------------------------------------------------
void SAL_CALL OSeekableInputStreamWrapper::seek( sal_Int64 _nLocation ) throw (IllegalArgumentException, IOException, RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
m_pSvStream->Seek((sal_uInt32)_nLocation);
checkError();
}
//------------------------------------------------------------------------------
sal_Int64 SAL_CALL OSeekableInputStreamWrapper::getPosition( ) throw (IOException, RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
sal_uInt32 nPos = m_pSvStream->Tell();
checkError();
return (sal_Int64)nPos;
}
//------------------------------------------------------------------------------
sal_Int64 SAL_CALL OSeekableInputStreamWrapper::getLength( ) throw (IOException, RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
sal_uInt32 nCurrentPos = m_pSvStream->Tell();
checkError();
m_pSvStream->Seek(STREAM_SEEK_TO_END);
sal_uInt32 nEndPos = m_pSvStream->Tell();
m_pSvStream->Seek(nCurrentPos);
checkError();
return (sal_Int64)nEndPos;
}
//==================================================================
//= OOutputStreamWrapper
//==================================================================
//------------------------------------------------------------------------------
void SAL_CALL OOutputStreamWrapper::writeBytes(const staruno::Sequence< sal_Int8 >& aData) throw( stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException )
{
sal_uInt32 nWritten = rStream.Write(aData.getConstArray(),aData.getLength());
ErrCode err = rStream.GetError();
if (err != ERRCODE_NONE || nWritten != aData.getLength())
if ( (ERRCODE_NONE != err)
|| (nWritten != (sal_uInt32)aData.getLength())
)
{
throw stario::BufferSizeExceededException(::rtl::OUString(),static_cast<staruno::XWeak*>(this));
}