summaryrefslogtreecommitdiff
path: root/unotools/source/streaming
diff options
context:
space:
mode:
authorFrank Schönheit <fs@openoffice.org>2001-05-15 06:44:56 +0000
committerFrank Schönheit <fs@openoffice.org>2001-05-15 06:44:56 +0000
commited4d769a620278cf8d08b976f76a51b691e53dd6 (patch)
treeee2f6fa996453c94b896638ed64b40abf55ed734 /unotools/source/streaming
parent947ccdea2ed0cf0204357fa63387f7088a2c14cd (diff)
#85437# +OSeekableInputStreamWrapper
Diffstat (limited to 'unotools/source/streaming')
-rw-r--r--unotools/source/streaming/streamwrap.cxx127
1 files changed, 106 insertions, 21 deletions
diff --git a/unotools/source/streaming/streamwrap.cxx b/unotools/source/streaming/streamwrap.cxx
index 399e78e328e1..28cd5106ba94 100644
--- a/unotools/source/streaming/streamwrap.cxx
+++ b/unotools/source/streaming/streamwrap.cxx
@@ -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));
}