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 #include <string.h> 33*cdf0e10cSrcweir #include <osl/mutex.hxx> 34*cdf0e10cSrcweir #include <osl/diagnose.h> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include <rtl/unload.h> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #include <uno/mapping.hxx> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #include <cppuhelper/factory.hxx> 41*cdf0e10cSrcweir #include <cppuhelper/implbase3.hxx> 42*cdf0e10cSrcweir #include <cppuhelper/implementationentry.hxx> 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir #include <rtl/textenc.h> 45*cdf0e10cSrcweir #include <rtl/tencinfo.h> 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir #include <com/sun/star/io/XTextInputStream.hpp> 48*cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSink.hpp> 49*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir #define IMPLEMENTATION_NAME "com.sun.star.comp.io.TextInputStream" 53*cdf0e10cSrcweir #define SERVICE_NAME "com.sun.star.io.TextInputStream" 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir using namespace ::osl; 56*cdf0e10cSrcweir using namespace ::rtl; 57*cdf0e10cSrcweir using namespace ::cppu; 58*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 59*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 60*cdf0e10cSrcweir using namespace ::com::sun::star::io; 61*cdf0e10cSrcweir using namespace ::com::sun::star::registry; 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir namespace io_TextInputStream 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir rtl_StandardModuleCount g_moduleCount = MODULE_COUNT_INIT; 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir //=========================================================================== 68*cdf0e10cSrcweir // Implementation XTextInputStream 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir typedef WeakImplHelper3< XTextInputStream, XActiveDataSink, XServiceInfo > TextInputStreamHelper; 71*cdf0e10cSrcweir class OCommandEnvironment; 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir #define INITIAL_UNICODE_BUFFER_CAPACITY 0x100 74*cdf0e10cSrcweir #define READ_BYTE_COUNT 0x100 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir class OTextInputStream : public TextInputStreamHelper 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir Reference< XInputStream > mxStream; 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir // Encoding 81*cdf0e10cSrcweir OUString mEncoding; 82*cdf0e10cSrcweir sal_Bool mbEncodingInitialized; 83*cdf0e10cSrcweir rtl_TextToUnicodeConverter mConvText2Unicode; 84*cdf0e10cSrcweir rtl_TextToUnicodeContext mContextText2Unicode; 85*cdf0e10cSrcweir Sequence<sal_Int8> mSeqSource; 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir // Internal buffer for characters that are already converted successfully 88*cdf0e10cSrcweir sal_Unicode* mpBuffer; 89*cdf0e10cSrcweir sal_Int32 mnBufferSize; 90*cdf0e10cSrcweir sal_Int32 mnCharsInBuffer; 91*cdf0e10cSrcweir sal_Bool mbReachedEOF; 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir void implResizeBuffer( void ); 94*cdf0e10cSrcweir OUString implReadString( const Sequence< sal_Unicode >& Delimiters, 95*cdf0e10cSrcweir sal_Bool bRemoveDelimiter, sal_Bool bFindLineEnd ) 96*cdf0e10cSrcweir throw(IOException, RuntimeException); 97*cdf0e10cSrcweir sal_Int32 implReadNext() throw(IOException, RuntimeException); 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir public: 100*cdf0e10cSrcweir OTextInputStream(); 101*cdf0e10cSrcweir virtual ~OTextInputStream(); 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir // Methods XTextInputStream 104*cdf0e10cSrcweir virtual OUString SAL_CALL readLine( ) 105*cdf0e10cSrcweir throw(IOException, RuntimeException); 106*cdf0e10cSrcweir virtual OUString SAL_CALL readString( const Sequence< sal_Unicode >& Delimiters, sal_Bool bRemoveDelimiter ) 107*cdf0e10cSrcweir throw(IOException, RuntimeException); 108*cdf0e10cSrcweir virtual sal_Bool SAL_CALL isEOF( ) 109*cdf0e10cSrcweir throw(IOException, RuntimeException); 110*cdf0e10cSrcweir virtual void SAL_CALL setEncoding( const OUString& Encoding ) throw(RuntimeException); 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir // Methods XInputStream 113*cdf0e10cSrcweir virtual sal_Int32 SAL_CALL readBytes( Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) 114*cdf0e10cSrcweir throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException); 115*cdf0e10cSrcweir virtual sal_Int32 SAL_CALL readSomeBytes( Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) 116*cdf0e10cSrcweir throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException); 117*cdf0e10cSrcweir virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) 118*cdf0e10cSrcweir throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException); 119*cdf0e10cSrcweir virtual sal_Int32 SAL_CALL available( ) 120*cdf0e10cSrcweir throw(NotConnectedException, IOException, RuntimeException); 121*cdf0e10cSrcweir virtual void SAL_CALL closeInput( ) 122*cdf0e10cSrcweir throw(NotConnectedException, IOException, RuntimeException); 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir // Methods XActiveDataSink 125*cdf0e10cSrcweir virtual void SAL_CALL setInputStream( const Reference< XInputStream >& aStream ) 126*cdf0e10cSrcweir throw(RuntimeException); 127*cdf0e10cSrcweir virtual Reference< XInputStream > SAL_CALL getInputStream() 128*cdf0e10cSrcweir throw(RuntimeException); 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir // Methods XServiceInfo 131*cdf0e10cSrcweir virtual OUString SAL_CALL getImplementationName() throw(); 132*cdf0e10cSrcweir virtual Sequence< OUString > SAL_CALL getSupportedServiceNames(void) throw(); 133*cdf0e10cSrcweir virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw(); 134*cdf0e10cSrcweir }; 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir OTextInputStream::OTextInputStream() 137*cdf0e10cSrcweir : mSeqSource( READ_BYTE_COUNT ), mpBuffer( NULL ), mnBufferSize( 0 ) 138*cdf0e10cSrcweir , mnCharsInBuffer( 0 ), mbReachedEOF( sal_False ) 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); 141*cdf0e10cSrcweir mbEncodingInitialized = false; 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir OTextInputStream::~OTextInputStream() 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir if( mbEncodingInitialized ) 147*cdf0e10cSrcweir { 148*cdf0e10cSrcweir rtl_destroyUnicodeToTextContext( mConvText2Unicode, mContextText2Unicode ); 149*cdf0e10cSrcweir rtl_destroyUnicodeToTextConverter( mConvText2Unicode ); 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir void OTextInputStream::implResizeBuffer( void ) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir sal_Int32 mnNewBufferSize = mnBufferSize * 2; 157*cdf0e10cSrcweir sal_Unicode* pNewBuffer = new sal_Unicode[ mnNewBufferSize ]; 158*cdf0e10cSrcweir memcpy( pNewBuffer, mpBuffer, mnCharsInBuffer * sizeof( sal_Unicode ) ); 159*cdf0e10cSrcweir mpBuffer = pNewBuffer; 160*cdf0e10cSrcweir mnBufferSize = mnNewBufferSize; 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir //=========================================================================== 165*cdf0e10cSrcweir // XTextInputStream 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir OUString OTextInputStream::readLine( ) 168*cdf0e10cSrcweir throw(IOException, RuntimeException) 169*cdf0e10cSrcweir { 170*cdf0e10cSrcweir static Sequence< sal_Unicode > aDummySeq; 171*cdf0e10cSrcweir return implReadString( aDummySeq, sal_True, sal_True ); 172*cdf0e10cSrcweir } 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir OUString OTextInputStream::readString( const Sequence< sal_Unicode >& Delimiters, sal_Bool bRemoveDelimiter ) 175*cdf0e10cSrcweir throw(IOException, RuntimeException) 176*cdf0e10cSrcweir { 177*cdf0e10cSrcweir return implReadString( Delimiters, bRemoveDelimiter, sal_False ); 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir sal_Bool OTextInputStream::isEOF() 181*cdf0e10cSrcweir throw(IOException, RuntimeException) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir sal_Bool bRet = sal_False; 184*cdf0e10cSrcweir if( mnCharsInBuffer == 0 && mbReachedEOF ) 185*cdf0e10cSrcweir bRet = sal_True; 186*cdf0e10cSrcweir return bRet; 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir OUString OTextInputStream::implReadString( const Sequence< sal_Unicode >& Delimiters, 191*cdf0e10cSrcweir sal_Bool bRemoveDelimiter, sal_Bool bFindLineEnd ) 192*cdf0e10cSrcweir throw(IOException, RuntimeException) 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir OUString aRetStr; 195*cdf0e10cSrcweir if( !mbEncodingInitialized ) 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir OUString aUtf8Str( RTL_CONSTASCII_USTRINGPARAM("utf8") ); 198*cdf0e10cSrcweir setEncoding( aUtf8Str ); 199*cdf0e10cSrcweir } 200*cdf0e10cSrcweir if( !mbEncodingInitialized ) 201*cdf0e10cSrcweir return aRetStr; 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir if( !mpBuffer ) 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir mnBufferSize = INITIAL_UNICODE_BUFFER_CAPACITY; 206*cdf0e10cSrcweir mpBuffer = new sal_Unicode[ mnBufferSize ]; 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir // Only for bFindLineEnd 210*cdf0e10cSrcweir sal_Unicode cLineEndChar1 = 0x0D; 211*cdf0e10cSrcweir sal_Unicode cLineEndChar2 = 0x0A; 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir sal_Int32 nBufferReadPos = 0; 214*cdf0e10cSrcweir sal_Int32 nCopyLen = 0; 215*cdf0e10cSrcweir sal_Bool bFound = sal_False; 216*cdf0e10cSrcweir sal_Bool bFoundFirstLineEndChar = sal_False; 217*cdf0e10cSrcweir sal_Unicode cFirstLineEndChar = 0; 218*cdf0e10cSrcweir const sal_Unicode* pDelims = Delimiters.getConstArray(); 219*cdf0e10cSrcweir const sal_Int32 nDelimCount = Delimiters.getLength(); 220*cdf0e10cSrcweir while( !bFound ) 221*cdf0e10cSrcweir { 222*cdf0e10cSrcweir // Still characters available? 223*cdf0e10cSrcweir if( nBufferReadPos == mnCharsInBuffer ) 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir // Already reached EOF? Then we can't read any more 226*cdf0e10cSrcweir if( mbReachedEOF ) 227*cdf0e10cSrcweir break; 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir // No, so read new characters 230*cdf0e10cSrcweir if( !implReadNext() ) 231*cdf0e10cSrcweir break; 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir // Now there should be characters available 235*cdf0e10cSrcweir // (otherwise the loop should have been breaked before) 236*cdf0e10cSrcweir sal_Unicode c = mpBuffer[ nBufferReadPos++ ]; 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir if( bFindLineEnd ) 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir if( bFoundFirstLineEndChar ) 241*cdf0e10cSrcweir { 242*cdf0e10cSrcweir bFound = sal_True; 243*cdf0e10cSrcweir nCopyLen = nBufferReadPos - 2; 244*cdf0e10cSrcweir if( c == cLineEndChar1 || c == cLineEndChar2 ) 245*cdf0e10cSrcweir { 246*cdf0e10cSrcweir // Same line end char -> new line break 247*cdf0e10cSrcweir if( c == cFirstLineEndChar ) 248*cdf0e10cSrcweir { 249*cdf0e10cSrcweir nBufferReadPos--; 250*cdf0e10cSrcweir } 251*cdf0e10cSrcweir } 252*cdf0e10cSrcweir else 253*cdf0e10cSrcweir { 254*cdf0e10cSrcweir // No second line end char 255*cdf0e10cSrcweir nBufferReadPos--; 256*cdf0e10cSrcweir } 257*cdf0e10cSrcweir } 258*cdf0e10cSrcweir else if( c == cLineEndChar1 || c == cLineEndChar2 ) 259*cdf0e10cSrcweir { 260*cdf0e10cSrcweir bFoundFirstLineEndChar = sal_True; 261*cdf0e10cSrcweir cFirstLineEndChar = c; 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir else 265*cdf0e10cSrcweir { 266*cdf0e10cSrcweir for( sal_Int32 i = 0 ; i < nDelimCount ; i++ ) 267*cdf0e10cSrcweir { 268*cdf0e10cSrcweir if( c == pDelims[ i ] ) 269*cdf0e10cSrcweir { 270*cdf0e10cSrcweir bFound = sal_True; 271*cdf0e10cSrcweir nCopyLen = nBufferReadPos; 272*cdf0e10cSrcweir if( bRemoveDelimiter ) 273*cdf0e10cSrcweir nCopyLen--; 274*cdf0e10cSrcweir } 275*cdf0e10cSrcweir } 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir } 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir // Nothing found? Return all 280*cdf0e10cSrcweir if( !nCopyLen && !bFound && mbReachedEOF ) 281*cdf0e10cSrcweir nCopyLen = nBufferReadPos; 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir // Create string 284*cdf0e10cSrcweir if( nCopyLen ) 285*cdf0e10cSrcweir aRetStr = OUString( mpBuffer, nCopyLen ); 286*cdf0e10cSrcweir 287*cdf0e10cSrcweir // Copy rest of buffer 288*cdf0e10cSrcweir memmove( mpBuffer, mpBuffer + nBufferReadPos, 289*cdf0e10cSrcweir (mnCharsInBuffer - nBufferReadPos) * sizeof( sal_Unicode ) ); 290*cdf0e10cSrcweir mnCharsInBuffer -= nBufferReadPos; 291*cdf0e10cSrcweir 292*cdf0e10cSrcweir return aRetStr; 293*cdf0e10cSrcweir } 294*cdf0e10cSrcweir 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir sal_Int32 OTextInputStream::implReadNext() 297*cdf0e10cSrcweir throw(IOException, RuntimeException) 298*cdf0e10cSrcweir { 299*cdf0e10cSrcweir sal_Int32 nFreeBufferSize = mnBufferSize - mnCharsInBuffer; 300*cdf0e10cSrcweir if( nFreeBufferSize < READ_BYTE_COUNT ) 301*cdf0e10cSrcweir implResizeBuffer(); 302*cdf0e10cSrcweir nFreeBufferSize = mnBufferSize - mnCharsInBuffer; 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir try 305*cdf0e10cSrcweir { 306*cdf0e10cSrcweir sal_Int32 nBytesToRead = READ_BYTE_COUNT; 307*cdf0e10cSrcweir sal_Int32 nRead = mxStream->readSomeBytes( mSeqSource, nBytesToRead ); 308*cdf0e10cSrcweir sal_Int32 nTotalRead = nRead; 309*cdf0e10cSrcweir if( nRead < nBytesToRead ) 310*cdf0e10cSrcweir mbReachedEOF = sal_True; 311*cdf0e10cSrcweir 312*cdf0e10cSrcweir // Try to convert 313*cdf0e10cSrcweir sal_uInt32 uiInfo; 314*cdf0e10cSrcweir sal_Size nSrcCvtBytes = 0; 315*cdf0e10cSrcweir sal_Size nTargetCount = 0; 316*cdf0e10cSrcweir sal_Size nSourceCount = 0; 317*cdf0e10cSrcweir while( sal_True ) 318*cdf0e10cSrcweir { 319*cdf0e10cSrcweir const sal_Int8 *pbSource = mSeqSource.getConstArray(); 320*cdf0e10cSrcweir 321*cdf0e10cSrcweir // All invalid characters are transformed to the unicode undefined char 322*cdf0e10cSrcweir nTargetCount += rtl_convertTextToUnicode( 323*cdf0e10cSrcweir mConvText2Unicode, 324*cdf0e10cSrcweir mContextText2Unicode, 325*cdf0e10cSrcweir (const sal_Char*) &( pbSource[nSourceCount] ), 326*cdf0e10cSrcweir nTotalRead - nSourceCount, 327*cdf0e10cSrcweir mpBuffer + mnCharsInBuffer + nTargetCount, 328*cdf0e10cSrcweir nFreeBufferSize - nTargetCount, 329*cdf0e10cSrcweir RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_DEFAULT | 330*cdf0e10cSrcweir RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_DEFAULT | 331*cdf0e10cSrcweir RTL_TEXTTOUNICODE_FLAGS_INVALID_DEFAULT, 332*cdf0e10cSrcweir &uiInfo, 333*cdf0e10cSrcweir &nSrcCvtBytes ); 334*cdf0e10cSrcweir nSourceCount += nSrcCvtBytes; 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir sal_Bool bCont = sal_False; 337*cdf0e10cSrcweir if( uiInfo & RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL ) 338*cdf0e10cSrcweir { 339*cdf0e10cSrcweir implResizeBuffer(); 340*cdf0e10cSrcweir bCont = sal_True; 341*cdf0e10cSrcweir } 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir if( uiInfo & RTL_TEXTTOUNICODE_INFO_SRCBUFFERTOSMALL ) 344*cdf0e10cSrcweir { 345*cdf0e10cSrcweir // read next byte 346*cdf0e10cSrcweir static Sequence< sal_Int8 > aOneByteSeq( 1 ); 347*cdf0e10cSrcweir nRead = mxStream->readSomeBytes( aOneByteSeq, 1 ); 348*cdf0e10cSrcweir if( nRead == 0 ) 349*cdf0e10cSrcweir { 350*cdf0e10cSrcweir mbReachedEOF = sal_True; 351*cdf0e10cSrcweir break; 352*cdf0e10cSrcweir } 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir sal_Int32 nOldLen = mSeqSource.getLength(); 355*cdf0e10cSrcweir nTotalRead++; 356*cdf0e10cSrcweir if( nTotalRead > nOldLen ) 357*cdf0e10cSrcweir { 358*cdf0e10cSrcweir mSeqSource.realloc( nTotalRead ); 359*cdf0e10cSrcweir } 360*cdf0e10cSrcweir mSeqSource.getArray()[ nOldLen ] = aOneByteSeq.getConstArray()[ 0 ]; 361*cdf0e10cSrcweir pbSource = mSeqSource.getConstArray(); 362*cdf0e10cSrcweir bCont = sal_True; 363*cdf0e10cSrcweir } 364*cdf0e10cSrcweir 365*cdf0e10cSrcweir if( bCont ) 366*cdf0e10cSrcweir continue; 367*cdf0e10cSrcweir break; 368*cdf0e10cSrcweir } 369*cdf0e10cSrcweir 370*cdf0e10cSrcweir mnCharsInBuffer += nTargetCount; 371*cdf0e10cSrcweir return nTargetCount; 372*cdf0e10cSrcweir } 373*cdf0e10cSrcweir catch( NotConnectedException& ) 374*cdf0e10cSrcweir { 375*cdf0e10cSrcweir throw IOException(); 376*cdf0e10cSrcweir //throw IOException( L"OTextInputStream::implReadString failed" ); 377*cdf0e10cSrcweir } 378*cdf0e10cSrcweir catch( BufferSizeExceededException& ) 379*cdf0e10cSrcweir { 380*cdf0e10cSrcweir throw IOException(); 381*cdf0e10cSrcweir } 382*cdf0e10cSrcweir } 383*cdf0e10cSrcweir 384*cdf0e10cSrcweir void OTextInputStream::setEncoding( const OUString& Encoding ) 385*cdf0e10cSrcweir throw(RuntimeException) 386*cdf0e10cSrcweir { 387*cdf0e10cSrcweir OString aOEncodingStr = OUStringToOString( Encoding, RTL_TEXTENCODING_ASCII_US ); 388*cdf0e10cSrcweir rtl_TextEncoding encoding = rtl_getTextEncodingFromMimeCharset( aOEncodingStr.getStr() ); 389*cdf0e10cSrcweir if( RTL_TEXTENCODING_DONTKNOW == encoding ) 390*cdf0e10cSrcweir return; 391*cdf0e10cSrcweir 392*cdf0e10cSrcweir mbEncodingInitialized = true; 393*cdf0e10cSrcweir mConvText2Unicode = rtl_createTextToUnicodeConverter( encoding ); 394*cdf0e10cSrcweir mContextText2Unicode = rtl_createTextToUnicodeContext( mConvText2Unicode ); 395*cdf0e10cSrcweir mEncoding = Encoding; 396*cdf0e10cSrcweir } 397*cdf0e10cSrcweir 398*cdf0e10cSrcweir //=========================================================================== 399*cdf0e10cSrcweir // XInputStream 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir sal_Int32 OTextInputStream::readBytes( Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) 402*cdf0e10cSrcweir throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) 403*cdf0e10cSrcweir { 404*cdf0e10cSrcweir return mxStream->readBytes( aData, nBytesToRead ); 405*cdf0e10cSrcweir } 406*cdf0e10cSrcweir 407*cdf0e10cSrcweir sal_Int32 OTextInputStream::readSomeBytes( Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) 408*cdf0e10cSrcweir throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) 409*cdf0e10cSrcweir { 410*cdf0e10cSrcweir return mxStream->readSomeBytes( aData, nMaxBytesToRead ); 411*cdf0e10cSrcweir } 412*cdf0e10cSrcweir 413*cdf0e10cSrcweir void OTextInputStream::skipBytes( sal_Int32 nBytesToSkip ) 414*cdf0e10cSrcweir throw(NotConnectedException, BufferSizeExceededException, IOException, RuntimeException) 415*cdf0e10cSrcweir { 416*cdf0e10cSrcweir mxStream->skipBytes( nBytesToSkip ); 417*cdf0e10cSrcweir } 418*cdf0e10cSrcweir 419*cdf0e10cSrcweir sal_Int32 OTextInputStream::available( ) 420*cdf0e10cSrcweir throw(NotConnectedException, IOException, RuntimeException) 421*cdf0e10cSrcweir { 422*cdf0e10cSrcweir return mxStream->available(); 423*cdf0e10cSrcweir } 424*cdf0e10cSrcweir 425*cdf0e10cSrcweir void OTextInputStream::closeInput( ) 426*cdf0e10cSrcweir throw(NotConnectedException, IOException, RuntimeException) 427*cdf0e10cSrcweir { 428*cdf0e10cSrcweir mxStream->closeInput(); 429*cdf0e10cSrcweir } 430*cdf0e10cSrcweir 431*cdf0e10cSrcweir 432*cdf0e10cSrcweir //=========================================================================== 433*cdf0e10cSrcweir // XActiveDataSink 434*cdf0e10cSrcweir 435*cdf0e10cSrcweir void OTextInputStream::setInputStream( const Reference< XInputStream >& aStream ) 436*cdf0e10cSrcweir throw(RuntimeException) 437*cdf0e10cSrcweir { 438*cdf0e10cSrcweir mxStream = aStream; 439*cdf0e10cSrcweir } 440*cdf0e10cSrcweir 441*cdf0e10cSrcweir Reference< XInputStream > OTextInputStream::getInputStream() 442*cdf0e10cSrcweir throw(RuntimeException) 443*cdf0e10cSrcweir { 444*cdf0e10cSrcweir return mxStream; 445*cdf0e10cSrcweir } 446*cdf0e10cSrcweir 447*cdf0e10cSrcweir 448*cdf0e10cSrcweir Reference< XInterface > SAL_CALL TextInputStream_CreateInstance( const Reference< XComponentContext > &) 449*cdf0e10cSrcweir { 450*cdf0e10cSrcweir return Reference < XInterface >( ( OWeakObject * ) new OTextInputStream() ); 451*cdf0e10cSrcweir } 452*cdf0e10cSrcweir 453*cdf0e10cSrcweir OUString TextInputStream_getImplementationName() 454*cdf0e10cSrcweir { 455*cdf0e10cSrcweir return OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) ); 456*cdf0e10cSrcweir } 457*cdf0e10cSrcweir 458*cdf0e10cSrcweir Sequence< OUString > TextInputStream_getSupportedServiceNames() 459*cdf0e10cSrcweir { 460*cdf0e10cSrcweir static Sequence < OUString > *pNames = 0; 461*cdf0e10cSrcweir if( ! pNames ) 462*cdf0e10cSrcweir { 463*cdf0e10cSrcweir MutexGuard guard( Mutex::getGlobalMutex() ); 464*cdf0e10cSrcweir if( !pNames ) 465*cdf0e10cSrcweir { 466*cdf0e10cSrcweir static Sequence< OUString > seqNames(1); 467*cdf0e10cSrcweir seqNames.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICE_NAME ) ); 468*cdf0e10cSrcweir pNames = &seqNames; 469*cdf0e10cSrcweir } 470*cdf0e10cSrcweir } 471*cdf0e10cSrcweir return *pNames; 472*cdf0e10cSrcweir } 473*cdf0e10cSrcweir 474*cdf0e10cSrcweir OUString OTextInputStream::getImplementationName() throw() 475*cdf0e10cSrcweir { 476*cdf0e10cSrcweir return TextInputStream_getImplementationName(); 477*cdf0e10cSrcweir } 478*cdf0e10cSrcweir 479*cdf0e10cSrcweir sal_Bool OTextInputStream::supportsService(const OUString& ServiceName) throw() 480*cdf0e10cSrcweir { 481*cdf0e10cSrcweir Sequence< OUString > aSNL = getSupportedServiceNames(); 482*cdf0e10cSrcweir const OUString * pArray = aSNL.getConstArray(); 483*cdf0e10cSrcweir 484*cdf0e10cSrcweir for( sal_Int32 i = 0; i < aSNL.getLength(); i++ ) 485*cdf0e10cSrcweir if( pArray[i] == ServiceName ) 486*cdf0e10cSrcweir return sal_True; 487*cdf0e10cSrcweir 488*cdf0e10cSrcweir return sal_False; 489*cdf0e10cSrcweir } 490*cdf0e10cSrcweir 491*cdf0e10cSrcweir Sequence< OUString > OTextInputStream::getSupportedServiceNames(void) throw() 492*cdf0e10cSrcweir { 493*cdf0e10cSrcweir return TextInputStream_getSupportedServiceNames(); 494*cdf0e10cSrcweir } 495*cdf0e10cSrcweir 496*cdf0e10cSrcweir } 497*cdf0e10cSrcweir 498*cdf0e10cSrcweir using namespace io_TextInputStream; 499*cdf0e10cSrcweir 500*cdf0e10cSrcweir static struct ImplementationEntry g_entries[] = 501*cdf0e10cSrcweir { 502*cdf0e10cSrcweir { 503*cdf0e10cSrcweir TextInputStream_CreateInstance, TextInputStream_getImplementationName , 504*cdf0e10cSrcweir TextInputStream_getSupportedServiceNames, createSingleComponentFactory , 505*cdf0e10cSrcweir &g_moduleCount.modCnt , 0 506*cdf0e10cSrcweir }, 507*cdf0e10cSrcweir { 0, 0, 0, 0, 0, 0 } 508*cdf0e10cSrcweir }; 509*cdf0e10cSrcweir 510*cdf0e10cSrcweir extern "C" 511*cdf0e10cSrcweir { 512*cdf0e10cSrcweir sal_Bool SAL_CALL component_canUnload( TimeValue *pTime ) 513*cdf0e10cSrcweir { 514*cdf0e10cSrcweir return g_moduleCount.canUnload( &g_moduleCount , pTime ); 515*cdf0e10cSrcweir } 516*cdf0e10cSrcweir 517*cdf0e10cSrcweir //================================================================================================== 518*cdf0e10cSrcweir void SAL_CALL component_getImplementationEnvironment( 519*cdf0e10cSrcweir const sal_Char ** ppEnvTypeName, uno_Environment ** ) 520*cdf0e10cSrcweir { 521*cdf0e10cSrcweir *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; 522*cdf0e10cSrcweir } 523*cdf0e10cSrcweir //================================================================================================== 524*cdf0e10cSrcweir void * SAL_CALL component_getFactory( 525*cdf0e10cSrcweir const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey ) 526*cdf0e10cSrcweir { 527*cdf0e10cSrcweir return component_getFactoryHelper( pImplName, pServiceManager, pRegistryKey , g_entries ); 528*cdf0e10cSrcweir } 529*cdf0e10cSrcweir } 530*cdf0e10cSrcweir 531*cdf0e10cSrcweir 532