1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_io.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir // streams 33*cdf0e10cSrcweir #include <hash_map> 34*cdf0e10cSrcweir #include <vector> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include <com/sun/star/io/XObjectInputStream.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/io/XObjectOutputStream.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSource.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSink.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/io/XMarkableStream.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/io/XConnectable.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/io/UnexpectedEOFException.hpp> 43*cdf0e10cSrcweir #include <com/sun/star/io/WrongFormatException.hpp> 44*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir #include <cppuhelper/weak.hxx> // OWeakObject 47*cdf0e10cSrcweir #include <cppuhelper/factory.hxx> 48*cdf0e10cSrcweir #include <cppuhelper/implbase4.hxx> 49*cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx> 50*cdf0e10cSrcweir #include <cppuhelper/queryinterface.hxx> 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir #include <osl/mutex.hxx> 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir #include <string.h> 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir using namespace ::cppu; 58*cdf0e10cSrcweir using namespace ::osl; 59*cdf0e10cSrcweir using namespace ::std; 60*cdf0e10cSrcweir using namespace ::rtl; 61*cdf0e10cSrcweir using namespace ::com::sun::star::io; 62*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 63*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir #include "factreg.hxx" 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir namespace io_stm { 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir class ODataInputStream : 70*cdf0e10cSrcweir public WeakImplHelper4 < 71*cdf0e10cSrcweir XDataInputStream, 72*cdf0e10cSrcweir XActiveDataSink, 73*cdf0e10cSrcweir XConnectable, 74*cdf0e10cSrcweir XServiceInfo 75*cdf0e10cSrcweir > 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir public: 78*cdf0e10cSrcweir ODataInputStream( ) 79*cdf0e10cSrcweir : m_bValidStream( sal_False ) 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir ~ODataInputStream(); 85*cdf0e10cSrcweir public: // XInputStream 86*cdf0e10cSrcweir virtual sal_Int32 SAL_CALL readBytes(Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead) 87*cdf0e10cSrcweir throw ( NotConnectedException, 88*cdf0e10cSrcweir BufferSizeExceededException, 89*cdf0e10cSrcweir RuntimeException); 90*cdf0e10cSrcweir virtual sal_Int32 SAL_CALL readSomeBytes(Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead) 91*cdf0e10cSrcweir throw ( NotConnectedException, 92*cdf0e10cSrcweir BufferSizeExceededException, 93*cdf0e10cSrcweir RuntimeException); 94*cdf0e10cSrcweir virtual void SAL_CALL skipBytes(sal_Int32 nBytesToSkip) throw ( NotConnectedException, 95*cdf0e10cSrcweir BufferSizeExceededException, 96*cdf0e10cSrcweir RuntimeException); 97*cdf0e10cSrcweir virtual sal_Int32 SAL_CALL available(void) throw ( NotConnectedException, 98*cdf0e10cSrcweir RuntimeException); 99*cdf0e10cSrcweir virtual void SAL_CALL closeInput(void) throw ( NotConnectedException, 100*cdf0e10cSrcweir RuntimeException); 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir public: // XDataInputStream 103*cdf0e10cSrcweir virtual sal_Int8 SAL_CALL readBoolean(void) throw (IOException, RuntimeException); 104*cdf0e10cSrcweir virtual sal_Int8 SAL_CALL readByte(void) throw (IOException, RuntimeException); 105*cdf0e10cSrcweir virtual sal_Unicode SAL_CALL readChar(void) throw (IOException, RuntimeException); 106*cdf0e10cSrcweir virtual sal_Int16 SAL_CALL readShort(void) throw (IOException, RuntimeException); 107*cdf0e10cSrcweir virtual sal_Int32 SAL_CALL readLong(void) throw (IOException, RuntimeException); 108*cdf0e10cSrcweir virtual sal_Int64 SAL_CALL readHyper(void) throw (IOException, RuntimeException); 109*cdf0e10cSrcweir virtual float SAL_CALL readFloat(void) throw (IOException, RuntimeException); 110*cdf0e10cSrcweir virtual double SAL_CALL readDouble(void) throw (IOException, RuntimeException); 111*cdf0e10cSrcweir virtual OUString SAL_CALL readUTF(void) throw (IOException, RuntimeException); 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir public: // XActiveDataSink 116*cdf0e10cSrcweir virtual void SAL_CALL setInputStream(const Reference< XInputStream > & aStream) 117*cdf0e10cSrcweir throw (RuntimeException); 118*cdf0e10cSrcweir virtual Reference< XInputStream > SAL_CALL getInputStream(void) throw (RuntimeException); 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir public: // XConnectable 121*cdf0e10cSrcweir virtual void SAL_CALL setPredecessor(const Reference < XConnectable >& aPredecessor) throw (RuntimeException); 122*cdf0e10cSrcweir virtual Reference < XConnectable > SAL_CALL getPredecessor(void) throw (RuntimeException); 123*cdf0e10cSrcweir virtual void SAL_CALL setSuccessor(const Reference < XConnectable >& aSuccessor) throw (RuntimeException); 124*cdf0e10cSrcweir virtual Reference < XConnectable > SAL_CALL getSuccessor(void) throw (RuntimeException) ; 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir public: // XServiceInfo 128*cdf0e10cSrcweir OUString SAL_CALL getImplementationName() throw (); 129*cdf0e10cSrcweir Sequence< OUString > SAL_CALL getSupportedServiceNames(void) throw (); 130*cdf0e10cSrcweir sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw (); 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir protected: 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir Reference < XConnectable > m_pred; 135*cdf0e10cSrcweir Reference < XConnectable > m_succ; 136*cdf0e10cSrcweir Reference < XInputStream > m_input; 137*cdf0e10cSrcweir sal_Bool m_bValidStream; 138*cdf0e10cSrcweir }; 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir ODataInputStream::~ODataInputStream() 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir // XInputStream 146*cdf0e10cSrcweir sal_Int32 ODataInputStream::readBytes(Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead) 147*cdf0e10cSrcweir throw ( NotConnectedException, 148*cdf0e10cSrcweir BufferSizeExceededException, 149*cdf0e10cSrcweir RuntimeException) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir sal_Int32 nRead; 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir if( m_bValidStream ) 154*cdf0e10cSrcweir { 155*cdf0e10cSrcweir nRead = m_input->readBytes( aData , nBytesToRead ); 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir else 158*cdf0e10cSrcweir { 159*cdf0e10cSrcweir throw NotConnectedException( ); 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir return nRead; 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir sal_Int32 ODataInputStream::readSomeBytes(Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead) 166*cdf0e10cSrcweir throw ( NotConnectedException, 167*cdf0e10cSrcweir BufferSizeExceededException, 168*cdf0e10cSrcweir RuntimeException) 169*cdf0e10cSrcweir { 170*cdf0e10cSrcweir sal_Int32 nRead; 171*cdf0e10cSrcweir if( m_bValidStream ) { 172*cdf0e10cSrcweir nRead = m_input->readSomeBytes( aData , nMaxBytesToRead ); 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir else { 175*cdf0e10cSrcweir throw NotConnectedException( ); 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir return nRead; 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir void ODataInputStream::skipBytes(sal_Int32 nBytesToSkip) 181*cdf0e10cSrcweir throw ( NotConnectedException, 182*cdf0e10cSrcweir BufferSizeExceededException, 183*cdf0e10cSrcweir RuntimeException) 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir if( m_bValidStream ) { 186*cdf0e10cSrcweir m_input->skipBytes( nBytesToSkip ); 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir else 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir throw NotConnectedException( ); 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir sal_Int32 ODataInputStream::available(void) 196*cdf0e10cSrcweir throw ( NotConnectedException, 197*cdf0e10cSrcweir RuntimeException) 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir sal_Int32 nAvail; 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir if( m_bValidStream ) 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir nAvail = m_input->available( ); 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir else 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir throw NotConnectedException( ); 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir return nAvail; 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir void ODataInputStream::closeInput(void ) 213*cdf0e10cSrcweir throw ( NotConnectedException, 214*cdf0e10cSrcweir RuntimeException) 215*cdf0e10cSrcweir { 216*cdf0e10cSrcweir if( m_bValidStream ) { 217*cdf0e10cSrcweir m_input->closeInput( ); 218*cdf0e10cSrcweir setInputStream( Reference< XInputStream > () ); 219*cdf0e10cSrcweir setPredecessor( Reference < XConnectable >() ); 220*cdf0e10cSrcweir setSuccessor( Reference < XConnectable >() ); 221*cdf0e10cSrcweir m_bValidStream = sal_False; 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir else 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir throw NotConnectedException( ); 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir //== XDataInputStream =========================================== 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir // XDataInputStream 235*cdf0e10cSrcweir sal_Int8 ODataInputStream::readBoolean(void) throw (IOException, RuntimeException) 236*cdf0e10cSrcweir { 237*cdf0e10cSrcweir return readByte(); 238*cdf0e10cSrcweir } 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir sal_Int8 ODataInputStream::readByte(void) throw (IOException, RuntimeException) 241*cdf0e10cSrcweir { 242*cdf0e10cSrcweir Sequence<sal_Int8> aTmp(1); 243*cdf0e10cSrcweir if( 1 != readBytes( aTmp, 1 ) ) 244*cdf0e10cSrcweir { 245*cdf0e10cSrcweir throw UnexpectedEOFException(); 246*cdf0e10cSrcweir } 247*cdf0e10cSrcweir return aTmp.getArray()[0]; 248*cdf0e10cSrcweir } 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir sal_Unicode ODataInputStream::readChar(void) throw (IOException, RuntimeException) 251*cdf0e10cSrcweir { 252*cdf0e10cSrcweir Sequence<sal_Int8> aTmp(2); 253*cdf0e10cSrcweir if( 2 != readBytes( aTmp, 2 ) ) 254*cdf0e10cSrcweir { 255*cdf0e10cSrcweir throw UnexpectedEOFException(); 256*cdf0e10cSrcweir } 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir const sal_uInt8 * pBytes = ( const sal_uInt8 * )aTmp.getConstArray(); 259*cdf0e10cSrcweir return ((sal_Unicode)pBytes[0] << 8) + pBytes[1]; 260*cdf0e10cSrcweir } 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir sal_Int16 ODataInputStream::readShort(void) throw (IOException, RuntimeException) 263*cdf0e10cSrcweir { 264*cdf0e10cSrcweir Sequence<sal_Int8> aTmp(2); 265*cdf0e10cSrcweir if( 2 != readBytes( aTmp, 2 ) ) 266*cdf0e10cSrcweir { 267*cdf0e10cSrcweir throw UnexpectedEOFException(); 268*cdf0e10cSrcweir } 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir const sal_uInt8 * pBytes = ( const sal_uInt8 * ) aTmp.getConstArray(); 271*cdf0e10cSrcweir return ((sal_Int16)pBytes[0] << 8) + pBytes[1]; 272*cdf0e10cSrcweir } 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir sal_Int32 ODataInputStream::readLong(void) throw (IOException, RuntimeException) 276*cdf0e10cSrcweir { 277*cdf0e10cSrcweir Sequence<sal_Int8> aTmp(4); 278*cdf0e10cSrcweir if( 4 != readBytes( aTmp, 4 ) ) 279*cdf0e10cSrcweir { 280*cdf0e10cSrcweir throw UnexpectedEOFException( ); 281*cdf0e10cSrcweir } 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir const sal_uInt8 * pBytes = ( const sal_uInt8 * ) aTmp.getConstArray(); 284*cdf0e10cSrcweir return ((sal_Int32)pBytes[0] << 24) + ((sal_Int32)pBytes[1] << 16) + ((sal_Int32)pBytes[2] << 8) + pBytes[3]; 285*cdf0e10cSrcweir } 286*cdf0e10cSrcweir 287*cdf0e10cSrcweir 288*cdf0e10cSrcweir sal_Int64 ODataInputStream::readHyper(void) throw (IOException, RuntimeException) 289*cdf0e10cSrcweir { 290*cdf0e10cSrcweir Sequence<sal_Int8> aTmp(8); 291*cdf0e10cSrcweir if( 8 != readBytes( aTmp, 8 ) ) 292*cdf0e10cSrcweir { 293*cdf0e10cSrcweir throw UnexpectedEOFException( ); 294*cdf0e10cSrcweir } 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir const sal_uInt8 * pBytes = ( const sal_uInt8 * ) aTmp.getConstArray(); 297*cdf0e10cSrcweir return 298*cdf0e10cSrcweir (((sal_Int64)pBytes[0]) << 56) + 299*cdf0e10cSrcweir (((sal_Int64)pBytes[1]) << 48) + 300*cdf0e10cSrcweir (((sal_Int64)pBytes[2]) << 40) + 301*cdf0e10cSrcweir (((sal_Int64)pBytes[3]) << 32) + 302*cdf0e10cSrcweir (((sal_Int64)pBytes[4]) << 24) + 303*cdf0e10cSrcweir (((sal_Int64)pBytes[5]) << 16) + 304*cdf0e10cSrcweir (((sal_Int64)pBytes[6]) << 8) + 305*cdf0e10cSrcweir pBytes[7]; 306*cdf0e10cSrcweir } 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir float ODataInputStream::readFloat(void) throw (IOException, RuntimeException) 309*cdf0e10cSrcweir { 310*cdf0e10cSrcweir union { float f; sal_uInt32 n; } a; 311*cdf0e10cSrcweir a.n = readLong(); 312*cdf0e10cSrcweir return a.f; 313*cdf0e10cSrcweir } 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir double ODataInputStream::readDouble(void) throw (IOException, RuntimeException) 316*cdf0e10cSrcweir { 317*cdf0e10cSrcweir sal_uInt32 n = 1; 318*cdf0e10cSrcweir union { double d; struct { sal_uInt32 n1; sal_uInt32 n2; } ad; } a; 319*cdf0e10cSrcweir if( *(sal_uInt8 *)&n == 1 ) 320*cdf0e10cSrcweir { 321*cdf0e10cSrcweir // little endian 322*cdf0e10cSrcweir a.ad.n2 = readLong(); 323*cdf0e10cSrcweir a.ad.n1 = readLong(); 324*cdf0e10cSrcweir } 325*cdf0e10cSrcweir else 326*cdf0e10cSrcweir { 327*cdf0e10cSrcweir // big endian 328*cdf0e10cSrcweir a.ad.n1 = readLong(); 329*cdf0e10cSrcweir a.ad.n2 = readLong(); 330*cdf0e10cSrcweir } 331*cdf0e10cSrcweir return a.d; 332*cdf0e10cSrcweir } 333*cdf0e10cSrcweir 334*cdf0e10cSrcweir OUString ODataInputStream::readUTF(void) throw (IOException, RuntimeException) 335*cdf0e10cSrcweir { 336*cdf0e10cSrcweir sal_uInt16 nShortLen = (sal_uInt16)readShort(); 337*cdf0e10cSrcweir sal_Int32 nUTFLen; 338*cdf0e10cSrcweir 339*cdf0e10cSrcweir if( ((sal_uInt16)0xffff) == nShortLen ) 340*cdf0e10cSrcweir { 341*cdf0e10cSrcweir // is interpreted as a sign, that string is longer than 64k 342*cdf0e10cSrcweir // incompatible to older XDataInputStream-routines, when strings are exactly 64k 343*cdf0e10cSrcweir nUTFLen = readLong(); 344*cdf0e10cSrcweir } 345*cdf0e10cSrcweir else 346*cdf0e10cSrcweir { 347*cdf0e10cSrcweir nUTFLen = ( sal_Int32 ) nShortLen; 348*cdf0e10cSrcweir } 349*cdf0e10cSrcweir 350*cdf0e10cSrcweir Sequence<sal_Unicode> aBuffer( nUTFLen ); 351*cdf0e10cSrcweir sal_Unicode * pStr = aBuffer.getArray(); 352*cdf0e10cSrcweir 353*cdf0e10cSrcweir sal_Int32 nCount = 0; 354*cdf0e10cSrcweir sal_Int32 nStrLen = 0; 355*cdf0e10cSrcweir while( nCount < nUTFLen ) 356*cdf0e10cSrcweir { 357*cdf0e10cSrcweir sal_uInt8 c = (sal_uInt8)readByte(); 358*cdf0e10cSrcweir sal_uInt8 char2, char3; 359*cdf0e10cSrcweir switch( c >> 4 ) 360*cdf0e10cSrcweir { 361*cdf0e10cSrcweir case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: 362*cdf0e10cSrcweir // 0xxxxxxx 363*cdf0e10cSrcweir nCount++; 364*cdf0e10cSrcweir pStr[nStrLen++] = c; 365*cdf0e10cSrcweir break; 366*cdf0e10cSrcweir 367*cdf0e10cSrcweir case 12: case 13: 368*cdf0e10cSrcweir // 110x xxxx 10xx xxxx 369*cdf0e10cSrcweir nCount += 2; 370*cdf0e10cSrcweir if( ! ( nCount <= nUTFLen ) ) 371*cdf0e10cSrcweir { 372*cdf0e10cSrcweir throw WrongFormatException( ); 373*cdf0e10cSrcweir } 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir char2 = (sal_uInt8)readByte(); 376*cdf0e10cSrcweir if( ! ( (char2 & 0xC0) == 0x80 ) ) 377*cdf0e10cSrcweir { 378*cdf0e10cSrcweir throw WrongFormatException( ); 379*cdf0e10cSrcweir } 380*cdf0e10cSrcweir 381*cdf0e10cSrcweir pStr[nStrLen++] = (sal_Unicode(c & 0x1F) << 6) | (char2 & 0x3F); 382*cdf0e10cSrcweir break; 383*cdf0e10cSrcweir 384*cdf0e10cSrcweir case 14: 385*cdf0e10cSrcweir // 1110 xxxx 10xx xxxx 10xx xxxx 386*cdf0e10cSrcweir nCount += 3; 387*cdf0e10cSrcweir if( !( nCount <= nUTFLen) ) 388*cdf0e10cSrcweir { 389*cdf0e10cSrcweir throw WrongFormatException( ); 390*cdf0e10cSrcweir } 391*cdf0e10cSrcweir 392*cdf0e10cSrcweir char2 = (sal_uInt8)readByte(); 393*cdf0e10cSrcweir char3 = (sal_uInt8)readByte(); 394*cdf0e10cSrcweir 395*cdf0e10cSrcweir if( (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80)) ) { 396*cdf0e10cSrcweir throw WrongFormatException( ); 397*cdf0e10cSrcweir } 398*cdf0e10cSrcweir pStr[nStrLen++] = (sal_Unicode(c & 0x0F) << 12) | 399*cdf0e10cSrcweir (sal_Unicode(char2 & 0x3F) << 6) | 400*cdf0e10cSrcweir (char3 & 0x3F); 401*cdf0e10cSrcweir break; 402*cdf0e10cSrcweir 403*cdf0e10cSrcweir default: 404*cdf0e10cSrcweir // 10xx xxxx, 1111 xxxx 405*cdf0e10cSrcweir throw WrongFormatException(); 406*cdf0e10cSrcweir //throw new UTFDataFormatException(); 407*cdf0e10cSrcweir } 408*cdf0e10cSrcweir } 409*cdf0e10cSrcweir return OUString( pStr, nStrLen ); 410*cdf0e10cSrcweir } 411*cdf0e10cSrcweir 412*cdf0e10cSrcweir 413*cdf0e10cSrcweir 414*cdf0e10cSrcweir // XActiveDataSource 415*cdf0e10cSrcweir void ODataInputStream::setInputStream(const Reference< XInputStream > & aStream) 416*cdf0e10cSrcweir throw (RuntimeException) 417*cdf0e10cSrcweir { 418*cdf0e10cSrcweir 419*cdf0e10cSrcweir if( m_input != aStream ) { 420*cdf0e10cSrcweir m_input = aStream; 421*cdf0e10cSrcweir 422*cdf0e10cSrcweir Reference < XConnectable > pred( m_input , UNO_QUERY ); 423*cdf0e10cSrcweir setPredecessor( pred ); 424*cdf0e10cSrcweir } 425*cdf0e10cSrcweir 426*cdf0e10cSrcweir m_bValidStream = m_input.is(); 427*cdf0e10cSrcweir } 428*cdf0e10cSrcweir 429*cdf0e10cSrcweir Reference< XInputStream > ODataInputStream::getInputStream(void) throw (RuntimeException) 430*cdf0e10cSrcweir { 431*cdf0e10cSrcweir return m_input; 432*cdf0e10cSrcweir } 433*cdf0e10cSrcweir 434*cdf0e10cSrcweir 435*cdf0e10cSrcweir 436*cdf0e10cSrcweir // XDataSink 437*cdf0e10cSrcweir void ODataInputStream::setSuccessor( const Reference < XConnectable > &r ) throw (RuntimeException) 438*cdf0e10cSrcweir { 439*cdf0e10cSrcweir /// if the references match, nothing needs to be done 440*cdf0e10cSrcweir if( m_succ != r ) { 441*cdf0e10cSrcweir /// store the reference for later use 442*cdf0e10cSrcweir m_succ = r; 443*cdf0e10cSrcweir 444*cdf0e10cSrcweir if( m_succ.is() ) { 445*cdf0e10cSrcweir /// set this instance as the sink ! 446*cdf0e10cSrcweir m_succ->setPredecessor( Reference< XConnectable > ( 447*cdf0e10cSrcweir SAL_STATIC_CAST( XConnectable * , this ) ) ); 448*cdf0e10cSrcweir } 449*cdf0e10cSrcweir } 450*cdf0e10cSrcweir } 451*cdf0e10cSrcweir 452*cdf0e10cSrcweir Reference < XConnectable > ODataInputStream::getSuccessor() throw (RuntimeException) 453*cdf0e10cSrcweir { 454*cdf0e10cSrcweir return m_succ; 455*cdf0e10cSrcweir } 456*cdf0e10cSrcweir 457*cdf0e10cSrcweir 458*cdf0e10cSrcweir // XDataSource 459*cdf0e10cSrcweir void ODataInputStream::setPredecessor( const Reference < XConnectable > &r ) 460*cdf0e10cSrcweir throw (RuntimeException) 461*cdf0e10cSrcweir { 462*cdf0e10cSrcweir if( r != m_pred ) { 463*cdf0e10cSrcweir m_pred = r; 464*cdf0e10cSrcweir if( m_pred.is() ) { 465*cdf0e10cSrcweir m_pred->setSuccessor( Reference< XConnectable > ( 466*cdf0e10cSrcweir SAL_STATIC_CAST( XConnectable * , this ) ) ); 467*cdf0e10cSrcweir } 468*cdf0e10cSrcweir } 469*cdf0e10cSrcweir } 470*cdf0e10cSrcweir Reference < XConnectable > ODataInputStream::getPredecessor() throw (RuntimeException) 471*cdf0e10cSrcweir { 472*cdf0e10cSrcweir return m_pred; 473*cdf0e10cSrcweir } 474*cdf0e10cSrcweir 475*cdf0e10cSrcweir // XServiceInfo 476*cdf0e10cSrcweir OUString ODataInputStream::getImplementationName() throw () 477*cdf0e10cSrcweir { 478*cdf0e10cSrcweir return ODataInputStream_getImplementationName(); 479*cdf0e10cSrcweir } 480*cdf0e10cSrcweir 481*cdf0e10cSrcweir // XServiceInfo 482*cdf0e10cSrcweir sal_Bool ODataInputStream::supportsService(const OUString& ServiceName) throw () 483*cdf0e10cSrcweir { 484*cdf0e10cSrcweir Sequence< OUString > aSNL = getSupportedServiceNames(); 485*cdf0e10cSrcweir const OUString * pArray = aSNL.getConstArray(); 486*cdf0e10cSrcweir 487*cdf0e10cSrcweir for( sal_Int32 i = 0; i < aSNL.getLength(); i++ ) 488*cdf0e10cSrcweir if( pArray[i] == ServiceName ) 489*cdf0e10cSrcweir return sal_True; 490*cdf0e10cSrcweir 491*cdf0e10cSrcweir return sal_False; 492*cdf0e10cSrcweir } 493*cdf0e10cSrcweir 494*cdf0e10cSrcweir // XServiceInfo 495*cdf0e10cSrcweir Sequence< OUString > ODataInputStream::getSupportedServiceNames(void) throw () 496*cdf0e10cSrcweir { 497*cdf0e10cSrcweir return ODataInputStream_getSupportedServiceNames(); 498*cdf0e10cSrcweir } 499*cdf0e10cSrcweir 500*cdf0e10cSrcweir /*** 501*cdf0e10cSrcweir * 502*cdf0e10cSrcweir * registration information 503*cdf0e10cSrcweir * 504*cdf0e10cSrcweir * 505*cdf0e10cSrcweir ****/ 506*cdf0e10cSrcweir 507*cdf0e10cSrcweir Reference< XInterface > SAL_CALL ODataInputStream_CreateInstance( const Reference < XComponentContext > & ) throw( Exception) 508*cdf0e10cSrcweir { 509*cdf0e10cSrcweir ODataInputStream *p = new ODataInputStream; 510*cdf0e10cSrcweir return Reference< XInterface > ( (OWeakObject * ) p ); 511*cdf0e10cSrcweir } 512*cdf0e10cSrcweir 513*cdf0e10cSrcweir OUString ODataInputStream_getImplementationName() 514*cdf0e10cSrcweir { 515*cdf0e10cSrcweir return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.io.stm.DataInputStream" ) ); 516*cdf0e10cSrcweir } 517*cdf0e10cSrcweir 518*cdf0e10cSrcweir Sequence<OUString> ODataInputStream_getSupportedServiceNames(void) 519*cdf0e10cSrcweir { 520*cdf0e10cSrcweir Sequence<OUString> aRet(1); 521*cdf0e10cSrcweir aRet.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.DataInputStream" ) ); 522*cdf0e10cSrcweir return aRet; 523*cdf0e10cSrcweir } 524*cdf0e10cSrcweir 525*cdf0e10cSrcweir 526*cdf0e10cSrcweir 527*cdf0e10cSrcweir 528*cdf0e10cSrcweir class ODataOutputStream : 529*cdf0e10cSrcweir public WeakImplHelper4 < 530*cdf0e10cSrcweir XDataOutputStream, 531*cdf0e10cSrcweir XActiveDataSource, 532*cdf0e10cSrcweir XConnectable, 533*cdf0e10cSrcweir XServiceInfo > 534*cdf0e10cSrcweir { 535*cdf0e10cSrcweir public: 536*cdf0e10cSrcweir ODataOutputStream() 537*cdf0e10cSrcweir : m_bValidStream( sal_False ) 538*cdf0e10cSrcweir { 539*cdf0e10cSrcweir g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); 540*cdf0e10cSrcweir } 541*cdf0e10cSrcweir ~ODataOutputStream(); 542*cdf0e10cSrcweir 543*cdf0e10cSrcweir public: // XOutputStream 544*cdf0e10cSrcweir virtual void SAL_CALL writeBytes(const Sequence< sal_Int8 >& aData) 545*cdf0e10cSrcweir throw ( NotConnectedException, 546*cdf0e10cSrcweir BufferSizeExceededException, 547*cdf0e10cSrcweir RuntimeException); 548*cdf0e10cSrcweir virtual void SAL_CALL flush(void) 549*cdf0e10cSrcweir throw ( NotConnectedException, 550*cdf0e10cSrcweir BufferSizeExceededException, 551*cdf0e10cSrcweir RuntimeException); 552*cdf0e10cSrcweir virtual void SAL_CALL closeOutput(void) 553*cdf0e10cSrcweir throw ( NotConnectedException, 554*cdf0e10cSrcweir BufferSizeExceededException, 555*cdf0e10cSrcweir RuntimeException); 556*cdf0e10cSrcweir 557*cdf0e10cSrcweir public: // XDataOutputStream 558*cdf0e10cSrcweir virtual void SAL_CALL writeBoolean(sal_Bool Value) throw (IOException, RuntimeException); 559*cdf0e10cSrcweir virtual void SAL_CALL writeByte(sal_Int8 Value) throw (IOException, RuntimeException); 560*cdf0e10cSrcweir virtual void SAL_CALL writeChar(sal_Unicode Value) throw (IOException, RuntimeException); 561*cdf0e10cSrcweir virtual void SAL_CALL writeShort(sal_Int16 Value) throw (IOException, RuntimeException); 562*cdf0e10cSrcweir virtual void SAL_CALL writeLong(sal_Int32 Value) throw (IOException, RuntimeException); 563*cdf0e10cSrcweir virtual void SAL_CALL writeHyper(sal_Int64 Value) throw (IOException, RuntimeException); 564*cdf0e10cSrcweir virtual void SAL_CALL writeFloat(float Value) throw (IOException, RuntimeException); 565*cdf0e10cSrcweir virtual void SAL_CALL writeDouble(double Value) throw (IOException, RuntimeException); 566*cdf0e10cSrcweir virtual void SAL_CALL writeUTF(const OUString& Value) throw (IOException, RuntimeException); 567*cdf0e10cSrcweir 568*cdf0e10cSrcweir public: // XActiveDataSource 569*cdf0e10cSrcweir virtual void SAL_CALL setOutputStream(const Reference< XOutputStream > & aStream) 570*cdf0e10cSrcweir throw (RuntimeException); 571*cdf0e10cSrcweir virtual Reference < XOutputStream > SAL_CALL getOutputStream(void) throw (RuntimeException); 572*cdf0e10cSrcweir 573*cdf0e10cSrcweir public: // XConnectable 574*cdf0e10cSrcweir virtual void SAL_CALL setPredecessor(const Reference < XConnectable >& aPredecessor) 575*cdf0e10cSrcweir throw (RuntimeException); 576*cdf0e10cSrcweir virtual Reference < XConnectable > SAL_CALL getPredecessor(void) 577*cdf0e10cSrcweir throw (RuntimeException); 578*cdf0e10cSrcweir virtual void SAL_CALL setSuccessor(const Reference < XConnectable >& aSuccessor) 579*cdf0e10cSrcweir throw (RuntimeException); 580*cdf0e10cSrcweir virtual Reference < XConnectable > SAL_CALL getSuccessor(void) 581*cdf0e10cSrcweir throw (RuntimeException); 582*cdf0e10cSrcweir 583*cdf0e10cSrcweir public: // XServiceInfo 584*cdf0e10cSrcweir OUString SAL_CALL getImplementationName() throw (); 585*cdf0e10cSrcweir Sequence< OUString > SAL_CALL getSupportedServiceNames(void) throw (); 586*cdf0e10cSrcweir sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw (); 587*cdf0e10cSrcweir 588*cdf0e10cSrcweir protected: 589*cdf0e10cSrcweir Reference < XConnectable > m_succ; 590*cdf0e10cSrcweir Reference < XConnectable > m_pred; 591*cdf0e10cSrcweir Reference< XOutputStream > m_output; 592*cdf0e10cSrcweir sal_Bool m_bValidStream; 593*cdf0e10cSrcweir }; 594*cdf0e10cSrcweir 595*cdf0e10cSrcweir ODataOutputStream::~ODataOutputStream() 596*cdf0e10cSrcweir { 597*cdf0e10cSrcweir g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); 598*cdf0e10cSrcweir } 599*cdf0e10cSrcweir 600*cdf0e10cSrcweir 601*cdf0e10cSrcweir // XOutputStream 602*cdf0e10cSrcweir void ODataOutputStream::writeBytes(const Sequence< sal_Int8 >& aData) 603*cdf0e10cSrcweir throw ( NotConnectedException, 604*cdf0e10cSrcweir BufferSizeExceededException, 605*cdf0e10cSrcweir RuntimeException) 606*cdf0e10cSrcweir { 607*cdf0e10cSrcweir if( m_bValidStream ) 608*cdf0e10cSrcweir { 609*cdf0e10cSrcweir m_output->writeBytes( aData ); 610*cdf0e10cSrcweir } 611*cdf0e10cSrcweir else { 612*cdf0e10cSrcweir throw NotConnectedException( ); 613*cdf0e10cSrcweir } 614*cdf0e10cSrcweir } 615*cdf0e10cSrcweir 616*cdf0e10cSrcweir void ODataOutputStream::flush(void) 617*cdf0e10cSrcweir throw ( NotConnectedException, 618*cdf0e10cSrcweir BufferSizeExceededException, 619*cdf0e10cSrcweir RuntimeException) 620*cdf0e10cSrcweir { 621*cdf0e10cSrcweir if( m_bValidStream ) 622*cdf0e10cSrcweir { 623*cdf0e10cSrcweir m_output->flush(); 624*cdf0e10cSrcweir } 625*cdf0e10cSrcweir else 626*cdf0e10cSrcweir { 627*cdf0e10cSrcweir throw NotConnectedException(); 628*cdf0e10cSrcweir } 629*cdf0e10cSrcweir 630*cdf0e10cSrcweir } 631*cdf0e10cSrcweir 632*cdf0e10cSrcweir 633*cdf0e10cSrcweir void ODataOutputStream::closeOutput(void) 634*cdf0e10cSrcweir throw ( NotConnectedException, 635*cdf0e10cSrcweir BufferSizeExceededException, 636*cdf0e10cSrcweir RuntimeException) 637*cdf0e10cSrcweir { 638*cdf0e10cSrcweir if( m_bValidStream ) 639*cdf0e10cSrcweir { 640*cdf0e10cSrcweir m_output->closeOutput(); 641*cdf0e10cSrcweir setOutputStream( Reference< XOutputStream > () ); 642*cdf0e10cSrcweir setPredecessor( Reference < XConnectable >() ); 643*cdf0e10cSrcweir setSuccessor( Reference < XConnectable >() ); 644*cdf0e10cSrcweir } 645*cdf0e10cSrcweir else 646*cdf0e10cSrcweir { 647*cdf0e10cSrcweir throw NotConnectedException(); 648*cdf0e10cSrcweir } 649*cdf0e10cSrcweir } 650*cdf0e10cSrcweir 651*cdf0e10cSrcweir // XDataOutputStream 652*cdf0e10cSrcweir void ODataOutputStream::writeBoolean(sal_Bool Value) 653*cdf0e10cSrcweir throw ( IOException, 654*cdf0e10cSrcweir RuntimeException) 655*cdf0e10cSrcweir { 656*cdf0e10cSrcweir if( Value ) 657*cdf0e10cSrcweir { 658*cdf0e10cSrcweir writeByte( 1 ); 659*cdf0e10cSrcweir } 660*cdf0e10cSrcweir else 661*cdf0e10cSrcweir { 662*cdf0e10cSrcweir writeByte( 0 ); 663*cdf0e10cSrcweir } 664*cdf0e10cSrcweir } 665*cdf0e10cSrcweir 666*cdf0e10cSrcweir 667*cdf0e10cSrcweir void ODataOutputStream::writeByte(sal_Int8 Value) 668*cdf0e10cSrcweir throw ( IOException, 669*cdf0e10cSrcweir RuntimeException) 670*cdf0e10cSrcweir { 671*cdf0e10cSrcweir Sequence<sal_Int8> aTmp( 1 ); 672*cdf0e10cSrcweir aTmp.getArray()[0] = Value; 673*cdf0e10cSrcweir writeBytes( aTmp ); 674*cdf0e10cSrcweir } 675*cdf0e10cSrcweir 676*cdf0e10cSrcweir void ODataOutputStream::writeChar(sal_Unicode Value) 677*cdf0e10cSrcweir throw ( IOException, 678*cdf0e10cSrcweir RuntimeException) 679*cdf0e10cSrcweir { 680*cdf0e10cSrcweir Sequence<sal_Int8> aTmp( 2 ); 681*cdf0e10cSrcweir sal_Int8 * pBytes = ( sal_Int8 * ) aTmp.getArray(); 682*cdf0e10cSrcweir pBytes[0] = sal_Int8(Value >> 8); 683*cdf0e10cSrcweir pBytes[1] = sal_Int8(Value); 684*cdf0e10cSrcweir writeBytes( aTmp ); 685*cdf0e10cSrcweir } 686*cdf0e10cSrcweir 687*cdf0e10cSrcweir 688*cdf0e10cSrcweir void ODataOutputStream::writeShort(sal_Int16 Value) 689*cdf0e10cSrcweir throw ( IOException, 690*cdf0e10cSrcweir RuntimeException) 691*cdf0e10cSrcweir { 692*cdf0e10cSrcweir Sequence<sal_Int8> aTmp( 2 ); 693*cdf0e10cSrcweir sal_Int8 * pBytes = aTmp.getArray(); 694*cdf0e10cSrcweir pBytes[0] = sal_Int8(Value >> 8); 695*cdf0e10cSrcweir pBytes[1] = sal_Int8(Value); 696*cdf0e10cSrcweir writeBytes( aTmp ); 697*cdf0e10cSrcweir } 698*cdf0e10cSrcweir 699*cdf0e10cSrcweir void ODataOutputStream::writeLong(sal_Int32 Value) 700*cdf0e10cSrcweir throw ( IOException, 701*cdf0e10cSrcweir RuntimeException) 702*cdf0e10cSrcweir { 703*cdf0e10cSrcweir Sequence<sal_Int8> aTmp( 4 ); 704*cdf0e10cSrcweir sal_Int8 * pBytes = aTmp.getArray(); 705*cdf0e10cSrcweir pBytes[0] = sal_Int8(Value >> 24); 706*cdf0e10cSrcweir pBytes[1] = sal_Int8(Value >> 16); 707*cdf0e10cSrcweir pBytes[2] = sal_Int8(Value >> 8); 708*cdf0e10cSrcweir pBytes[3] = sal_Int8(Value); 709*cdf0e10cSrcweir writeBytes( aTmp ); 710*cdf0e10cSrcweir } 711*cdf0e10cSrcweir 712*cdf0e10cSrcweir void ODataOutputStream::writeHyper(sal_Int64 Value) 713*cdf0e10cSrcweir throw ( IOException, 714*cdf0e10cSrcweir RuntimeException) 715*cdf0e10cSrcweir { 716*cdf0e10cSrcweir Sequence<sal_Int8> aTmp( 8 ); 717*cdf0e10cSrcweir sal_Int8 * pBytes = aTmp.getArray(); 718*cdf0e10cSrcweir pBytes[0] = sal_Int8(Value >> 56); 719*cdf0e10cSrcweir pBytes[1] = sal_Int8(Value >> 48); 720*cdf0e10cSrcweir pBytes[2] = sal_Int8(Value >> 40); 721*cdf0e10cSrcweir pBytes[3] = sal_Int8(Value >> 32); 722*cdf0e10cSrcweir pBytes[4] = sal_Int8(Value >> 24); 723*cdf0e10cSrcweir pBytes[5] = sal_Int8(Value >> 16); 724*cdf0e10cSrcweir pBytes[6] = sal_Int8(Value >> 8); 725*cdf0e10cSrcweir pBytes[7] = sal_Int8(Value); 726*cdf0e10cSrcweir writeBytes( aTmp ); 727*cdf0e10cSrcweir } 728*cdf0e10cSrcweir 729*cdf0e10cSrcweir 730*cdf0e10cSrcweir void ODataOutputStream::writeFloat(float Value) 731*cdf0e10cSrcweir throw ( IOException, 732*cdf0e10cSrcweir RuntimeException) 733*cdf0e10cSrcweir { 734*cdf0e10cSrcweir union { float f; sal_uInt32 n; } a; 735*cdf0e10cSrcweir a.f = Value; 736*cdf0e10cSrcweir writeLong( a.n ); 737*cdf0e10cSrcweir } 738*cdf0e10cSrcweir 739*cdf0e10cSrcweir void ODataOutputStream::writeDouble(double Value) 740*cdf0e10cSrcweir throw ( IOException, 741*cdf0e10cSrcweir RuntimeException) 742*cdf0e10cSrcweir { 743*cdf0e10cSrcweir sal_uInt32 n = 1; 744*cdf0e10cSrcweir union { double d; struct { sal_uInt32 n1; sal_uInt32 n2; } ad; } a; 745*cdf0e10cSrcweir a.d = Value; 746*cdf0e10cSrcweir if( *(sal_Int8 *)&n == 1 ) 747*cdf0e10cSrcweir { 748*cdf0e10cSrcweir // little endian 749*cdf0e10cSrcweir writeLong( a.ad.n2 ); 750*cdf0e10cSrcweir writeLong( a.ad.n1 ); 751*cdf0e10cSrcweir } 752*cdf0e10cSrcweir else 753*cdf0e10cSrcweir { 754*cdf0e10cSrcweir // big endian 755*cdf0e10cSrcweir writeLong( a.ad.n1 ); 756*cdf0e10cSrcweir writeLong( a.ad.n2 ); 757*cdf0e10cSrcweir } 758*cdf0e10cSrcweir } 759*cdf0e10cSrcweir 760*cdf0e10cSrcweir void ODataOutputStream::writeUTF(const OUString& Value) 761*cdf0e10cSrcweir throw ( IOException, 762*cdf0e10cSrcweir RuntimeException) 763*cdf0e10cSrcweir { 764*cdf0e10cSrcweir sal_Int32 nStrLen = Value.getLength(); 765*cdf0e10cSrcweir const sal_Unicode * pStr = Value.getStr(); 766*cdf0e10cSrcweir sal_Int32 nUTFLen = 0; 767*cdf0e10cSrcweir sal_Int32 i; 768*cdf0e10cSrcweir 769*cdf0e10cSrcweir for( i = 0 ; i < nStrLen ; i++ ) 770*cdf0e10cSrcweir { 771*cdf0e10cSrcweir sal_uInt16 c = pStr[i]; 772*cdf0e10cSrcweir if( (c >= 0x0001) && (c <= 0x007F) ) 773*cdf0e10cSrcweir { 774*cdf0e10cSrcweir nUTFLen++; 775*cdf0e10cSrcweir } 776*cdf0e10cSrcweir else if( c > 0x07FF ) 777*cdf0e10cSrcweir { 778*cdf0e10cSrcweir nUTFLen += 3; 779*cdf0e10cSrcweir } 780*cdf0e10cSrcweir else 781*cdf0e10cSrcweir { 782*cdf0e10cSrcweir nUTFLen += 2; 783*cdf0e10cSrcweir } 784*cdf0e10cSrcweir } 785*cdf0e10cSrcweir 786*cdf0e10cSrcweir 787*cdf0e10cSrcweir // compatibility mode for older implementations, where it was not possible 788*cdf0e10cSrcweir // to write blocks bigger than 64 k. Note that there is a tradeoff. Blocks, 789*cdf0e10cSrcweir // that are exactly 64k long can not be read by older routines when written 790*cdf0e10cSrcweir // with these routines and the other way round !!!!! 791*cdf0e10cSrcweir if( nUTFLen >= 0xFFFF ) { 792*cdf0e10cSrcweir writeShort( (sal_Int16)-1 ); 793*cdf0e10cSrcweir writeLong( nUTFLen ); 794*cdf0e10cSrcweir } 795*cdf0e10cSrcweir else { 796*cdf0e10cSrcweir writeShort( ((sal_uInt16)nUTFLen) ); 797*cdf0e10cSrcweir } 798*cdf0e10cSrcweir for( i = 0 ; i < nStrLen ; i++ ) 799*cdf0e10cSrcweir { 800*cdf0e10cSrcweir sal_uInt16 c = pStr[i]; 801*cdf0e10cSrcweir if( (c >= 0x0001) && (c <= 0x007F) ) 802*cdf0e10cSrcweir { 803*cdf0e10cSrcweir writeByte(sal_Int8(c)); 804*cdf0e10cSrcweir } 805*cdf0e10cSrcweir else if( c > 0x07FF ) 806*cdf0e10cSrcweir { 807*cdf0e10cSrcweir writeByte(sal_Int8(0xE0 | ((c >> 12) & 0x0F))); 808*cdf0e10cSrcweir writeByte(sal_Int8(0x80 | ((c >> 6) & 0x3F))); 809*cdf0e10cSrcweir writeByte(sal_Int8(0x80 | ((c >> 0) & 0x3F))); 810*cdf0e10cSrcweir //written += 2; 811*cdf0e10cSrcweir } 812*cdf0e10cSrcweir else 813*cdf0e10cSrcweir { 814*cdf0e10cSrcweir writeByte(sal_Int8(0xC0 | ((c >> 6) & 0x1F))); 815*cdf0e10cSrcweir writeByte(sal_Int8(0x80 | ((c >> 0) & 0x3F))); 816*cdf0e10cSrcweir //written += 1; 817*cdf0e10cSrcweir } 818*cdf0e10cSrcweir } 819*cdf0e10cSrcweir //written += strlen + 2; 820*cdf0e10cSrcweir } 821*cdf0e10cSrcweir 822*cdf0e10cSrcweir // XActiveDataSource 823*cdf0e10cSrcweir void ODataOutputStream::setOutputStream(const Reference< XOutputStream > & aStream) 824*cdf0e10cSrcweir throw (RuntimeException) 825*cdf0e10cSrcweir { 826*cdf0e10cSrcweir if( m_output != aStream ) { 827*cdf0e10cSrcweir m_output = aStream; 828*cdf0e10cSrcweir m_bValidStream = m_output.is(); 829*cdf0e10cSrcweir 830*cdf0e10cSrcweir Reference < XConnectable > succ( m_output , UNO_QUERY ); 831*cdf0e10cSrcweir setSuccessor( succ ); 832*cdf0e10cSrcweir } 833*cdf0e10cSrcweir } 834*cdf0e10cSrcweir 835*cdf0e10cSrcweir Reference< XOutputStream > ODataOutputStream::getOutputStream(void) 836*cdf0e10cSrcweir throw (RuntimeException) 837*cdf0e10cSrcweir { 838*cdf0e10cSrcweir return m_output; 839*cdf0e10cSrcweir } 840*cdf0e10cSrcweir 841*cdf0e10cSrcweir 842*cdf0e10cSrcweir 843*cdf0e10cSrcweir 844*cdf0e10cSrcweir // XDataSink 845*cdf0e10cSrcweir void ODataOutputStream::setSuccessor( const Reference < XConnectable > &r ) 846*cdf0e10cSrcweir throw (RuntimeException) 847*cdf0e10cSrcweir { 848*cdf0e10cSrcweir /// if the references match, nothing needs to be done 849*cdf0e10cSrcweir if( m_succ != r ) 850*cdf0e10cSrcweir { 851*cdf0e10cSrcweir /// store the reference for later use 852*cdf0e10cSrcweir m_succ = r; 853*cdf0e10cSrcweir 854*cdf0e10cSrcweir if( m_succ.is() ) 855*cdf0e10cSrcweir { 856*cdf0e10cSrcweir /// set this instance as the sink ! 857*cdf0e10cSrcweir m_succ->setPredecessor( Reference < XConnectable > ( 858*cdf0e10cSrcweir SAL_STATIC_CAST( XConnectable * , this ) )); 859*cdf0e10cSrcweir } 860*cdf0e10cSrcweir } 861*cdf0e10cSrcweir } 862*cdf0e10cSrcweir Reference < XConnectable > ODataOutputStream::getSuccessor() throw (RuntimeException) 863*cdf0e10cSrcweir { 864*cdf0e10cSrcweir return m_succ; 865*cdf0e10cSrcweir } 866*cdf0e10cSrcweir 867*cdf0e10cSrcweir 868*cdf0e10cSrcweir // XDataSource 869*cdf0e10cSrcweir void ODataOutputStream::setPredecessor( const Reference < XConnectable > &r ) throw (RuntimeException) 870*cdf0e10cSrcweir { 871*cdf0e10cSrcweir if( r != m_pred ) { 872*cdf0e10cSrcweir m_pred = r; 873*cdf0e10cSrcweir if( m_pred.is() ) { 874*cdf0e10cSrcweir m_pred->setSuccessor( Reference< XConnectable > ( 875*cdf0e10cSrcweir SAL_STATIC_CAST( XConnectable * , this ) )); 876*cdf0e10cSrcweir } 877*cdf0e10cSrcweir } 878*cdf0e10cSrcweir } 879*cdf0e10cSrcweir Reference < XConnectable > ODataOutputStream::getPredecessor() throw (RuntimeException) 880*cdf0e10cSrcweir { 881*cdf0e10cSrcweir return m_pred; 882*cdf0e10cSrcweir } 883*cdf0e10cSrcweir 884*cdf0e10cSrcweir 885*cdf0e10cSrcweir 886*cdf0e10cSrcweir // XServiceInfo 887*cdf0e10cSrcweir OUString ODataOutputStream::getImplementationName() throw () 888*cdf0e10cSrcweir { 889*cdf0e10cSrcweir return ODataOutputStream_getImplementationName(); 890*cdf0e10cSrcweir } 891*cdf0e10cSrcweir 892*cdf0e10cSrcweir // XServiceInfo 893*cdf0e10cSrcweir sal_Bool ODataOutputStream::supportsService(const OUString& ServiceName) throw () 894*cdf0e10cSrcweir { 895*cdf0e10cSrcweir Sequence< OUString > aSNL = getSupportedServiceNames(); 896*cdf0e10cSrcweir const OUString * pArray = aSNL.getConstArray(); 897*cdf0e10cSrcweir 898*cdf0e10cSrcweir for( sal_Int32 i = 0; i < aSNL.getLength(); i++ ) 899*cdf0e10cSrcweir if( pArray[i] == ServiceName ) 900*cdf0e10cSrcweir return sal_True; 901*cdf0e10cSrcweir 902*cdf0e10cSrcweir return sal_False; 903*cdf0e10cSrcweir } 904*cdf0e10cSrcweir 905*cdf0e10cSrcweir // XServiceInfo 906*cdf0e10cSrcweir Sequence< OUString > ODataOutputStream::getSupportedServiceNames(void) throw () 907*cdf0e10cSrcweir { 908*cdf0e10cSrcweir return ODataOutputStream_getSupportedServiceNames(); 909*cdf0e10cSrcweir } 910*cdf0e10cSrcweir 911*cdf0e10cSrcweir 912*cdf0e10cSrcweir 913*cdf0e10cSrcweir 914*cdf0e10cSrcweir Reference< XInterface > SAL_CALL ODataOutputStream_CreateInstance( const Reference < XComponentContext > & ) throw(Exception) 915*cdf0e10cSrcweir { 916*cdf0e10cSrcweir ODataOutputStream *p = new ODataOutputStream; 917*cdf0e10cSrcweir Reference< XInterface > xService = *p; 918*cdf0e10cSrcweir return xService; 919*cdf0e10cSrcweir } 920*cdf0e10cSrcweir 921*cdf0e10cSrcweir 922*cdf0e10cSrcweir OUString ODataOutputStream_getImplementationName() 923*cdf0e10cSrcweir { 924*cdf0e10cSrcweir return OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.io.stm.DataOutputStream" ) ); 925*cdf0e10cSrcweir } 926*cdf0e10cSrcweir 927*cdf0e10cSrcweir Sequence<OUString> ODataOutputStream_getSupportedServiceNames(void) 928*cdf0e10cSrcweir { 929*cdf0e10cSrcweir Sequence<OUString> aRet(1); 930*cdf0e10cSrcweir aRet.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.DataOutputStream" ) ); 931*cdf0e10cSrcweir return aRet; 932*cdf0e10cSrcweir } 933*cdf0e10cSrcweir 934*cdf0e10cSrcweir //-------------------------------------- 935*cdf0e10cSrcweir struct equalObjectContainer_Impl 936*cdf0e10cSrcweir { 937*cdf0e10cSrcweir sal_Int32 operator()(const Reference< XInterface > & s1, 938*cdf0e10cSrcweir const Reference< XInterface > & s2) const 939*cdf0e10cSrcweir { 940*cdf0e10cSrcweir return s1 == s2; 941*cdf0e10cSrcweir } 942*cdf0e10cSrcweir }; 943*cdf0e10cSrcweir 944*cdf0e10cSrcweir //----------------------------------------------------------------------------- 945*cdf0e10cSrcweir struct hashObjectContainer_Impl 946*cdf0e10cSrcweir { 947*cdf0e10cSrcweir size_t operator()(const Reference< XInterface > & xRef) const 948*cdf0e10cSrcweir { 949*cdf0e10cSrcweir return (size_t)xRef.get(); 950*cdf0e10cSrcweir } 951*cdf0e10cSrcweir }; 952*cdf0e10cSrcweir 953*cdf0e10cSrcweir typedef hash_map 954*cdf0e10cSrcweir < 955*cdf0e10cSrcweir Reference< XInterface >, 956*cdf0e10cSrcweir sal_Int32, 957*cdf0e10cSrcweir hashObjectContainer_Impl, 958*cdf0e10cSrcweir equalObjectContainer_Impl 959*cdf0e10cSrcweir > ObjectContainer_Impl; 960*cdf0e10cSrcweir 961*cdf0e10cSrcweir /*--------------------------------------------- 962*cdf0e10cSrcweir * 963*cdf0e10cSrcweir * 964*cdf0e10cSrcweir * 965*cdf0e10cSrcweir * 966*cdf0e10cSrcweir *--------------------------------------------*/ 967*cdf0e10cSrcweir class OObjectOutputStream : 968*cdf0e10cSrcweir public ODataOutputStream, 969*cdf0e10cSrcweir public XObjectOutputStream, 970*cdf0e10cSrcweir public XMarkableStream 971*cdf0e10cSrcweir { 972*cdf0e10cSrcweir public: 973*cdf0e10cSrcweir OObjectOutputStream() 974*cdf0e10cSrcweir : m_nMaxId(0) , 975*cdf0e10cSrcweir m_bValidMarkable(sal_False) 976*cdf0e10cSrcweir { 977*cdf0e10cSrcweir g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); 978*cdf0e10cSrcweir } 979*cdf0e10cSrcweir 980*cdf0e10cSrcweir ~OObjectOutputStream(); 981*cdf0e10cSrcweir 982*cdf0e10cSrcweir public: 983*cdf0e10cSrcweir Any SAL_CALL queryInterface( const Type &type ) throw (::com::sun::star::uno::RuntimeException); 984*cdf0e10cSrcweir void SAL_CALL acquire() throw() { ODataOutputStream::acquire(); } 985*cdf0e10cSrcweir void SAL_CALL release() throw() { ODataOutputStream::release(); } 986*cdf0e10cSrcweir 987*cdf0e10cSrcweir public: 988*cdf0e10cSrcweir // XOutputStream 989*cdf0e10cSrcweir virtual void SAL_CALL writeBytes(const Sequence< sal_Int8 >& aData) 990*cdf0e10cSrcweir throw ( NotConnectedException, 991*cdf0e10cSrcweir BufferSizeExceededException, 992*cdf0e10cSrcweir RuntimeException) 993*cdf0e10cSrcweir { ODataOutputStream::writeBytes( aData ); } 994*cdf0e10cSrcweir 995*cdf0e10cSrcweir virtual void SAL_CALL flush(void) 996*cdf0e10cSrcweir throw ( NotConnectedException, 997*cdf0e10cSrcweir BufferSizeExceededException, 998*cdf0e10cSrcweir RuntimeException) 999*cdf0e10cSrcweir { ODataOutputStream::flush(); } 1000*cdf0e10cSrcweir 1001*cdf0e10cSrcweir virtual void SAL_CALL closeOutput(void) 1002*cdf0e10cSrcweir throw ( NotConnectedException, 1003*cdf0e10cSrcweir BufferSizeExceededException, 1004*cdf0e10cSrcweir RuntimeException) 1005*cdf0e10cSrcweir { ODataOutputStream::closeOutput(); } 1006*cdf0e10cSrcweir 1007*cdf0e10cSrcweir public: 1008*cdf0e10cSrcweir // XDataOutputStream 1009*cdf0e10cSrcweir virtual void SAL_CALL writeBoolean(sal_Bool Value) throw (IOException, RuntimeException) 1010*cdf0e10cSrcweir { ODataOutputStream::writeBoolean( Value ); } 1011*cdf0e10cSrcweir virtual void SAL_CALL writeByte(sal_Int8 Value) throw (IOException, RuntimeException) 1012*cdf0e10cSrcweir { ODataOutputStream::writeByte( Value ); } 1013*cdf0e10cSrcweir virtual void SAL_CALL writeChar(sal_Unicode Value) throw (IOException, RuntimeException) 1014*cdf0e10cSrcweir { ODataOutputStream::writeChar( Value ); } 1015*cdf0e10cSrcweir virtual void SAL_CALL writeShort(sal_Int16 Value) throw (IOException, RuntimeException) 1016*cdf0e10cSrcweir { ODataOutputStream::writeShort( Value ); } 1017*cdf0e10cSrcweir virtual void SAL_CALL writeLong(sal_Int32 Value) throw (IOException, RuntimeException) 1018*cdf0e10cSrcweir { ODataOutputStream::writeLong( Value ); } 1019*cdf0e10cSrcweir virtual void SAL_CALL writeHyper(sal_Int64 Value) throw (IOException, RuntimeException) 1020*cdf0e10cSrcweir { ODataOutputStream::writeHyper( Value ); } 1021*cdf0e10cSrcweir virtual void SAL_CALL writeFloat(float Value) throw (IOException, RuntimeException) 1022*cdf0e10cSrcweir { ODataOutputStream::writeFloat( Value ); } 1023*cdf0e10cSrcweir virtual void SAL_CALL writeDouble(double Value) throw (IOException, RuntimeException) 1024*cdf0e10cSrcweir { ODataOutputStream::writeDouble( Value ); } 1025*cdf0e10cSrcweir virtual void SAL_CALL writeUTF(const OUString& Value) throw (IOException, RuntimeException) 1026*cdf0e10cSrcweir { ODataOutputStream::writeUTF( Value );} 1027*cdf0e10cSrcweir 1028*cdf0e10cSrcweir // XObjectOutputStream 1029*cdf0e10cSrcweir virtual void SAL_CALL writeObject( const Reference< XPersistObject > & r ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); 1030*cdf0e10cSrcweir 1031*cdf0e10cSrcweir public: // XMarkableStream 1032*cdf0e10cSrcweir virtual sal_Int32 SAL_CALL createMark(void) throw (IOException, RuntimeException); 1033*cdf0e10cSrcweir virtual void SAL_CALL deleteMark(sal_Int32 Mark) throw (IOException, IllegalArgumentException, RuntimeException); 1034*cdf0e10cSrcweir virtual void SAL_CALL jumpToMark(sal_Int32 nMark) throw (IOException, IllegalArgumentException, RuntimeException); 1035*cdf0e10cSrcweir virtual void SAL_CALL jumpToFurthest(void) throw (IOException, RuntimeException); 1036*cdf0e10cSrcweir virtual sal_Int32 SAL_CALL offsetToMark(sal_Int32 nMark) 1037*cdf0e10cSrcweir throw (IOException, IllegalArgumentException, RuntimeException); 1038*cdf0e10cSrcweir 1039*cdf0e10cSrcweir public: //XTypeProvider 1040*cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL 1041*cdf0e10cSrcweir getTypes( ) throw(::com::sun::star::uno::RuntimeException); 1042*cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL 1043*cdf0e10cSrcweir getImplementationId( ) throw(::com::sun::star::uno::RuntimeException); 1044*cdf0e10cSrcweir 1045*cdf0e10cSrcweir public: // XServiceInfo 1046*cdf0e10cSrcweir OUString SAL_CALL getImplementationName() throw (); 1047*cdf0e10cSrcweir Sequence< OUString > SAL_CALL getSupportedServiceNames(void) throw (); 1048*cdf0e10cSrcweir sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw (); 1049*cdf0e10cSrcweir 1050*cdf0e10cSrcweir private: 1051*cdf0e10cSrcweir void connectToMarkable(); 1052*cdf0e10cSrcweir private: 1053*cdf0e10cSrcweir ObjectContainer_Impl m_mapObject; 1054*cdf0e10cSrcweir sal_Int32 m_nMaxId; 1055*cdf0e10cSrcweir Reference< XMarkableStream > m_rMarkable; 1056*cdf0e10cSrcweir sal_Bool m_bValidMarkable; 1057*cdf0e10cSrcweir }; 1058*cdf0e10cSrcweir 1059*cdf0e10cSrcweir OObjectOutputStream::~OObjectOutputStream() 1060*cdf0e10cSrcweir { 1061*cdf0e10cSrcweir g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); 1062*cdf0e10cSrcweir } 1063*cdf0e10cSrcweir 1064*cdf0e10cSrcweir Any OObjectOutputStream::queryInterface( const Type &aType ) throw (::com::sun::star::uno::RuntimeException) 1065*cdf0e10cSrcweir { 1066*cdf0e10cSrcweir Any a = ::cppu::queryInterface( 1067*cdf0e10cSrcweir aType , 1068*cdf0e10cSrcweir SAL_STATIC_CAST( XMarkableStream * , this ), 1069*cdf0e10cSrcweir SAL_STATIC_CAST( XObjectOutputStream * , this ) ); 1070*cdf0e10cSrcweir if( a.hasValue() ) 1071*cdf0e10cSrcweir { 1072*cdf0e10cSrcweir return a; 1073*cdf0e10cSrcweir } 1074*cdf0e10cSrcweir 1075*cdf0e10cSrcweir return ODataOutputStream::queryInterface( aType ); 1076*cdf0e10cSrcweir 1077*cdf0e10cSrcweir } 1078*cdf0e10cSrcweir void OObjectOutputStream::writeObject( const Reference< XPersistObject > & xPObj ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) 1079*cdf0e10cSrcweir { 1080*cdf0e10cSrcweir 1081*cdf0e10cSrcweir connectToMarkable(); 1082*cdf0e10cSrcweir sal_Bool bWriteObj = sal_False; 1083*cdf0e10cSrcweir // create Mark to write length of info 1084*cdf0e10cSrcweir sal_uInt32 nInfoLenMark = m_rMarkable->createMark(); 1085*cdf0e10cSrcweir 1086*cdf0e10cSrcweir // length of the info data (is later rewritten) 1087*cdf0e10cSrcweir OObjectOutputStream::writeShort( 0 ); 1088*cdf0e10cSrcweir 1089*cdf0e10cSrcweir // write the object identifier 1090*cdf0e10cSrcweir if( xPObj.is() ) 1091*cdf0e10cSrcweir { 1092*cdf0e10cSrcweir Reference< XInterface > rX( xPObj , UNO_QUERY ); 1093*cdf0e10cSrcweir 1094*cdf0e10cSrcweir ObjectContainer_Impl::const_iterator aIt 1095*cdf0e10cSrcweir = m_mapObject.find( rX ); 1096*cdf0e10cSrcweir if( aIt == m_mapObject.end() ) 1097*cdf0e10cSrcweir { 1098*cdf0e10cSrcweir // insert new object in hash table 1099*cdf0e10cSrcweir m_mapObject[ rX ] = ++m_nMaxId; 1100*cdf0e10cSrcweir ODataOutputStream::writeLong( m_nMaxId ); 1101*cdf0e10cSrcweir ODataOutputStream::writeUTF( xPObj->getServiceName() ); 1102*cdf0e10cSrcweir bWriteObj = sal_True; 1103*cdf0e10cSrcweir } 1104*cdf0e10cSrcweir else 1105*cdf0e10cSrcweir { 1106*cdf0e10cSrcweir ODataOutputStream::writeLong( (*aIt).second ); 1107*cdf0e10cSrcweir OUString aName; 1108*cdf0e10cSrcweir ODataOutputStream::writeUTF( aName ); 1109*cdf0e10cSrcweir } 1110*cdf0e10cSrcweir } 1111*cdf0e10cSrcweir else 1112*cdf0e10cSrcweir { 1113*cdf0e10cSrcweir ODataOutputStream::writeLong( 0 ); 1114*cdf0e10cSrcweir OUString aName; 1115*cdf0e10cSrcweir ODataOutputStream::writeUTF( aName ); 1116*cdf0e10cSrcweir } 1117*cdf0e10cSrcweir 1118*cdf0e10cSrcweir sal_uInt32 nObjLenMark = m_rMarkable->createMark(); 1119*cdf0e10cSrcweir ODataOutputStream::writeLong( 0 ); 1120*cdf0e10cSrcweir 1121*cdf0e10cSrcweir sal_Int32 nInfoLen = m_rMarkable->offsetToMark( nInfoLenMark ); 1122*cdf0e10cSrcweir m_rMarkable->jumpToMark( nInfoLenMark ); 1123*cdf0e10cSrcweir // write length of the info data 1124*cdf0e10cSrcweir ODataOutputStream::writeShort( (sal_Int16)nInfoLen ); 1125*cdf0e10cSrcweir // jump to the end of the stream 1126*cdf0e10cSrcweir m_rMarkable->jumpToFurthest(); 1127*cdf0e10cSrcweir 1128*cdf0e10cSrcweir if( bWriteObj ) 1129*cdf0e10cSrcweir xPObj->write( Reference< XObjectOutputStream > ( 1130*cdf0e10cSrcweir SAL_STATIC_CAST( XObjectOutputStream * , this ) ) ); 1131*cdf0e10cSrcweir 1132*cdf0e10cSrcweir sal_Int32 nObjLen = m_rMarkable->offsetToMark( nObjLenMark ) -4; 1133*cdf0e10cSrcweir m_rMarkable->jumpToMark( nObjLenMark ); 1134*cdf0e10cSrcweir // write length of the info data 1135*cdf0e10cSrcweir ODataOutputStream::writeLong( nObjLen ); 1136*cdf0e10cSrcweir // jump to the end of the stream 1137*cdf0e10cSrcweir m_rMarkable->jumpToFurthest(); 1138*cdf0e10cSrcweir 1139*cdf0e10cSrcweir m_rMarkable->deleteMark( nObjLenMark ); 1140*cdf0e10cSrcweir m_rMarkable->deleteMark( nInfoLenMark ); 1141*cdf0e10cSrcweir } 1142*cdf0e10cSrcweir 1143*cdf0e10cSrcweir 1144*cdf0e10cSrcweir 1145*cdf0e10cSrcweir void OObjectOutputStream::connectToMarkable(void) 1146*cdf0e10cSrcweir { 1147*cdf0e10cSrcweir if( ! m_bValidMarkable ) { 1148*cdf0e10cSrcweir if( ! m_bValidStream ) 1149*cdf0e10cSrcweir { 1150*cdf0e10cSrcweir throw NotConnectedException(); 1151*cdf0e10cSrcweir } 1152*cdf0e10cSrcweir 1153*cdf0e10cSrcweir // find the markable stream ! 1154*cdf0e10cSrcweir Reference< XInterface > rTry(m_output); 1155*cdf0e10cSrcweir while( sal_True ) { 1156*cdf0e10cSrcweir if( ! rTry.is() ) 1157*cdf0e10cSrcweir { 1158*cdf0e10cSrcweir throw NotConnectedException(); 1159*cdf0e10cSrcweir } 1160*cdf0e10cSrcweir Reference < XMarkableStream > markable( rTry , UNO_QUERY ); 1161*cdf0e10cSrcweir if( markable.is() ) 1162*cdf0e10cSrcweir { 1163*cdf0e10cSrcweir m_rMarkable = markable; 1164*cdf0e10cSrcweir break; 1165*cdf0e10cSrcweir } 1166*cdf0e10cSrcweir Reference < XActiveDataSource > source( rTry , UNO_QUERY ); 1167*cdf0e10cSrcweir rTry = source; 1168*cdf0e10cSrcweir } 1169*cdf0e10cSrcweir m_bValidMarkable = sal_True; 1170*cdf0e10cSrcweir } 1171*cdf0e10cSrcweir } 1172*cdf0e10cSrcweir 1173*cdf0e10cSrcweir 1174*cdf0e10cSrcweir sal_Int32 OObjectOutputStream::createMark(void) 1175*cdf0e10cSrcweir throw (IOException, RuntimeException) 1176*cdf0e10cSrcweir { 1177*cdf0e10cSrcweir connectToMarkable(); // throws an exception, if a markable is not connected ! 1178*cdf0e10cSrcweir 1179*cdf0e10cSrcweir return m_rMarkable->createMark(); 1180*cdf0e10cSrcweir } 1181*cdf0e10cSrcweir 1182*cdf0e10cSrcweir void OObjectOutputStream::deleteMark(sal_Int32 Mark) 1183*cdf0e10cSrcweir throw (IOException, IllegalArgumentException, RuntimeException) 1184*cdf0e10cSrcweir { 1185*cdf0e10cSrcweir if( ! m_bValidMarkable ) 1186*cdf0e10cSrcweir { 1187*cdf0e10cSrcweir throw NotConnectedException(); 1188*cdf0e10cSrcweir } 1189*cdf0e10cSrcweir m_rMarkable->deleteMark( Mark ); 1190*cdf0e10cSrcweir } 1191*cdf0e10cSrcweir 1192*cdf0e10cSrcweir void OObjectOutputStream::jumpToMark(sal_Int32 nMark) 1193*cdf0e10cSrcweir throw (IOException, IllegalArgumentException, RuntimeException) 1194*cdf0e10cSrcweir { 1195*cdf0e10cSrcweir if( ! m_bValidMarkable ) 1196*cdf0e10cSrcweir { 1197*cdf0e10cSrcweir throw NotConnectedException(); 1198*cdf0e10cSrcweir } 1199*cdf0e10cSrcweir m_rMarkable->jumpToMark( nMark ); 1200*cdf0e10cSrcweir } 1201*cdf0e10cSrcweir 1202*cdf0e10cSrcweir 1203*cdf0e10cSrcweir void OObjectOutputStream::jumpToFurthest(void) 1204*cdf0e10cSrcweir throw (IOException, RuntimeException) 1205*cdf0e10cSrcweir { 1206*cdf0e10cSrcweir connectToMarkable(); 1207*cdf0e10cSrcweir m_rMarkable->jumpToFurthest(); 1208*cdf0e10cSrcweir } 1209*cdf0e10cSrcweir 1210*cdf0e10cSrcweir sal_Int32 OObjectOutputStream::offsetToMark(sal_Int32 nMark) 1211*cdf0e10cSrcweir throw (IOException, IllegalArgumentException, RuntimeException) 1212*cdf0e10cSrcweir { 1213*cdf0e10cSrcweir if( ! m_bValidMarkable ) 1214*cdf0e10cSrcweir { 1215*cdf0e10cSrcweir throw NotConnectedException(); 1216*cdf0e10cSrcweir } 1217*cdf0e10cSrcweir return m_rMarkable->offsetToMark( nMark ); 1218*cdf0e10cSrcweir } 1219*cdf0e10cSrcweir 1220*cdf0e10cSrcweir 1221*cdf0e10cSrcweir 1222*cdf0e10cSrcweir 1223*cdf0e10cSrcweir Reference< XInterface > SAL_CALL OObjectOutputStream_CreateInstance( const Reference < XComponentContext > & ) 1224*cdf0e10cSrcweir throw(Exception) 1225*cdf0e10cSrcweir { 1226*cdf0e10cSrcweir OObjectOutputStream *p = new OObjectOutputStream; 1227*cdf0e10cSrcweir return Reference< XInterface > ( SAL_STATIC_CAST( OWeakObject * , p ) ); 1228*cdf0e10cSrcweir } 1229*cdf0e10cSrcweir 1230*cdf0e10cSrcweir OUString OObjectOutputStream_getImplementationName() 1231*cdf0e10cSrcweir { 1232*cdf0e10cSrcweir return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.io.stm.ObjectOutputStream" ) ); 1233*cdf0e10cSrcweir } 1234*cdf0e10cSrcweir 1235*cdf0e10cSrcweir Sequence<OUString> OObjectOutputStream_getSupportedServiceNames(void) 1236*cdf0e10cSrcweir { 1237*cdf0e10cSrcweir Sequence<OUString> aRet(1); 1238*cdf0e10cSrcweir aRet.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.ObjectOutputStream" ) ); 1239*cdf0e10cSrcweir return aRet; 1240*cdf0e10cSrcweir } 1241*cdf0e10cSrcweir 1242*cdf0e10cSrcweir Sequence< Type > SAL_CALL OObjectOutputStream::getTypes(void) throw( RuntimeException ) 1243*cdf0e10cSrcweir { 1244*cdf0e10cSrcweir static OTypeCollection *pCollection = 0; 1245*cdf0e10cSrcweir if( ! pCollection ) 1246*cdf0e10cSrcweir { 1247*cdf0e10cSrcweir MutexGuard guard( Mutex::getGlobalMutex() ); 1248*cdf0e10cSrcweir if( ! pCollection ) 1249*cdf0e10cSrcweir { 1250*cdf0e10cSrcweir static OTypeCollection collection( 1251*cdf0e10cSrcweir getCppuType( (Reference< XMarkableStream > * ) 0 ), 1252*cdf0e10cSrcweir getCppuType( (Reference< XObjectOutputStream > * ) 0 ), 1253*cdf0e10cSrcweir ODataOutputStream::getTypes() ); 1254*cdf0e10cSrcweir pCollection = &collection; 1255*cdf0e10cSrcweir } 1256*cdf0e10cSrcweir } 1257*cdf0e10cSrcweir return (*pCollection).getTypes(); 1258*cdf0e10cSrcweir } 1259*cdf0e10cSrcweir 1260*cdf0e10cSrcweir Sequence< sal_Int8 > SAL_CALL OObjectOutputStream::getImplementationId( ) throw( RuntimeException) 1261*cdf0e10cSrcweir { 1262*cdf0e10cSrcweir static OImplementationId *pId = 0; 1263*cdf0e10cSrcweir if( ! pId ) 1264*cdf0e10cSrcweir { 1265*cdf0e10cSrcweir MutexGuard guard( Mutex::getGlobalMutex() ); 1266*cdf0e10cSrcweir if( ! pId ) 1267*cdf0e10cSrcweir { 1268*cdf0e10cSrcweir static OImplementationId id( sal_False ); 1269*cdf0e10cSrcweir pId = &id; 1270*cdf0e10cSrcweir } 1271*cdf0e10cSrcweir } 1272*cdf0e10cSrcweir return (*pId).getImplementationId(); 1273*cdf0e10cSrcweir } 1274*cdf0e10cSrcweir 1275*cdf0e10cSrcweir 1276*cdf0e10cSrcweir // XServiceInfo 1277*cdf0e10cSrcweir OUString OObjectOutputStream::getImplementationName() throw () 1278*cdf0e10cSrcweir { 1279*cdf0e10cSrcweir return ODataInputStream_getImplementationName(); 1280*cdf0e10cSrcweir } 1281*cdf0e10cSrcweir 1282*cdf0e10cSrcweir // XServiceInfo 1283*cdf0e10cSrcweir sal_Bool OObjectOutputStream::supportsService(const OUString& ServiceName) throw () 1284*cdf0e10cSrcweir { 1285*cdf0e10cSrcweir Sequence< OUString > aSNL = getSupportedServiceNames(); 1286*cdf0e10cSrcweir const OUString * pArray = aSNL.getConstArray(); 1287*cdf0e10cSrcweir 1288*cdf0e10cSrcweir for( sal_Int32 i = 0; i < aSNL.getLength(); i++ ) 1289*cdf0e10cSrcweir if( pArray[i] == ServiceName ) 1290*cdf0e10cSrcweir return sal_True; 1291*cdf0e10cSrcweir 1292*cdf0e10cSrcweir return sal_False; 1293*cdf0e10cSrcweir } 1294*cdf0e10cSrcweir 1295*cdf0e10cSrcweir // XServiceInfo 1296*cdf0e10cSrcweir Sequence< OUString > OObjectOutputStream::getSupportedServiceNames(void) throw () 1297*cdf0e10cSrcweir { 1298*cdf0e10cSrcweir return OObjectOutputStream_getSupportedServiceNames(); 1299*cdf0e10cSrcweir } 1300*cdf0e10cSrcweir 1301*cdf0e10cSrcweir 1302*cdf0e10cSrcweir 1303*cdf0e10cSrcweir 1304*cdf0e10cSrcweir 1305*cdf0e10cSrcweir class OObjectInputStream : 1306*cdf0e10cSrcweir public ODataInputStream, 1307*cdf0e10cSrcweir public XObjectInputStream, 1308*cdf0e10cSrcweir public XMarkableStream 1309*cdf0e10cSrcweir { 1310*cdf0e10cSrcweir public: 1311*cdf0e10cSrcweir OObjectInputStream( const Reference < XComponentContext > &r) 1312*cdf0e10cSrcweir : m_rSMgr( r->getServiceManager() ) 1313*cdf0e10cSrcweir , m_rCxt( r ) 1314*cdf0e10cSrcweir , m_bValidMarkable(sal_False) 1315*cdf0e10cSrcweir { 1316*cdf0e10cSrcweir g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); 1317*cdf0e10cSrcweir } 1318*cdf0e10cSrcweir ~OObjectInputStream(); 1319*cdf0e10cSrcweir 1320*cdf0e10cSrcweir public: 1321*cdf0e10cSrcweir Any SAL_CALL queryInterface( const Type &type ) throw(); 1322*cdf0e10cSrcweir void SAL_CALL acquire() throw() { ODataInputStream::acquire(); } 1323*cdf0e10cSrcweir void SAL_CALL release() throw() { ODataInputStream::release(); } 1324*cdf0e10cSrcweir 1325*cdf0e10cSrcweir public: // XInputStream 1326*cdf0e10cSrcweir virtual sal_Int32 SAL_CALL readBytes(Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead) 1327*cdf0e10cSrcweir throw ( NotConnectedException, 1328*cdf0e10cSrcweir BufferSizeExceededException, 1329*cdf0e10cSrcweir RuntimeException) 1330*cdf0e10cSrcweir { return ODataInputStream::readBytes( aData , nBytesToRead ); } 1331*cdf0e10cSrcweir 1332*cdf0e10cSrcweir virtual sal_Int32 SAL_CALL readSomeBytes(Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead) 1333*cdf0e10cSrcweir throw ( NotConnectedException, 1334*cdf0e10cSrcweir BufferSizeExceededException, 1335*cdf0e10cSrcweir RuntimeException) 1336*cdf0e10cSrcweir { return ODataInputStream::readSomeBytes( aData, nMaxBytesToRead ); } 1337*cdf0e10cSrcweir 1338*cdf0e10cSrcweir virtual void SAL_CALL skipBytes(sal_Int32 nBytesToSkip) 1339*cdf0e10cSrcweir throw ( NotConnectedException, 1340*cdf0e10cSrcweir BufferSizeExceededException, 1341*cdf0e10cSrcweir RuntimeException) 1342*cdf0e10cSrcweir { ODataInputStream::skipBytes( nBytesToSkip ); } 1343*cdf0e10cSrcweir 1344*cdf0e10cSrcweir virtual sal_Int32 SAL_CALL available(void) 1345*cdf0e10cSrcweir throw ( NotConnectedException, 1346*cdf0e10cSrcweir RuntimeException) 1347*cdf0e10cSrcweir { return ODataInputStream::available(); } 1348*cdf0e10cSrcweir 1349*cdf0e10cSrcweir virtual void SAL_CALL closeInput(void) 1350*cdf0e10cSrcweir throw ( NotConnectedException, 1351*cdf0e10cSrcweir RuntimeException) 1352*cdf0e10cSrcweir { ODataInputStream::closeInput(); } 1353*cdf0e10cSrcweir 1354*cdf0e10cSrcweir public: // XDataInputStream 1355*cdf0e10cSrcweir virtual sal_Int8 SAL_CALL readBoolean(void) throw (IOException, RuntimeException) 1356*cdf0e10cSrcweir { return ODataInputStream::readBoolean(); } 1357*cdf0e10cSrcweir virtual sal_Int8 SAL_CALL readByte(void) throw (IOException, RuntimeException) 1358*cdf0e10cSrcweir { return ODataInputStream::readByte(); } 1359*cdf0e10cSrcweir virtual sal_Unicode SAL_CALL readChar(void) throw (IOException, RuntimeException) 1360*cdf0e10cSrcweir { return ODataInputStream::readChar(); } 1361*cdf0e10cSrcweir virtual sal_Int16 SAL_CALL readShort(void) throw (IOException, RuntimeException) 1362*cdf0e10cSrcweir { return ODataInputStream::readShort(); } 1363*cdf0e10cSrcweir virtual sal_Int32 SAL_CALL readLong(void) throw (IOException, RuntimeException) 1364*cdf0e10cSrcweir { return ODataInputStream::readLong(); } 1365*cdf0e10cSrcweir virtual sal_Int64 SAL_CALL readHyper(void) throw (IOException, RuntimeException) 1366*cdf0e10cSrcweir { return ODataInputStream::readHyper(); } 1367*cdf0e10cSrcweir virtual float SAL_CALL readFloat(void) throw (IOException, RuntimeException) 1368*cdf0e10cSrcweir { return ODataInputStream::readFloat(); } 1369*cdf0e10cSrcweir virtual double SAL_CALL readDouble(void) throw (IOException, RuntimeException) 1370*cdf0e10cSrcweir { return ODataInputStream::readDouble(); } 1371*cdf0e10cSrcweir virtual OUString SAL_CALL readUTF(void) throw (IOException, RuntimeException) 1372*cdf0e10cSrcweir { return ODataInputStream::readUTF(); } 1373*cdf0e10cSrcweir 1374*cdf0e10cSrcweir public: // XObjectInputStream 1375*cdf0e10cSrcweir virtual Reference< XPersistObject > SAL_CALL readObject( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); 1376*cdf0e10cSrcweir 1377*cdf0e10cSrcweir public: // XMarkableStream 1378*cdf0e10cSrcweir virtual sal_Int32 SAL_CALL createMark(void) 1379*cdf0e10cSrcweir throw (IOException, RuntimeException); 1380*cdf0e10cSrcweir virtual void SAL_CALL deleteMark(sal_Int32 Mark) throw (IOException, IllegalArgumentException, RuntimeException); 1381*cdf0e10cSrcweir virtual void SAL_CALL jumpToMark(sal_Int32 nMark) throw (IOException, IllegalArgumentException, RuntimeException); 1382*cdf0e10cSrcweir virtual void SAL_CALL jumpToFurthest(void) throw (IOException, RuntimeException); 1383*cdf0e10cSrcweir virtual sal_Int32 SAL_CALL offsetToMark(sal_Int32 nMark) 1384*cdf0e10cSrcweir throw (IOException, IllegalArgumentException, RuntimeException); 1385*cdf0e10cSrcweir 1386*cdf0e10cSrcweir public: //XTypeProvider 1387*cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL 1388*cdf0e10cSrcweir getTypes( ) throw(::com::sun::star::uno::RuntimeException); 1389*cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL 1390*cdf0e10cSrcweir getImplementationId( ) throw(::com::sun::star::uno::RuntimeException); 1391*cdf0e10cSrcweir 1392*cdf0e10cSrcweir public: // XServiceInfo 1393*cdf0e10cSrcweir OUString SAL_CALL getImplementationName() throw (); 1394*cdf0e10cSrcweir Sequence< OUString > SAL_CALL getSupportedServiceNames(void) throw (); 1395*cdf0e10cSrcweir sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw (); 1396*cdf0e10cSrcweir 1397*cdf0e10cSrcweir private: 1398*cdf0e10cSrcweir void connectToMarkable(); 1399*cdf0e10cSrcweir private: 1400*cdf0e10cSrcweir Reference < XMultiComponentFactory > m_rSMgr; 1401*cdf0e10cSrcweir Reference < XComponentContext > m_rCxt; 1402*cdf0e10cSrcweir sal_Bool m_bValidMarkable; 1403*cdf0e10cSrcweir Reference < XMarkableStream > m_rMarkable; 1404*cdf0e10cSrcweir vector < Reference< XPersistObject > > m_aPersistVector; 1405*cdf0e10cSrcweir 1406*cdf0e10cSrcweir }; 1407*cdf0e10cSrcweir 1408*cdf0e10cSrcweir OObjectInputStream::~OObjectInputStream() 1409*cdf0e10cSrcweir { 1410*cdf0e10cSrcweir g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); 1411*cdf0e10cSrcweir } 1412*cdf0e10cSrcweir 1413*cdf0e10cSrcweir Any OObjectInputStream::queryInterface( const Type &aType ) throw () 1414*cdf0e10cSrcweir { 1415*cdf0e10cSrcweir Any a = ::cppu::queryInterface( 1416*cdf0e10cSrcweir aType , 1417*cdf0e10cSrcweir SAL_STATIC_CAST( XMarkableStream * , this ), 1418*cdf0e10cSrcweir SAL_STATIC_CAST( XObjectInputStream * , this ) ); 1419*cdf0e10cSrcweir if( a.hasValue() ) 1420*cdf0e10cSrcweir { 1421*cdf0e10cSrcweir return a; 1422*cdf0e10cSrcweir } 1423*cdf0e10cSrcweir 1424*cdf0e10cSrcweir return ODataInputStream::queryInterface( aType ); 1425*cdf0e10cSrcweir 1426*cdf0e10cSrcweir } 1427*cdf0e10cSrcweir 1428*cdf0e10cSrcweir Reference< XPersistObject > OObjectInputStream::readObject() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) 1429*cdf0e10cSrcweir { 1430*cdf0e10cSrcweir // check if chain contains a XMarkableStream 1431*cdf0e10cSrcweir connectToMarkable(); 1432*cdf0e10cSrcweir 1433*cdf0e10cSrcweir Reference< XPersistObject > xLoadedObj; 1434*cdf0e10cSrcweir 1435*cdf0e10cSrcweir // create Mark to skip newer versions 1436*cdf0e10cSrcweir sal_uInt32 nMark = m_rMarkable->createMark(); 1437*cdf0e10cSrcweir // length of the data 1438*cdf0e10cSrcweir sal_Int32 nLen = (sal_uInt16) ODataInputStream::readShort(); 1439*cdf0e10cSrcweir if( nLen < 0xc ) 1440*cdf0e10cSrcweir { 1441*cdf0e10cSrcweir throw WrongFormatException(); 1442*cdf0e10cSrcweir } 1443*cdf0e10cSrcweir 1444*cdf0e10cSrcweir // read the object identifier 1445*cdf0e10cSrcweir sal_uInt32 nId = readLong(); 1446*cdf0e10cSrcweir 1447*cdf0e10cSrcweir // the name of the persist model 1448*cdf0e10cSrcweir // MM ??? 1449*cdf0e10cSrcweir OUString aName = readUTF(); 1450*cdf0e10cSrcweir 1451*cdf0e10cSrcweir // Read the length of the object 1452*cdf0e10cSrcweir sal_Int32 nObjLen = readLong(); 1453*cdf0e10cSrcweir if( ( 0 == nId && 0 != nObjLen ) ) 1454*cdf0e10cSrcweir { 1455*cdf0e10cSrcweir throw WrongFormatException(); 1456*cdf0e10cSrcweir } 1457*cdf0e10cSrcweir 1458*cdf0e10cSrcweir // skip data of new version 1459*cdf0e10cSrcweir skipBytes( nLen - m_rMarkable->offsetToMark( nMark ) ); 1460*cdf0e10cSrcweir 1461*cdf0e10cSrcweir sal_Bool bLoadSuccesfull = sal_True; 1462*cdf0e10cSrcweir if( nId ) 1463*cdf0e10cSrcweir { 1464*cdf0e10cSrcweir if( aName.getLength() ) 1465*cdf0e10cSrcweir { 1466*cdf0e10cSrcweir // load the object 1467*cdf0e10cSrcweir Reference< XInterface > x = m_rSMgr->createInstanceWithContext( aName, m_rCxt ); 1468*cdf0e10cSrcweir xLoadedObj = Reference< XPersistObject >( x, UNO_QUERY ); 1469*cdf0e10cSrcweir if( xLoadedObj.is() ) 1470*cdf0e10cSrcweir { 1471*cdf0e10cSrcweir sal_uInt32 nSize = m_aPersistVector.size(); 1472*cdf0e10cSrcweir if( nSize <= nId ) 1473*cdf0e10cSrcweir { 1474*cdf0e10cSrcweir // grow to the right size 1475*cdf0e10cSrcweir Reference< XPersistObject > xEmpty; 1476*cdf0e10cSrcweir m_aPersistVector.insert( m_aPersistVector.end(), (long)(nId - nSize + 1), xEmpty ); 1477*cdf0e10cSrcweir } 1478*cdf0e10cSrcweir 1479*cdf0e10cSrcweir m_aPersistVector[nId] = xLoadedObj; 1480*cdf0e10cSrcweir xLoadedObj->read( Reference< XObjectInputStream >( 1481*cdf0e10cSrcweir SAL_STATIC_CAST( XObjectInputStream *, this ) ) ); 1482*cdf0e10cSrcweir } 1483*cdf0e10cSrcweir else 1484*cdf0e10cSrcweir { 1485*cdf0e10cSrcweir // no service with this name could be instantiated 1486*cdf0e10cSrcweir bLoadSuccesfull = sal_False; 1487*cdf0e10cSrcweir } 1488*cdf0e10cSrcweir } 1489*cdf0e10cSrcweir else { 1490*cdf0e10cSrcweir if( m_aPersistVector.size() < nId ) 1491*cdf0e10cSrcweir { 1492*cdf0e10cSrcweir // id unknown, load failure ! 1493*cdf0e10cSrcweir bLoadSuccesfull = sal_False; 1494*cdf0e10cSrcweir } 1495*cdf0e10cSrcweir else 1496*cdf0e10cSrcweir { 1497*cdf0e10cSrcweir // Object has alread been read, 1498*cdf0e10cSrcweir xLoadedObj = m_aPersistVector[nId]; 1499*cdf0e10cSrcweir } 1500*cdf0e10cSrcweir } 1501*cdf0e10cSrcweir } 1502*cdf0e10cSrcweir 1503*cdf0e10cSrcweir // skip to the position behind the object 1504*cdf0e10cSrcweir skipBytes( nObjLen + nLen - m_rMarkable->offsetToMark( nMark ) ); 1505*cdf0e10cSrcweir m_rMarkable->deleteMark( nMark ); 1506*cdf0e10cSrcweir 1507*cdf0e10cSrcweir if( ! bLoadSuccesfull ) 1508*cdf0e10cSrcweir { 1509*cdf0e10cSrcweir throw WrongFormatException(); 1510*cdf0e10cSrcweir } 1511*cdf0e10cSrcweir return xLoadedObj; 1512*cdf0e10cSrcweir } 1513*cdf0e10cSrcweir 1514*cdf0e10cSrcweir 1515*cdf0e10cSrcweir void OObjectInputStream::connectToMarkable() 1516*cdf0e10cSrcweir { 1517*cdf0e10cSrcweir if( ! m_bValidMarkable ) { 1518*cdf0e10cSrcweir if( ! m_bValidStream ) 1519*cdf0e10cSrcweir { 1520*cdf0e10cSrcweir throw NotConnectedException( ); 1521*cdf0e10cSrcweir } 1522*cdf0e10cSrcweir 1523*cdf0e10cSrcweir // find the markable stream ! 1524*cdf0e10cSrcweir Reference< XInterface > rTry(m_input); 1525*cdf0e10cSrcweir while( sal_True ) { 1526*cdf0e10cSrcweir if( ! rTry.is() ) 1527*cdf0e10cSrcweir { 1528*cdf0e10cSrcweir throw NotConnectedException( ); 1529*cdf0e10cSrcweir } 1530*cdf0e10cSrcweir Reference< XMarkableStream > markable( rTry , UNO_QUERY ); 1531*cdf0e10cSrcweir if( markable.is() ) 1532*cdf0e10cSrcweir { 1533*cdf0e10cSrcweir m_rMarkable = markable; 1534*cdf0e10cSrcweir break; 1535*cdf0e10cSrcweir } 1536*cdf0e10cSrcweir Reference < XActiveDataSink > sink( rTry , UNO_QUERY ); 1537*cdf0e10cSrcweir rTry = sink; 1538*cdf0e10cSrcweir } 1539*cdf0e10cSrcweir m_bValidMarkable = sal_True; 1540*cdf0e10cSrcweir } 1541*cdf0e10cSrcweir } 1542*cdf0e10cSrcweir 1543*cdf0e10cSrcweir sal_Int32 OObjectInputStream::createMark(void) throw (IOException, RuntimeException) 1544*cdf0e10cSrcweir { 1545*cdf0e10cSrcweir connectToMarkable(); // throws an exception, if a markable is not connected ! 1546*cdf0e10cSrcweir 1547*cdf0e10cSrcweir return m_rMarkable->createMark(); 1548*cdf0e10cSrcweir } 1549*cdf0e10cSrcweir 1550*cdf0e10cSrcweir void OObjectInputStream::deleteMark(sal_Int32 Mark) throw (IOException, IllegalArgumentException, RuntimeException) 1551*cdf0e10cSrcweir { 1552*cdf0e10cSrcweir if( ! m_bValidMarkable ) 1553*cdf0e10cSrcweir { 1554*cdf0e10cSrcweir throw NotConnectedException(); 1555*cdf0e10cSrcweir } 1556*cdf0e10cSrcweir m_rMarkable->deleteMark( Mark ); 1557*cdf0e10cSrcweir } 1558*cdf0e10cSrcweir 1559*cdf0e10cSrcweir void OObjectInputStream::jumpToMark(sal_Int32 nMark) throw (IOException, IllegalArgumentException, RuntimeException) 1560*cdf0e10cSrcweir { 1561*cdf0e10cSrcweir if( ! m_bValidMarkable ) 1562*cdf0e10cSrcweir { 1563*cdf0e10cSrcweir throw NotConnectedException(); 1564*cdf0e10cSrcweir } 1565*cdf0e10cSrcweir m_rMarkable->jumpToMark( nMark ); 1566*cdf0e10cSrcweir } 1567*cdf0e10cSrcweir void OObjectInputStream::jumpToFurthest(void) throw (IOException, RuntimeException) 1568*cdf0e10cSrcweir { 1569*cdf0e10cSrcweir connectToMarkable(); 1570*cdf0e10cSrcweir m_rMarkable->jumpToFurthest(); 1571*cdf0e10cSrcweir } 1572*cdf0e10cSrcweir 1573*cdf0e10cSrcweir sal_Int32 OObjectInputStream::offsetToMark(sal_Int32 nMark) 1574*cdf0e10cSrcweir throw (IOException, IllegalArgumentException, RuntimeException) 1575*cdf0e10cSrcweir { 1576*cdf0e10cSrcweir if( ! m_bValidMarkable ) 1577*cdf0e10cSrcweir { 1578*cdf0e10cSrcweir throw NotConnectedException(); 1579*cdf0e10cSrcweir } 1580*cdf0e10cSrcweir return m_rMarkable->offsetToMark( nMark ); 1581*cdf0e10cSrcweir } 1582*cdf0e10cSrcweir 1583*cdf0e10cSrcweir 1584*cdf0e10cSrcweir Sequence< Type > SAL_CALL OObjectInputStream::getTypes(void) throw( RuntimeException ) 1585*cdf0e10cSrcweir { 1586*cdf0e10cSrcweir static OTypeCollection *pCollection = 0; 1587*cdf0e10cSrcweir if( ! pCollection ) 1588*cdf0e10cSrcweir { 1589*cdf0e10cSrcweir MutexGuard guard( Mutex::getGlobalMutex() ); 1590*cdf0e10cSrcweir if( ! pCollection ) 1591*cdf0e10cSrcweir { 1592*cdf0e10cSrcweir static OTypeCollection collection( 1593*cdf0e10cSrcweir getCppuType( (Reference< XMarkableStream > * ) 0 ), 1594*cdf0e10cSrcweir getCppuType( (Reference< XObjectInputStream > * ) 0 ), 1595*cdf0e10cSrcweir ODataInputStream::getTypes() ); 1596*cdf0e10cSrcweir pCollection = &collection; 1597*cdf0e10cSrcweir } 1598*cdf0e10cSrcweir } 1599*cdf0e10cSrcweir return (*pCollection).getTypes(); 1600*cdf0e10cSrcweir } 1601*cdf0e10cSrcweir 1602*cdf0e10cSrcweir Sequence< sal_Int8 > SAL_CALL OObjectInputStream::getImplementationId( ) throw( RuntimeException) 1603*cdf0e10cSrcweir { 1604*cdf0e10cSrcweir static OImplementationId *pId = 0; 1605*cdf0e10cSrcweir if( ! pId ) 1606*cdf0e10cSrcweir { 1607*cdf0e10cSrcweir MutexGuard guard( Mutex::getGlobalMutex() ); 1608*cdf0e10cSrcweir if( ! pId ) 1609*cdf0e10cSrcweir { 1610*cdf0e10cSrcweir static OImplementationId id( sal_False ); 1611*cdf0e10cSrcweir pId = &id; 1612*cdf0e10cSrcweir } 1613*cdf0e10cSrcweir } 1614*cdf0e10cSrcweir return (*pId).getImplementationId(); 1615*cdf0e10cSrcweir } 1616*cdf0e10cSrcweir 1617*cdf0e10cSrcweir 1618*cdf0e10cSrcweir // XServiceInfo 1619*cdf0e10cSrcweir OUString OObjectInputStream::getImplementationName() throw () 1620*cdf0e10cSrcweir { 1621*cdf0e10cSrcweir return OObjectInputStream_getImplementationName(); 1622*cdf0e10cSrcweir } 1623*cdf0e10cSrcweir 1624*cdf0e10cSrcweir // XServiceInfo 1625*cdf0e10cSrcweir sal_Bool OObjectInputStream::supportsService(const OUString& ServiceName) throw () 1626*cdf0e10cSrcweir { 1627*cdf0e10cSrcweir Sequence< OUString > aSNL = getSupportedServiceNames(); 1628*cdf0e10cSrcweir const OUString * pArray = aSNL.getConstArray(); 1629*cdf0e10cSrcweir 1630*cdf0e10cSrcweir for( sal_Int32 i = 0; i < aSNL.getLength(); i++ ) 1631*cdf0e10cSrcweir if( pArray[i] == ServiceName ) 1632*cdf0e10cSrcweir return sal_True; 1633*cdf0e10cSrcweir 1634*cdf0e10cSrcweir return sal_False; 1635*cdf0e10cSrcweir } 1636*cdf0e10cSrcweir 1637*cdf0e10cSrcweir // XServiceInfo 1638*cdf0e10cSrcweir Sequence< OUString > OObjectInputStream::getSupportedServiceNames(void) throw () 1639*cdf0e10cSrcweir { 1640*cdf0e10cSrcweir return OObjectInputStream_getSupportedServiceNames(); 1641*cdf0e10cSrcweir } 1642*cdf0e10cSrcweir 1643*cdf0e10cSrcweir 1644*cdf0e10cSrcweir 1645*cdf0e10cSrcweir 1646*cdf0e10cSrcweir Reference< XInterface > SAL_CALL OObjectInputStream_CreateInstance( const Reference < XComponentContext > & rCtx ) throw(Exception) 1647*cdf0e10cSrcweir { 1648*cdf0e10cSrcweir OObjectInputStream *p = new OObjectInputStream( rCtx ); 1649*cdf0e10cSrcweir return Reference< XInterface> ( SAL_STATIC_CAST( OWeakObject *, p ) ); 1650*cdf0e10cSrcweir } 1651*cdf0e10cSrcweir 1652*cdf0e10cSrcweir OUString OObjectInputStream_getImplementationName() 1653*cdf0e10cSrcweir { 1654*cdf0e10cSrcweir return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.io.stm.ObjectInputStream" ) ); 1655*cdf0e10cSrcweir } 1656*cdf0e10cSrcweir 1657*cdf0e10cSrcweir Sequence<OUString> OObjectInputStream_getSupportedServiceNames(void) 1658*cdf0e10cSrcweir { 1659*cdf0e10cSrcweir Sequence<OUString> aRet(1); 1660*cdf0e10cSrcweir aRet.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.ObjectInputStream" ) ); 1661*cdf0e10cSrcweir return aRet; 1662*cdf0e10cSrcweir } 1663*cdf0e10cSrcweir 1664*cdf0e10cSrcweir } 1665