diff options
author | Frank Schönheit <fs@openoffice.org> | 2000-09-29 10:28:15 +0000 |
---|---|---|
committer | Frank Schönheit <fs@openoffice.org> | 2000-09-29 10:28:15 +0000 |
commit | b83bbfa982ec0bdf93fb96e515ba7e2d053d66e8 (patch) | |
tree | 0bfac8a4080bca433ec6e3892dd3f4c1142593c9 /comphelper/source/streaming | |
parent | dc8ad513eb9af14c133c8984081196eea2df5839 (diff) |
initial import
Diffstat (limited to 'comphelper/source/streaming')
-rw-r--r-- | comphelper/source/streaming/basicio.cxx | 208 | ||||
-rw-r--r-- | comphelper/source/streaming/makefile.mk | 83 | ||||
-rw-r--r-- | comphelper/source/streaming/oslfile2streamwrap.cxx | 228 | ||||
-rw-r--r-- | comphelper/source/streaming/seqstream.cxx | 160 | ||||
-rw-r--r-- | comphelper/source/streaming/streamsection.cxx | 144 |
5 files changed, 823 insertions, 0 deletions
diff --git a/comphelper/source/streaming/basicio.cxx b/comphelper/source/streaming/basicio.cxx new file mode 100644 index 000000000000..56710f46b080 --- /dev/null +++ b/comphelper/source/streaming/basicio.cxx @@ -0,0 +1,208 @@ +/************************************************************************* + * + * $RCSfile: basicio.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_BASIC_IO_HXX_ +#include <comphelper/basicio.hxx> +#endif + +//......................................................................... +namespace comphelper +{ +//......................................................................... + +//------------------------------------------------------------------------------ +const staruno::Reference<stario::XObjectOutputStream>& operator << ( + const staruno::Reference<stario::XObjectOutputStream>& _rxOutStream, + const starawt::FontDescriptor& _rFont) +{ + _rxOutStream->writeUTF( _rFont.Name ); + _rxOutStream->writeShort( _rFont.Height ); + _rxOutStream->writeShort( _rFont.Width ); + _rxOutStream->writeUTF( _rFont.StyleName ); + _rxOutStream->writeShort( _rFont.Family ); + _rxOutStream->writeShort( _rFont.CharSet ); + _rxOutStream->writeShort( _rFont.Pitch ); + _rxOutStream->writeDouble( _rFont.CharacterWidth ); + _rxOutStream->writeDouble( _rFont.Weight ); + _rxOutStream->writeShort( _rFont.Slant ); + _rxOutStream->writeShort( _rFont.Underline ); + _rxOutStream->writeShort( _rFont.Strikeout ); + _rxOutStream->writeDouble( _rFont.Orientation ); + _rxOutStream->writeBoolean( _rFont.Kerning ); + _rxOutStream->writeBoolean( _rFont.WordLineMode ); + _rxOutStream->writeShort( _rFont.Type ); + return _rxOutStream; +} + +// FontDescriptor +//------------------------------------------------------------------------------ +const staruno::Reference<stario::XObjectInputStream>& operator >> ( + const staruno::Reference<stario::XObjectInputStream>& _rxInStream, + starawt::FontDescriptor& _rFont) +{ + // schreiben des Fontdescriptors + _rFont.Name = _rxInStream->readUTF(); + _rFont.Height = _rxInStream->readShort(); + _rFont.Width = _rxInStream->readShort(); + _rFont.StyleName = _rxInStream->readUTF(); + _rFont.Family = _rxInStream->readShort(); + _rFont.CharSet = _rxInStream->readShort(); + _rFont.Pitch = _rxInStream->readShort(); + _rFont.CharacterWidth = _rxInStream->readDouble(); + _rFont.Weight = _rxInStream->readDouble(); + _rFont.Slant = (starawt::FontSlant)_rxInStream->readShort(); + _rFont.Underline = _rxInStream->readShort(); + _rFont.Strikeout = _rxInStream->readShort(); + _rFont.Orientation = _rxInStream->readDouble(); + _rFont.Kerning = _rxInStream->readBoolean(); + _rFont.WordLineMode = _rxInStream->readBoolean(); + _rFont.Type = _rxInStream->readShort(); + return _rxInStream; +} + +//------------------------------------------------------------------------------ +const staruno::Reference<stario::XObjectInputStream>& operator >> (const staruno::Reference<stario::XObjectInputStream>& _rxInStream, sal_Bool& _rVal) +{ + _rVal = _rxInStream->readBoolean(); + return _rxInStream; +} + +//------------------------------------------------------------------------------ +const staruno::Reference<stario::XObjectOutputStream>& operator << (const staruno::Reference<stario::XObjectOutputStream>& _rxOutStream, sal_Bool _bVal) +{ + _rxOutStream->writeBoolean(_bVal); + return _rxOutStream; +} + +//------------------------------------------------------------------------------ +const staruno::Reference<stario::XObjectInputStream>& operator >> (const staruno::Reference<stario::XObjectInputStream>& _rxInStream, ::rtl::OUString& rStr) +{ + rStr = _rxInStream->readUTF(); + return _rxInStream; +} + +//------------------------------------------------------------------------------ +const staruno::Reference<stario::XObjectOutputStream>& operator << (const staruno::Reference<stario::XObjectOutputStream>& _rxOutStream, const ::rtl::OUString& rStr) +{ + _rxOutStream->writeUTF(rStr); + return _rxOutStream; +} + +//------------------------------------------------------------------------------ +const staruno::Reference<stario::XObjectInputStream>& operator >> (const staruno::Reference<stario::XObjectInputStream>& _rxInStream, sal_Int16& _rValue) +{ + _rValue = _rxInStream->readShort(); + return _rxInStream; +} + +//------------------------------------------------------------------------------ +const staruno::Reference<stario::XObjectOutputStream>& operator << (const staruno::Reference<stario::XObjectOutputStream>& _rxOutStream, sal_Int16 _nValue) +{ + _rxOutStream->writeShort(_nValue); + return _rxOutStream; +} + +//------------------------------------------------------------------------------ +const staruno::Reference<stario::XObjectInputStream>& operator >> (const staruno::Reference<stario::XObjectInputStream>& _rxInStream, sal_uInt16& _rValue) +{ + _rValue = _rxInStream->readShort(); + return _rxInStream; +} + +//------------------------------------------------------------------------------ +const staruno::Reference<stario::XObjectOutputStream>& operator << (const staruno::Reference<stario::XObjectOutputStream>& _rxOutStream, sal_uInt16 _nValue) +{ + _rxOutStream->writeShort(_nValue); + return _rxOutStream; +} + +//------------------------------------------------------------------------------ +const staruno::Reference<stario::XObjectInputStream>& operator >> (const staruno::Reference<stario::XObjectInputStream>& _rxInStream, sal_uInt32& _rValue) +{ + _rValue = _rxInStream->readLong(); + return _rxInStream; +} + +//------------------------------------------------------------------------------ +const staruno::Reference<stario::XObjectOutputStream>& operator << (const staruno::Reference<stario::XObjectOutputStream>& _rxOutStream, sal_uInt32 _nValue) +{ + _rxOutStream->writeLong(_nValue); + return _rxOutStream; +} + +//------------------------------------------------------------------------------ +const staruno::Reference<stario::XObjectInputStream>& operator >> (const staruno::Reference<stario::XObjectInputStream>& _rxInStream, sal_Int32& _rValue) +{ + _rValue = _rxInStream->readLong(); + return _rxInStream; +} + +//------------------------------------------------------------------------------ +const staruno::Reference<stario::XObjectOutputStream>& operator << (const staruno::Reference<stario::XObjectOutputStream>& _rxOutStream, sal_Int32 _nValue) +{ + _rxOutStream->writeLong(_nValue); + return _rxOutStream; +} + +//......................................................................... +} // namespace comphelper +//......................................................................... + diff --git a/comphelper/source/streaming/makefile.mk b/comphelper/source/streaming/makefile.mk new file mode 100644 index 000000000000..891c4d5203fd --- /dev/null +++ b/comphelper/source/streaming/makefile.mk @@ -0,0 +1,83 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. +PRJNAME=comphelper +TARGET=streaming + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +# --- Files ------------------------------------- + +SLOFILES= $(SLO)$/basicio.obj \ + $(SLO)$/oslfile2streamwrap.obj \ + $(SLO)$/seqstream.obj \ + $(SLO)$/streamsection.obj \ + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + diff --git a/comphelper/source/streaming/oslfile2streamwrap.cxx b/comphelper/source/streaming/oslfile2streamwrap.cxx new file mode 100644 index 000000000000..03f65286aba7 --- /dev/null +++ b/comphelper/source/streaming/oslfile2streamwrap.cxx @@ -0,0 +1,228 @@ +/************************************************************************* + * + * $RCSfile: oslfile2streamwrap.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_STREAM_OSLFILEWRAPPER_HXX_ +#include <comphelper/oslfile2streamwrap.hxx> +#endif + +namespace comphelper +{ + using namespace osl; + +//------------------------------------------------------------------ +OSLInputStreamWrapper::OSLInputStreamWrapper( File& _rFile ) + :m_pFile(&_rFile) + ,m_bFileOwner(sal_False) +{ +} + +//------------------------------------------------------------------ +OSLInputStreamWrapper::OSLInputStreamWrapper( File* pStream, sal_Bool bOwner ) + :m_pFile( pStream ) + ,m_bFileOwner( bOwner ) +{ +} + +//------------------------------------------------------------------ +OSLInputStreamWrapper::~OSLInputStreamWrapper() +{ + if( m_bFileOwner ) + delete m_pFile; +} + +//------------------------------------------------------------------------------ +sal_Int32 SAL_CALL OSLInputStreamWrapper::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 OSLInputStreamWrapper::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 OSLInputStreamWrapper::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 OSLInputStreamWrapper::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 OSLInputStreamWrapper::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; +} + +/*************************************************************************/ +// stario::XOutputStream +//------------------------------------------------------------------------------ +void SAL_CALL OSLOutputStreamWrapper::writeBytes(const staruno::Sequence< sal_Int8 >& aData) throw( stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException ) +{ + sal_uInt64 nWritten; + FileBase::RC eError = rFile.write(aData.getConstArray(),aData.getLength(), nWritten); + if (eError != osl_File_E_None || nWritten != aData.getLength()) + { + throw stario::BufferSizeExceededException(::rtl::OUString(),static_cast<staruno::XWeak*>(this)); + } +} + +//------------------------------------------------------------------ +void SAL_CALL OSLOutputStreamWrapper::flush() throw( stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException ) +{ +} + +//------------------------------------------------------------------ +void SAL_CALL OSLOutputStreamWrapper::closeOutput() throw( stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException ) +{ + rFile.close(); +} + +} // namespace comphelper + + diff --git a/comphelper/source/streaming/seqstream.cxx b/comphelper/source/streaming/seqstream.cxx new file mode 100644 index 000000000000..469a9a963468 --- /dev/null +++ b/comphelper/source/streaming/seqstream.cxx @@ -0,0 +1,160 @@ +/************************************************************************* + * + * $RCSfile: seqstream.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_SEQSTREAM_HXX +#include <comphelper/seqstream.hxx> +#endif + +#include <memory.h> // for memcpy + +namespace comphelper +{ + +//--------------------------------------------------------------------------------------------- +// class SequenceInputStream +//--------------------------------------------------------------------------------------------- + +//------------------------------------------------------------------ +SequenceInputStream::SequenceInputStream(const ByteSequence& rData) +: m_aData(rData) +, m_nPos(0) +{ +} + +// checks if closed, returns available size, not mutex-protected +//------------------------------------------------------------------ +inline sal_Int32 SequenceInputStream::avail() +{ + if (m_nPos == -1) + throw stario::NotConnectedException(::rtl::OUString(), *this); + + return m_aData.getLength() - m_nPos; +} + +// com::sun::star::io::XInputStream +//------------------------------------------------------------------ +sal_Int32 SAL_CALL SequenceInputStream::readBytes( staruno::Sequence<sal_Int8>& aData, sal_Int32 nBytesToRead ) + throw(stario::NotConnectedException, stario::BufferSizeExceededException, + stario::IOException, staruno::RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + sal_Int32 nAvail = avail(); + + if (nBytesToRead < 0) + throw stario::BufferSizeExceededException(::rtl::OUString(),*this); + + if (nAvail < nBytesToRead) + nBytesToRead = nAvail; + + aData.realloc(nBytesToRead); + memcpy(aData.getArray(), m_aData.getConstArray() + m_nPos, nBytesToRead); + m_nPos += nBytesToRead; + + return nBytesToRead; +} + +//------------------------------------------------------------------ +sal_Int32 SAL_CALL SequenceInputStream::readSomeBytes( staruno::Sequence<sal_Int8>& aData, sal_Int32 nMaxBytesToRead ) + throw(stario::NotConnectedException, stario::BufferSizeExceededException, + stario::IOException, staruno::RuntimeException) +{ + // all data is available at once + return readBytes(aData, nMaxBytesToRead); +} + +//------------------------------------------------------------------ +void SAL_CALL SequenceInputStream::skipBytes( sal_Int32 nBytesToSkip ) + throw(stario::NotConnectedException, stario::BufferSizeExceededException, + stario::IOException, staruno::RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + sal_Int32 nAvail = avail(); + + if (nBytesToSkip < 0) + throw stario::BufferSizeExceededException(::rtl::OUString(),*this); + + if (nAvail < nBytesToSkip) + nBytesToSkip = nAvail; + + m_nPos += nBytesToSkip; +} + +//------------------------------------------------------------------ +sal_Int32 SAL_CALL SequenceInputStream::available( ) + throw(stario::NotConnectedException, stario::IOException, staruno::RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return avail(); +} + +//------------------------------------------------------------------ +void SAL_CALL SequenceInputStream::closeInput( ) + throw(stario::NotConnectedException, stario::IOException, staruno::RuntimeException) +{ + if (m_nPos == -1) + throw stario::NotConnectedException(::rtl::OUString(), *this); + + m_nPos = -1; +} +} // namespace comphelper diff --git a/comphelper/source/streaming/streamsection.cxx b/comphelper/source/streaming/streamsection.cxx new file mode 100644 index 000000000000..3bd940849b4c --- /dev/null +++ b/comphelper/source/streaming/streamsection.cxx @@ -0,0 +1,144 @@ +/************************************************************************* + * + * $RCSfile: streamsection.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: fs $ $Date: 2000-09-29 11:28:15 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COMPHELPER_STREAMSECTION_HXX_ +#include <comphelper/streamsection.hxx> +#endif + +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif + +namespace comphelper +{ + +//------------------------------------------------------------------------- +OStreamSection::OStreamSection(const staruno::Reference< stario::XDataInputStream >& _rxInput) + :m_xInStream(_rxInput) + ,m_xMarkStream(_rxInput, ::com::sun::star::uno::UNO_QUERY) + ,m_nBlockStart(-1) + ,m_nBlockLen(-1) +{ + OSL_ENSHURE(m_xInStream.is() && m_xMarkStream.is(), "OStreamSection::OStreamSection : invalid argument !"); + if (m_xInStream.is() && m_xMarkStream.is()) + { + m_nBlockLen = _rxInput->readLong(); + m_nBlockStart = m_xMarkStream->createMark(); + } +} + +//------------------------------------------------------------------------- +OStreamSection::OStreamSection(const staruno::Reference< stario::XDataOutputStream >& _rxOutput, sal_Int32 _nPresumedLength) + :m_xOutStream(_rxOutput) + ,m_xMarkStream(_rxOutput, ::com::sun::star::uno::UNO_QUERY) + ,m_nBlockStart(-1) + ,m_nBlockLen(-1) +{ + OSL_ENSHURE(m_xOutStream.is() && m_xMarkStream.is(), "OStreamSection::OStreamSection : invalid argument !"); + if (m_xOutStream.is() && m_xMarkStream.is()) + { + m_nBlockStart = m_xMarkStream->createMark(); + // a placeholder where we will write the overall length (within the destructor) + if (_nPresumedLength > 0) + m_nBlockLen = _nPresumedLength + sizeof(m_nBlockLen); + // as the caller did not consider - of course - the placeholder we are going to write + else + m_nBlockLen = 0; + m_xOutStream->writeLong(m_nBlockLen); + } +} + +//------------------------------------------------------------------------- +OStreamSection::~OStreamSection() +{ + try + { // don't allow any exceptions to leave this block, this may be called during the stack unwinding of an exception + // handling routing + if (m_xInStream.is() && m_xMarkStream.is()) + { // we're working on an input stream + m_xMarkStream->jumpToMark(m_nBlockStart); + m_xInStream->skipBytes(m_nBlockLen); + m_xMarkStream->deleteMark(m_nBlockStart); + } + else if (m_xOutStream.is() && m_xMarkStream.is()) + { + sal_Int32 nRealBlockLength = m_xMarkStream->offsetToMark(m_nBlockStart) - sizeof(m_nBlockLen); + if (m_nBlockLen && (m_nBlockLen == nRealBlockLength)) + // nothing to do : the estimation the caller gave us (in the ctor) was correct + m_xMarkStream->deleteMark(m_nBlockStart); + else + { // the estimation was wrong (or we didn't get one) + m_nBlockLen = nRealBlockLength; + m_xMarkStream->jumpToMark(m_nBlockStart); + m_xOutStream->writeLong(m_nBlockLen); + m_xMarkStream->jumpToFurthest(); + m_xMarkStream->deleteMark(m_nBlockStart); + } + } + } + catch(...) + { + } +} + +} // namespace comphelper + + |