summaryrefslogtreecommitdiff
path: root/configmgr/source
diff options
context:
space:
mode:
authorLars Langhans <lla@openoffice.org>2001-05-31 13:09:46 +0000
committerLars Langhans <lla@openoffice.org>2001-05-31 13:09:46 +0000
commit4d4d0eb61b0a7a940c25351ca4a268c8c4c86cd3 (patch)
tree153d0d86d1d0330087ba2f4ceaff9cc027f5f2d1 /configmgr/source
parent93d14c136d803921a643596acdbc409d4f66911f (diff)
#87337# create a new buffered osl wrapper
Diffstat (limited to 'configmgr/source')
-rw-r--r--configmgr/source/inc/oslstream.hxx28
-rw-r--r--configmgr/source/misc/oslstream.cxx141
2 files changed, 165 insertions, 4 deletions
diff --git a/configmgr/source/inc/oslstream.hxx b/configmgr/source/inc/oslstream.hxx
index 2ba3d12d90d6..f2b67ca654e6 100644
--- a/configmgr/source/inc/oslstream.hxx
+++ b/configmgr/source/inc/oslstream.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: oslstream.hxx,v $
*
- * $Revision: 1.2 $
+ * $Revision: 1.3 $
*
- * last change: $Author: fs $ $Date: 2000-10-25 06:50:58 $
+ * last change: $Author: lla $ $Date: 2001-05-31 14:09:32 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -85,6 +85,7 @@
#include <osl/file.hxx>
#endif
+#include <trivialbufferedfile.hxx>
namespace configmgr
{
@@ -119,6 +120,29 @@ public:
virtual void SAL_CALL closeInput() throw(stario::NotConnectedException, staruno::RuntimeException);
};
+// -----------------------------------------------------------------------------
+class OSLInputBufferedStreamWrapper : public InputStreamWrapper_Base
+{
+ ::osl::Mutex m_aMutex;
+ OTrivialBufferedFile* m_pFile;
+ sal_Bool m_bFileOwner : 1;
+
+public:
+ // OSLInputStreamWrapper(OTrivialBufferedFile& _rStream);
+ OSLInputBufferedStreamWrapper(OTrivialBufferedFile* pStream, sal_Bool bOwner=sal_False);
+ virtual ~OSLInputBufferedStreamWrapper();
+
+// UNO Anbindung
+ DECLARE_UNO3_AGG_DEFAULTS(OSLInputBufferedStreamWrapper, InputStreamWrapper_Base);
+
+// stario::XInputStream
+ virtual sal_Int32 SAL_CALL readBytes(staruno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException);
+ virtual sal_Int32 SAL_CALL readSomeBytes(staruno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException);
+ 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);
+};
+
//==================================================================
// FmUnoOutStream,
// Datensenke fuer Files
diff --git a/configmgr/source/misc/oslstream.cxx b/configmgr/source/misc/oslstream.cxx
index 1fe03b22ec7e..9b3104a63b14 100644
--- a/configmgr/source/misc/oslstream.cxx
+++ b/configmgr/source/misc/oslstream.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: oslstream.cxx,v $
*
- * $Revision: 1.1.1.1 $
+ * $Revision: 1.2 $
*
- * last change: $Author: hr $ $Date: 2000-09-18 16:13:41 $
+ * last change: $Author: lla $ $Date: 2001-05-31 14:09:46 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -234,6 +234,143 @@ void SAL_CALL OSLOutputStreamWrapper::closeOutput() throw( stario::NotConnectedE
rFile.close();
}
+// -----------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
+// ----------------------------- Buffered OSLStream -----------------------------
+// -----------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
+//------------------------------------------------------------------
+/*
+OSLInputBufferedStreamWrapper::OSLInputBufferedStreamWrapper( File& _rFile )
+ :m_pFile(&_rFile)
+ ,m_bFileOwner(sal_False)
+{
+}
+*/
+//------------------------------------------------------------------
+OSLInputBufferedStreamWrapper::OSLInputBufferedStreamWrapper( OTrivialBufferedFile* pStream, sal_Bool bOwner )
+ :m_pFile( pStream )
+ ,m_bFileOwner( bOwner )
+{
+}
+
+//------------------------------------------------------------------
+OSLInputBufferedStreamWrapper::~OSLInputBufferedStreamWrapper()
+{
+ if( m_bFileOwner )
+ delete m_pFile;
+}
+
+//------------------------------------------------------------------------------
+sal_Int32 SAL_CALL OSLInputBufferedStreamWrapper::readBytes(staruno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead)
+ throw( stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException )
+{
+ if (!m_pFile)
+ throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this));
+
+ if (nBytesToRead < 0)
+ throw stario::BufferSizeExceededException(::rtl::OUString(),static_cast<staruno::XWeak*>(this));
+
+ ::osl::MutexGuard aGuard( m_aMutex );
+
+ aData.realloc(nBytesToRead);
+
+ sal_uInt64 nRead = 0;
+ FileBase::RC eError = m_pFile->read((void*)aData.getArray(), nBytesToRead, nRead);
+ if (eError != osl_File_E_None)
+ throw stario::BufferSizeExceededException(::rtl::OUString(),static_cast<staruno::XWeak*>(this));
+
+ // Wenn gelesene Zeichen < MaxLength, staruno::Sequence anpassen
+ if (nRead < (sal_uInt32)nBytesToRead)
+ aData.realloc( nRead );
+
+ return nRead;
+}
+
+//------------------------------------------------------------------------------
+sal_Int32 SAL_CALL OSLInputBufferedStreamWrapper::readSomeBytes(staruno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead) throw( stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException )
+{
+ if (!m_pFile)
+ throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this));
+
+ if (nMaxBytesToRead < 0)
+ throw stario::BufferSizeExceededException(::rtl::OUString(),static_cast<staruno::XWeak*>(this));
+
+ /*
+ if (m_pFile->IsEof())
+ {
+ aData.realloc(0);
+ return 0;
+ }
+ else
+ */
+ return readBytes(aData, nMaxBytesToRead);
+}
+
+//------------------------------------------------------------------------------
+void SAL_CALL OSLInputBufferedStreamWrapper::skipBytes(sal_Int32 nBytesToSkip) throw( stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if (!m_pFile)
+ throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this));
+
+ sal_uInt64 nCurrentPos;
+ m_pFile->getPos(nCurrentPos);
+
+ sal_uInt64 nNewPos = nCurrentPos + nBytesToSkip;
+ FileBase::RC eError = m_pFile->setPos(osl_Pos_Absolut, nNewPos);
+ if (eError != osl_File_E_None)
+ {
+ throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this));
+ }
+
+#ifdef DBG_UTIL
+ m_pFile->getPos(nCurrentPos);
+ volatile int dummy = 0; // to take a look at last changes ;-)
+#endif
+}
+
+//------------------------------------------------------------------------------
+sal_Int32 SAL_CALL OSLInputBufferedStreamWrapper::available() throw( stario::NotConnectedException, staruno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if (!m_pFile)
+ throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this));
+
+ sal_uInt64 nPos;
+ FileBase::RC eError = m_pFile->getPos(nPos);
+ if (eError != osl_File_E_None)
+ throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this));
+
+ sal_uInt64 nDummy = 0;
+ eError = m_pFile->setPos(Pos_End, nDummy);
+ if (eError != osl_File_E_None)
+ throw stario::NotConnectedException(::rtl::OUString(),static_cast<staruno::XWeak*>(this));
+
+ sal_uInt64 nAvailable;
+ eError = m_pFile->getPos(nAvailable);
+ if (eError != osl_File_E_None)
+ throw stario::NotConnectedException(::rtl::OUString(),static_cast<staruno::XWeak*>(this));
+
+ nAvailable = nAvailable - nPos;
+ eError = m_pFile->setPos(Pos_Absolut, nPos);
+ if (eError != osl_File_E_None)
+ throw stario::NotConnectedException(::rtl::OUString(),static_cast<staruno::XWeak*>(this));
+ return nAvailable;
+}
+
+//------------------------------------------------------------------------------
+void SAL_CALL OSLInputBufferedStreamWrapper::closeInput() throw( stario::NotConnectedException, staruno::RuntimeException )
+{
+ if (!m_pFile)
+ throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this));
+
+ m_pFile->close();
+ if (m_bFileOwner)
+ delete m_pFile;
+
+ m_pFile = NULL;
+}
} // namespace configmgr