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