189b56da7SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 389b56da7SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 489b56da7SAndrew Rist * or more contributor license agreements. See the NOTICE file 589b56da7SAndrew Rist * distributed with this work for additional information 689b56da7SAndrew Rist * regarding copyright ownership. The ASF licenses this file 789b56da7SAndrew Rist * to you under the Apache License, Version 2.0 (the 889b56da7SAndrew Rist * "License"); you may not use this file except in compliance 989b56da7SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 1189b56da7SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 1389b56da7SAndrew Rist * Unless required by applicable law or agreed to in writing, 1489b56da7SAndrew Rist * software distributed under the License is distributed on an 1589b56da7SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1689b56da7SAndrew Rist * KIND, either express or implied. See the License for the 1789b56da7SAndrew Rist * specific language governing permissions and limitations 1889b56da7SAndrew Rist * under the License. 19cdf0e10cSrcweir * 2089b56da7SAndrew Rist *************************************************************/ 2189b56da7SAndrew Rist 2289b56da7SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_tools.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir // ToDo: 28cdf0e10cSrcweir // - Read->RefreshBuffer->Auf Aenderungen von nBufActualLen reagieren 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include <cstddef> 31cdf0e10cSrcweir 32cdf0e10cSrcweir #include <string.h> 33cdf0e10cSrcweir #include <stdio.h> 34cdf0e10cSrcweir #include <ctype.h> // isspace 35cdf0e10cSrcweir #include <stdlib.h> // strtol, _crotl 36cdf0e10cSrcweir 37cdf0e10cSrcweir #include "boost/static_assert.hpp" 38cdf0e10cSrcweir 39cdf0e10cSrcweir /* 40cdf0e10cSrcweir #if defined( DBG_UTIL ) && (OSL_DEBUG_LEVEL > 1) 41cdf0e10cSrcweir // prueft Synchronisation des Buffers nach allen Read, Write, Seek 42cdf0e10cSrcweir #define OV_DEBUG 43cdf0e10cSrcweir #endif 44cdf0e10cSrcweir */ 45cdf0e10cSrcweir 46cdf0e10cSrcweir #include <tools/solar.h> 47cdf0e10cSrcweir 48cdf0e10cSrcweir #if defined(BLC) 49cdf0e10cSrcweir #define SWAPNIBBLES(c) c=_crotl(c,4); 50cdf0e10cSrcweir #else 51cdf0e10cSrcweir #define SWAPNIBBLES(c) \ 52cdf0e10cSrcweir unsigned char nSwapTmp=c; \ 53cdf0e10cSrcweir nSwapTmp <<= 4; \ 54cdf0e10cSrcweir c >>= 4; \ 55cdf0e10cSrcweir c |= nSwapTmp; 56cdf0e10cSrcweir #endif 57cdf0e10cSrcweir 58cdf0e10cSrcweir #include <tools/debug.hxx> 59cdf0e10cSrcweir #define ENABLE_BYTESTRING_STREAM_OPERATORS 60cdf0e10cSrcweir #include <tools/stream.hxx> 61cdf0e10cSrcweir #include <osl/thread.h> 62cdf0e10cSrcweir #include <algorithm> 63cdf0e10cSrcweir 64cdf0e10cSrcweir // ----------------------------------------------------------------------- 65cdf0e10cSrcweir 66cdf0e10cSrcweir DBG_NAME( Stream ) 67cdf0e10cSrcweir 68cdf0e10cSrcweir // ----------------------------------------------------------------------- 69cdf0e10cSrcweir 70cdf0e10cSrcweir // sprintf Param-Mode 71cdf0e10cSrcweir #define SPECIAL_PARAM_NONE 0 // Format-Str, Number 72cdf0e10cSrcweir #define SPECIAL_PARAM_WIDTH 1 // Format-Str, Width, Number 73cdf0e10cSrcweir #define SPECIAL_PARAM_PRECISION 2 // Format-Str, Precision, Number 74cdf0e10cSrcweir #define SPECIAL_PARAM_BOTH 3 // Format-Str, Width, Precision, Number 75cdf0e10cSrcweir 76cdf0e10cSrcweir // ----------------------------------------------------------------------- 77cdf0e10cSrcweir 78cdf0e10cSrcweir // !!! Nicht inline, wenn Operatoren <<,>> inline sind 79cdf0e10cSrcweir inline static void SwapUShort( sal_uInt16& r ) 80cdf0e10cSrcweir { r = SWAPSHORT(r); } 81cdf0e10cSrcweir inline static void SwapShort( short& r ) 82cdf0e10cSrcweir { r = SWAPSHORT(r); } 83cdf0e10cSrcweir inline static void SwapLong( long& r ) 84cdf0e10cSrcweir { r = SWAPLONG(r); } 85cdf0e10cSrcweir inline static void SwapULong( sal_uInt32& r ) 86cdf0e10cSrcweir { r = SWAPLONG(r); } 87cdf0e10cSrcweir inline static void SwapLongInt( int& r ) 88cdf0e10cSrcweir { r = SWAPLONG(r); } 89cdf0e10cSrcweir inline static void SwapLongUInt( unsigned int& r ) 90cdf0e10cSrcweir { r = SWAPLONG(r); } 91cdf0e10cSrcweir #ifdef UNX 92cdf0e10cSrcweir inline static void SwapFloat( float& r ) 93cdf0e10cSrcweir { 94cdf0e10cSrcweir *((sal_uInt32*)(void*)&r) = SWAPLONG( *((sal_uInt32*)(void*)&r) ); 95cdf0e10cSrcweir } 96cdf0e10cSrcweir inline static void SwapDouble( double& r ) 97cdf0e10cSrcweir { 98cdf0e10cSrcweir if( sizeof(double) != 8 ) 99cdf0e10cSrcweir { 100cdf0e10cSrcweir DBG_ASSERT( sal_False, "Can only swap 8-Byte-doubles\n" ); 101cdf0e10cSrcweir } 102cdf0e10cSrcweir else 103cdf0e10cSrcweir { 104cdf0e10cSrcweir sal_uInt32* c = (sal_uInt32*)(void*)&r; 105cdf0e10cSrcweir c[0] ^= c[1]; // zwei 32-Bit-Werte in situ vertauschen 106cdf0e10cSrcweir c[1] ^= c[0]; 107cdf0e10cSrcweir c[0] ^= c[1]; 108cdf0e10cSrcweir c[0] = SWAPLONG(c[0]); // und die beiden 32-Bit-Werte selbst in situ drehen 109cdf0e10cSrcweir c[1] = SWAPLONG(c[1]); 110cdf0e10cSrcweir } 111cdf0e10cSrcweir } 112cdf0e10cSrcweir #endif 113cdf0e10cSrcweir 114cdf0e10cSrcweir //SDO 115cdf0e10cSrcweir 116cdf0e10cSrcweir #define READNUMBER_WITHOUT_SWAP(datatype,value) \ 117cdf0e10cSrcweir {\ 118cdf0e10cSrcweir int tmp = eIOMode; \ 119cdf0e10cSrcweir if( (tmp == STREAM_IO_READ) && sizeof(datatype)<=nBufFree) \ 120cdf0e10cSrcweir {\ 121cdf0e10cSrcweir for (std::size_t i = 0; i < sizeof(datatype); i++)\ 122cdf0e10cSrcweir ((char *)&value)[i] = pBufPos[i];\ 123cdf0e10cSrcweir nBufActualPos += sizeof(datatype);\ 124cdf0e10cSrcweir pBufPos += sizeof(datatype);\ 125cdf0e10cSrcweir nBufFree -= sizeof(datatype);\ 126cdf0e10cSrcweir }\ 127cdf0e10cSrcweir else\ 128cdf0e10cSrcweir Read( (char*)&value, sizeof(datatype) );\ 129cdf0e10cSrcweir } 130cdf0e10cSrcweir 131cdf0e10cSrcweir #define WRITENUMBER_WITHOUT_SWAP(datatype,value) \ 132cdf0e10cSrcweir {\ 133cdf0e10cSrcweir int tmp = eIOMode; \ 134cdf0e10cSrcweir if( (tmp==STREAM_IO_WRITE) && sizeof(datatype) <= nBufFree)\ 135cdf0e10cSrcweir {\ 136cdf0e10cSrcweir for (std::size_t i = 0; i < sizeof(datatype); i++)\ 137cdf0e10cSrcweir pBufPos[i] = ((char *)&value)[i];\ 138cdf0e10cSrcweir nBufFree -= sizeof(datatype);\ 139cdf0e10cSrcweir nBufActualPos += sizeof(datatype);\ 140cdf0e10cSrcweir if( nBufActualPos > nBufActualLen )\ 141cdf0e10cSrcweir nBufActualLen = nBufActualPos;\ 142cdf0e10cSrcweir pBufPos += sizeof(datatype);\ 143cdf0e10cSrcweir bIsDirty = sal_True;\ 144cdf0e10cSrcweir }\ 145cdf0e10cSrcweir else\ 146cdf0e10cSrcweir Write( (char*)&value, sizeof(datatype) );\ 147cdf0e10cSrcweir } 148cdf0e10cSrcweir 149cdf0e10cSrcweir //============================================================================ 150cdf0e10cSrcweir // 151cdf0e10cSrcweir // class SvLockBytes 152cdf0e10cSrcweir // 153cdf0e10cSrcweir //============================================================================ 154cdf0e10cSrcweir 155cdf0e10cSrcweir void SvLockBytes::close() 156cdf0e10cSrcweir { 157cdf0e10cSrcweir if (m_bOwner) 158cdf0e10cSrcweir delete m_pStream; 159cdf0e10cSrcweir m_pStream = 0; 160cdf0e10cSrcweir } 161cdf0e10cSrcweir 162cdf0e10cSrcweir //============================================================================ 163cdf0e10cSrcweir TYPEINIT0(SvLockBytes); 164cdf0e10cSrcweir 165cdf0e10cSrcweir //============================================================================ 166cdf0e10cSrcweir // virtual 167cdf0e10cSrcweir ErrCode SvLockBytes::ReadAt(sal_Size nPos, void * pBuffer, sal_Size nCount, 168cdf0e10cSrcweir sal_Size * pRead) const 169cdf0e10cSrcweir { 170cdf0e10cSrcweir if (!m_pStream) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir DBG_ERROR("SvLockBytes::ReadAt(): Bad stream"); 173cdf0e10cSrcweir return ERRCODE_NONE; 174cdf0e10cSrcweir } 175cdf0e10cSrcweir 176cdf0e10cSrcweir m_pStream->Seek(nPos); 177cdf0e10cSrcweir sal_Size nTheRead = m_pStream->Read(pBuffer, nCount); 178cdf0e10cSrcweir if (pRead) 179cdf0e10cSrcweir *pRead = nTheRead; 180cdf0e10cSrcweir return m_pStream->GetErrorCode(); 181cdf0e10cSrcweir } 182cdf0e10cSrcweir 183cdf0e10cSrcweir //============================================================================ 184cdf0e10cSrcweir // virtual 185cdf0e10cSrcweir ErrCode SvLockBytes::WriteAt(sal_Size nPos, const void * pBuffer, sal_Size nCount, 186cdf0e10cSrcweir sal_Size * pWritten) 187cdf0e10cSrcweir { 188cdf0e10cSrcweir if (!m_pStream) 189cdf0e10cSrcweir { 190cdf0e10cSrcweir DBG_ERROR("SvLockBytes::WriteAt(): Bad stream"); 191cdf0e10cSrcweir return ERRCODE_NONE; 192cdf0e10cSrcweir } 193cdf0e10cSrcweir 194cdf0e10cSrcweir m_pStream->Seek(nPos); 195cdf0e10cSrcweir sal_Size nTheWritten = m_pStream->Write(pBuffer, nCount); 196cdf0e10cSrcweir if (pWritten) 197cdf0e10cSrcweir *pWritten = nTheWritten; 198cdf0e10cSrcweir return m_pStream->GetErrorCode(); 199cdf0e10cSrcweir } 200cdf0e10cSrcweir 201cdf0e10cSrcweir //============================================================================ 202cdf0e10cSrcweir // virtual 203cdf0e10cSrcweir ErrCode SvLockBytes::Flush() const 204cdf0e10cSrcweir { 205cdf0e10cSrcweir if (!m_pStream) 206cdf0e10cSrcweir { 207cdf0e10cSrcweir DBG_ERROR("SvLockBytes::Flush(): Bad stream"); 208cdf0e10cSrcweir return ERRCODE_NONE; 209cdf0e10cSrcweir } 210cdf0e10cSrcweir 211cdf0e10cSrcweir m_pStream->Flush(); 212cdf0e10cSrcweir return m_pStream->GetErrorCode(); 213cdf0e10cSrcweir } 214cdf0e10cSrcweir 215cdf0e10cSrcweir //============================================================================ 216cdf0e10cSrcweir // virtual 217cdf0e10cSrcweir ErrCode SvLockBytes::SetSize(sal_Size nSize) 218cdf0e10cSrcweir { 219cdf0e10cSrcweir if (!m_pStream) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir DBG_ERROR("SvLockBytes::SetSize(): Bad stream"); 222cdf0e10cSrcweir return ERRCODE_NONE; 223cdf0e10cSrcweir } 224cdf0e10cSrcweir 225cdf0e10cSrcweir m_pStream->SetStreamSize(nSize); 226cdf0e10cSrcweir return m_pStream->GetErrorCode(); 227cdf0e10cSrcweir } 228cdf0e10cSrcweir 229cdf0e10cSrcweir //============================================================================ 230cdf0e10cSrcweir ErrCode SvLockBytes::LockRegion(sal_Size, sal_Size, LockType) 231cdf0e10cSrcweir { 232cdf0e10cSrcweir DBG_ERROR("SvLockBytes::LockRegion(): Not implemented"); 233cdf0e10cSrcweir return ERRCODE_NONE; 234cdf0e10cSrcweir } 235cdf0e10cSrcweir 236cdf0e10cSrcweir //============================================================================ 237cdf0e10cSrcweir 238cdf0e10cSrcweir ErrCode SvLockBytes::UnlockRegion(sal_Size, sal_Size, LockType) 239cdf0e10cSrcweir { 240cdf0e10cSrcweir DBG_ERROR("SvLockBytes::UnlockRegion(): Not implemented"); 241cdf0e10cSrcweir return ERRCODE_NONE; 242cdf0e10cSrcweir } 243cdf0e10cSrcweir 244cdf0e10cSrcweir //============================================================================ 245cdf0e10cSrcweir ErrCode SvLockBytes::Stat(SvLockBytesStat * pStat, SvLockBytesStatFlag) const 246cdf0e10cSrcweir { 247cdf0e10cSrcweir if (!m_pStream) 248cdf0e10cSrcweir { 249cdf0e10cSrcweir DBG_ERROR("SvLockBytes::Stat(): Bad stream"); 250cdf0e10cSrcweir return ERRCODE_NONE; 251cdf0e10cSrcweir } 252cdf0e10cSrcweir 253cdf0e10cSrcweir if (pStat) 254cdf0e10cSrcweir { 255cdf0e10cSrcweir sal_Size nPos = m_pStream->Tell(); 256cdf0e10cSrcweir pStat->nSize = m_pStream->Seek(STREAM_SEEK_TO_END); 257cdf0e10cSrcweir m_pStream->Seek(nPos); 258cdf0e10cSrcweir } 259cdf0e10cSrcweir return ERRCODE_NONE; 260cdf0e10cSrcweir } 261cdf0e10cSrcweir 262cdf0e10cSrcweir //============================================================================ 263cdf0e10cSrcweir // 264cdf0e10cSrcweir // class SvOpenLockBytes 265cdf0e10cSrcweir // 266cdf0e10cSrcweir //============================================================================ 267cdf0e10cSrcweir 268cdf0e10cSrcweir TYPEINIT1(SvOpenLockBytes, SvLockBytes); 269cdf0e10cSrcweir 270cdf0e10cSrcweir //============================================================================ 271cdf0e10cSrcweir // 272cdf0e10cSrcweir // class SvAsyncLockBytes 273cdf0e10cSrcweir // 274cdf0e10cSrcweir //============================================================================ 275cdf0e10cSrcweir 276cdf0e10cSrcweir TYPEINIT1(SvAsyncLockBytes, SvOpenLockBytes); 277cdf0e10cSrcweir 278cdf0e10cSrcweir //============================================================================ 279cdf0e10cSrcweir // virtual 280cdf0e10cSrcweir ErrCode SvAsyncLockBytes::ReadAt(sal_Size nPos, void * pBuffer, sal_Size nCount, 281cdf0e10cSrcweir sal_Size * pRead) const 282cdf0e10cSrcweir { 283cdf0e10cSrcweir if (m_bTerminated) 284cdf0e10cSrcweir return SvOpenLockBytes::ReadAt(nPos, pBuffer, nCount, pRead); 285cdf0e10cSrcweir else 286cdf0e10cSrcweir { 287cdf0e10cSrcweir sal_Size nTheCount = std::min(nPos < m_nSize ? m_nSize - nPos : 0, nCount); 288cdf0e10cSrcweir ErrCode nError = SvOpenLockBytes::ReadAt(nPos, pBuffer, nTheCount, 289cdf0e10cSrcweir pRead); 290cdf0e10cSrcweir return !nCount || nTheCount == nCount || nError ? nError : 291cdf0e10cSrcweir ERRCODE_IO_PENDING; 292cdf0e10cSrcweir } 293cdf0e10cSrcweir } 294cdf0e10cSrcweir 295cdf0e10cSrcweir //============================================================================ 296cdf0e10cSrcweir // virtual 297cdf0e10cSrcweir ErrCode SvAsyncLockBytes::WriteAt(sal_Size nPos, const void * pBuffer, 298cdf0e10cSrcweir sal_Size nCount, sal_Size * pWritten) 299cdf0e10cSrcweir { 300cdf0e10cSrcweir if (m_bTerminated) 301cdf0e10cSrcweir return SvOpenLockBytes::WriteAt(nPos, pBuffer, nCount, pWritten); 302cdf0e10cSrcweir else 303cdf0e10cSrcweir { 304cdf0e10cSrcweir sal_Size nTheCount = std::min(nPos < m_nSize ? m_nSize - nPos : 0, nCount); 305cdf0e10cSrcweir ErrCode nError = SvOpenLockBytes::WriteAt(nPos, pBuffer, nTheCount, 306cdf0e10cSrcweir pWritten); 307cdf0e10cSrcweir return !nCount || nTheCount == nCount || nError ? nError : 308cdf0e10cSrcweir ERRCODE_IO_PENDING; 309cdf0e10cSrcweir } 310cdf0e10cSrcweir } 311cdf0e10cSrcweir 312cdf0e10cSrcweir //============================================================================ 313cdf0e10cSrcweir // virtual 314cdf0e10cSrcweir ErrCode SvAsyncLockBytes::FillAppend(const void * pBuffer, sal_Size nCount, 315cdf0e10cSrcweir sal_Size * pWritten) 316cdf0e10cSrcweir { 317cdf0e10cSrcweir sal_Size nTheWritten; 318cdf0e10cSrcweir ErrCode nError = SvOpenLockBytes::WriteAt(m_nSize, pBuffer, nCount, 319cdf0e10cSrcweir &nTheWritten); 320cdf0e10cSrcweir if (!nError) 321cdf0e10cSrcweir m_nSize += nTheWritten; 322cdf0e10cSrcweir if (pWritten) 323cdf0e10cSrcweir *pWritten = nTheWritten; 324cdf0e10cSrcweir return nError; 325cdf0e10cSrcweir } 326cdf0e10cSrcweir 327cdf0e10cSrcweir //============================================================================ 328cdf0e10cSrcweir // virtual 329cdf0e10cSrcweir sal_Size SvAsyncLockBytes::Seek(sal_Size nPos) 330cdf0e10cSrcweir { 331cdf0e10cSrcweir if (nPos != STREAM_SEEK_TO_END) 332cdf0e10cSrcweir m_nSize = nPos; 333cdf0e10cSrcweir return m_nSize; 334cdf0e10cSrcweir } 335cdf0e10cSrcweir 336cdf0e10cSrcweir //============================================================================ 337cdf0e10cSrcweir // 338cdf0e10cSrcweir // class SvStream 339cdf0e10cSrcweir // 340cdf0e10cSrcweir //============================================================================ 341cdf0e10cSrcweir 342cdf0e10cSrcweir sal_Size SvStream::GetData( void* pData, sal_Size nSize ) 343cdf0e10cSrcweir { 344cdf0e10cSrcweir if( !GetError() ) 345cdf0e10cSrcweir { 346cdf0e10cSrcweir DBG_ASSERT( xLockBytes.Is(), "pure virtual function" ); 347cdf0e10cSrcweir sal_Size nRet; 348cdf0e10cSrcweir nError = xLockBytes->ReadAt( nActPos, pData, nSize, &nRet ); 349cdf0e10cSrcweir nActPos += nRet; 350cdf0e10cSrcweir return nRet; 351cdf0e10cSrcweir } 352cdf0e10cSrcweir else return 0; 353cdf0e10cSrcweir } 354cdf0e10cSrcweir 355cdf0e10cSrcweir ErrCode SvStream::SetLockBytes( SvLockBytesRef& rLB ) 356cdf0e10cSrcweir { 357cdf0e10cSrcweir xLockBytes = rLB; 358cdf0e10cSrcweir RefreshBuffer(); 359cdf0e10cSrcweir return ERRCODE_NONE; 360cdf0e10cSrcweir } 361cdf0e10cSrcweir 362cdf0e10cSrcweir //======================================================================== 363cdf0e10cSrcweir 364cdf0e10cSrcweir sal_Size SvStream::PutData( const void* pData, sal_Size nSize ) 365cdf0e10cSrcweir { 366cdf0e10cSrcweir if( !GetError() ) 367cdf0e10cSrcweir { 368cdf0e10cSrcweir DBG_ASSERT( xLockBytes.Is(), "pure virtual function" ); 369cdf0e10cSrcweir sal_Size nRet; 370cdf0e10cSrcweir nError = xLockBytes->WriteAt( nActPos, pData, nSize, &nRet ); 371cdf0e10cSrcweir nActPos += nRet; 372cdf0e10cSrcweir return nRet; 373cdf0e10cSrcweir } 374cdf0e10cSrcweir else return 0; 375cdf0e10cSrcweir } 376cdf0e10cSrcweir 377cdf0e10cSrcweir //======================================================================== 378cdf0e10cSrcweir 379cdf0e10cSrcweir sal_Size SvStream::SeekPos( sal_Size nPos ) 380cdf0e10cSrcweir { 381cdf0e10cSrcweir if( !GetError() && nPos == STREAM_SEEK_TO_END ) 382cdf0e10cSrcweir { 383cdf0e10cSrcweir DBG_ASSERT( xLockBytes.Is(), "pure virtual function" ); 384cdf0e10cSrcweir SvLockBytesStat aStat; 385cdf0e10cSrcweir xLockBytes->Stat( &aStat, SVSTATFLAG_DEFAULT ); 386cdf0e10cSrcweir nActPos = aStat.nSize; 387cdf0e10cSrcweir } 388cdf0e10cSrcweir else 389cdf0e10cSrcweir nActPos = nPos; 390cdf0e10cSrcweir return nActPos; 391cdf0e10cSrcweir } 392cdf0e10cSrcweir 393cdf0e10cSrcweir //======================================================================== 394cdf0e10cSrcweir 395cdf0e10cSrcweir void SvStream::FlushData() 396cdf0e10cSrcweir { 397cdf0e10cSrcweir if( !GetError() ) 398cdf0e10cSrcweir { 399cdf0e10cSrcweir DBG_ASSERT( xLockBytes.Is(), "pure virtual function" ); 400cdf0e10cSrcweir nError = xLockBytes->Flush(); 401cdf0e10cSrcweir } 402cdf0e10cSrcweir } 403cdf0e10cSrcweir 404cdf0e10cSrcweir //======================================================================== 405cdf0e10cSrcweir 406cdf0e10cSrcweir void SvStream::SetSize( sal_Size nSize ) 407cdf0e10cSrcweir { 408cdf0e10cSrcweir DBG_ASSERT( xLockBytes.Is(), "pure virtual function" ); 409cdf0e10cSrcweir nError = xLockBytes->SetSize( nSize ); 410cdf0e10cSrcweir } 411cdf0e10cSrcweir 412cdf0e10cSrcweir void SvStream::ImpInit() 413cdf0e10cSrcweir { 414cdf0e10cSrcweir nActPos = 0; 415cdf0e10cSrcweir nCompressMode = COMPRESSMODE_NONE; 416cdf0e10cSrcweir eStreamCharSet = osl_getThreadTextEncoding(); 417cdf0e10cSrcweir // eTargetCharSet = osl_getThreadTextEncoding(); 418cdf0e10cSrcweir nCryptMask = 0; 419cdf0e10cSrcweir bIsEof = sal_False; 420cdf0e10cSrcweir #if defined UNX 421cdf0e10cSrcweir eLineDelimiter = LINEEND_LF; // UNIX-Format 422cdf0e10cSrcweir #else 423cdf0e10cSrcweir eLineDelimiter = LINEEND_CRLF; // DOS-Format 424cdf0e10cSrcweir #endif 425cdf0e10cSrcweir 426cdf0e10cSrcweir SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN ); 427cdf0e10cSrcweir 428cdf0e10cSrcweir nBufFilePos = 0; 429cdf0e10cSrcweir nBufActualPos = 0; 430cdf0e10cSrcweir bIsDirty = sal_False; 431cdf0e10cSrcweir bIsConsistent = sal_True; 432cdf0e10cSrcweir bIsWritable = sal_True; 433cdf0e10cSrcweir 434cdf0e10cSrcweir pRWBuf = 0; 435cdf0e10cSrcweir pBufPos = 0; 436cdf0e10cSrcweir nBufSize = 0; 437cdf0e10cSrcweir nBufActualLen = 0; 438cdf0e10cSrcweir eIOMode = STREAM_IO_DONTKNOW; 439cdf0e10cSrcweir nBufFree = 0; 440cdf0e10cSrcweir 441cdf0e10cSrcweir nRadix = 10; 442cdf0e10cSrcweir nPrecision = 0; // all significant digits 443cdf0e10cSrcweir nWidth = 0; // default width 444cdf0e10cSrcweir cFiller = ' '; 445cdf0e10cSrcweir nJustification = JUSTIFY_RIGHT; 446cdf0e10cSrcweir eStreamMode = 0; 447cdf0e10cSrcweir CreateFormatString(); 448cdf0e10cSrcweir 449cdf0e10cSrcweir nVersion = 0; 450cdf0e10cSrcweir 451cdf0e10cSrcweir ClearError(); 452cdf0e10cSrcweir } 453cdf0e10cSrcweir 454cdf0e10cSrcweir /************************************************************************* 455cdf0e10cSrcweir |* 456cdf0e10cSrcweir |* Stream::Stream() 457cdf0e10cSrcweir |* 458cdf0e10cSrcweir |* Beschreibung STREAM.SDW 459cdf0e10cSrcweir |* Ersterstellung OV 08.06.94 460cdf0e10cSrcweir |* Letzte Aenderung OV 08.06.94 461cdf0e10cSrcweir |* 462cdf0e10cSrcweir *************************************************************************/ 463cdf0e10cSrcweir 464cdf0e10cSrcweir SvStream::SvStream( SvLockBytes* pLockBytesP ) 465cdf0e10cSrcweir { 466cdf0e10cSrcweir DBG_CTOR( Stream, NULL ); 467cdf0e10cSrcweir 468cdf0e10cSrcweir ImpInit(); 469cdf0e10cSrcweir xLockBytes = pLockBytesP; 470cdf0e10cSrcweir const SvStream* pStrm; 471cdf0e10cSrcweir if( pLockBytesP ) { 472cdf0e10cSrcweir pStrm = pLockBytesP->GetStream(); 473cdf0e10cSrcweir if( pStrm ) { 474cdf0e10cSrcweir SetError( pStrm->GetErrorCode() ); 475cdf0e10cSrcweir } 476cdf0e10cSrcweir } 477cdf0e10cSrcweir SetBufferSize( 256 ); 478cdf0e10cSrcweir } 479cdf0e10cSrcweir 480cdf0e10cSrcweir SvStream::SvStream() 481cdf0e10cSrcweir { 482cdf0e10cSrcweir DBG_CTOR( Stream, NULL ); 483cdf0e10cSrcweir 484cdf0e10cSrcweir ImpInit(); 485cdf0e10cSrcweir } 486cdf0e10cSrcweir 487cdf0e10cSrcweir /************************************************************************* 488cdf0e10cSrcweir |* 489cdf0e10cSrcweir |* Stream::~Stream() 490cdf0e10cSrcweir |* 491cdf0e10cSrcweir |* Beschreibung STREAM.SDW 492cdf0e10cSrcweir |* Ersterstellung OV 08.06.94 493cdf0e10cSrcweir |* Letzte Aenderung OV 08.06.94 494cdf0e10cSrcweir |* 495cdf0e10cSrcweir *************************************************************************/ 496cdf0e10cSrcweir 497cdf0e10cSrcweir SvStream::~SvStream() 498cdf0e10cSrcweir { 499cdf0e10cSrcweir DBG_DTOR( Stream, NULL ); 500cdf0e10cSrcweir 501cdf0e10cSrcweir if ( xLockBytes.Is() ) 502cdf0e10cSrcweir Flush(); 503cdf0e10cSrcweir 504cdf0e10cSrcweir if( pRWBuf ) 505cdf0e10cSrcweir delete[] pRWBuf; 506cdf0e10cSrcweir } 507cdf0e10cSrcweir 508cdf0e10cSrcweir /************************************************************************* 509cdf0e10cSrcweir |* 510cdf0e10cSrcweir |* Stream::IsA() 511cdf0e10cSrcweir |* 512cdf0e10cSrcweir |* Beschreibung STREAM.SDW 513cdf0e10cSrcweir |* Ersterstellung OV 08.06.94 514cdf0e10cSrcweir |* Letzte Aenderung OV 08.06.94 515cdf0e10cSrcweir |* 516cdf0e10cSrcweir *************************************************************************/ 517cdf0e10cSrcweir 518cdf0e10cSrcweir sal_uInt16 SvStream::IsA() const 519cdf0e10cSrcweir { 520cdf0e10cSrcweir return (sal_uInt16)ID_STREAM; 521cdf0e10cSrcweir } 522cdf0e10cSrcweir 523cdf0e10cSrcweir /************************************************************************* 524cdf0e10cSrcweir |* 525cdf0e10cSrcweir |* Stream::ClearError() 526cdf0e10cSrcweir |* 527cdf0e10cSrcweir |* Beschreibung STREAM.SDW 528cdf0e10cSrcweir |* Ersterstellung OV 08.06.94 529cdf0e10cSrcweir |* Letzte Aenderung OV 08.06.94 530cdf0e10cSrcweir |* 531cdf0e10cSrcweir *************************************************************************/ 532cdf0e10cSrcweir 533cdf0e10cSrcweir void SvStream::ClearError() 534cdf0e10cSrcweir { 535cdf0e10cSrcweir bIsEof = sal_False; 536cdf0e10cSrcweir nError = SVSTREAM_OK; 537cdf0e10cSrcweir } 538cdf0e10cSrcweir 539cdf0e10cSrcweir /************************************************************************* 540cdf0e10cSrcweir |* 541cdf0e10cSrcweir |* Stream::SetError() 542cdf0e10cSrcweir |* 543cdf0e10cSrcweir |* Beschreibung STREAM.SDW 544cdf0e10cSrcweir |* Ersterstellung OV 08.06.94 545cdf0e10cSrcweir |* Letzte Aenderung OV 08.06.94 546cdf0e10cSrcweir |* 547cdf0e10cSrcweir *************************************************************************/ 548cdf0e10cSrcweir 549cdf0e10cSrcweir void SvStream::SetError( sal_uInt32 nErrorCode ) 550cdf0e10cSrcweir { 551cdf0e10cSrcweir if ( nError == SVSTREAM_OK ) 552cdf0e10cSrcweir nError = nErrorCode; 553cdf0e10cSrcweir } 554cdf0e10cSrcweir 555cdf0e10cSrcweir 556cdf0e10cSrcweir /************************************************************************* 557cdf0e10cSrcweir |* 558cdf0e10cSrcweir |* Stream::SetNumberFormatInt() 559cdf0e10cSrcweir |* 560cdf0e10cSrcweir |* Beschreibung STREAM.SDW 561cdf0e10cSrcweir |* Ersterstellung OV 08.06.94 562cdf0e10cSrcweir |* Letzte Aenderung OV 08.06.94 563cdf0e10cSrcweir |* 564cdf0e10cSrcweir *************************************************************************/ 565cdf0e10cSrcweir 566cdf0e10cSrcweir void SvStream::SetNumberFormatInt( sal_uInt16 nNewFormat ) 567cdf0e10cSrcweir { 568cdf0e10cSrcweir nNumberFormatInt = nNewFormat; 569cdf0e10cSrcweir bSwap = sal_False; 570cdf0e10cSrcweir #ifdef OSL_BIGENDIAN 571cdf0e10cSrcweir if( nNumberFormatInt == NUMBERFORMAT_INT_LITTLEENDIAN ) 572cdf0e10cSrcweir bSwap = sal_True; 573cdf0e10cSrcweir #else 574cdf0e10cSrcweir if( nNumberFormatInt == NUMBERFORMAT_INT_BIGENDIAN ) 575cdf0e10cSrcweir bSwap = sal_True; 576cdf0e10cSrcweir #endif 577cdf0e10cSrcweir } 578cdf0e10cSrcweir 579cdf0e10cSrcweir /************************************************************************* 580cdf0e10cSrcweir |* 581cdf0e10cSrcweir |* Stream::SetBufferSize() 582cdf0e10cSrcweir |* 583cdf0e10cSrcweir |* Beschreibung STREAM.SDW 584cdf0e10cSrcweir |* Ersterstellung OV 08.06.94 585cdf0e10cSrcweir |* Letzte Aenderung OV 08.06.94 586cdf0e10cSrcweir |* 587cdf0e10cSrcweir *************************************************************************/ 588cdf0e10cSrcweir 589cdf0e10cSrcweir void SvStream::SetBufferSize( sal_uInt16 nBufferSize ) 590cdf0e10cSrcweir { 591cdf0e10cSrcweir sal_Size nActualFilePos = Tell(); 592cdf0e10cSrcweir sal_Bool bDontSeek = (sal_Bool)(pRWBuf == 0); 593cdf0e10cSrcweir 594cdf0e10cSrcweir if( bIsDirty && bIsConsistent && bIsWritable ) // wg. Windows NT: Access denied 595cdf0e10cSrcweir Flush(); 596cdf0e10cSrcweir 597cdf0e10cSrcweir if( nBufSize ) 598cdf0e10cSrcweir { 599cdf0e10cSrcweir delete[] pRWBuf; 600cdf0e10cSrcweir nBufFilePos += nBufActualPos; 601cdf0e10cSrcweir } 602cdf0e10cSrcweir 603cdf0e10cSrcweir pRWBuf = 0; 604cdf0e10cSrcweir nBufActualLen = 0; 605cdf0e10cSrcweir nBufActualPos = 0; 606cdf0e10cSrcweir nBufSize = nBufferSize; 607cdf0e10cSrcweir if( nBufSize ) 608cdf0e10cSrcweir pRWBuf = new sal_uInt8[ nBufSize ]; 609cdf0e10cSrcweir bIsConsistent = sal_True; 610cdf0e10cSrcweir pBufPos = pRWBuf; 611cdf0e10cSrcweir eIOMode = STREAM_IO_DONTKNOW; 612cdf0e10cSrcweir if( !bDontSeek ) 613cdf0e10cSrcweir SeekPos( nActualFilePos ); 614cdf0e10cSrcweir } 615cdf0e10cSrcweir 616cdf0e10cSrcweir /************************************************************************* 617cdf0e10cSrcweir |* 618cdf0e10cSrcweir |* Stream::ClearBuffer() 619cdf0e10cSrcweir |* 620cdf0e10cSrcweir |* Beschreibung STREAM.SDW 621cdf0e10cSrcweir |* Ersterstellung OV 08.06.94 622cdf0e10cSrcweir |* Letzte Aenderung OV 08.06.94 623cdf0e10cSrcweir |* 624cdf0e10cSrcweir *************************************************************************/ 625cdf0e10cSrcweir 626cdf0e10cSrcweir void SvStream::ClearBuffer() 627cdf0e10cSrcweir { 628cdf0e10cSrcweir nBufActualLen = 0; 629cdf0e10cSrcweir nBufActualPos = 0; 630cdf0e10cSrcweir nBufFilePos = 0; 631cdf0e10cSrcweir pBufPos = pRWBuf; 632cdf0e10cSrcweir bIsDirty = sal_False; 633cdf0e10cSrcweir bIsConsistent = sal_True; 634cdf0e10cSrcweir eIOMode = STREAM_IO_DONTKNOW; 635cdf0e10cSrcweir 636cdf0e10cSrcweir bIsEof = sal_False; 637cdf0e10cSrcweir } 638cdf0e10cSrcweir 639cdf0e10cSrcweir /************************************************************************* 640cdf0e10cSrcweir |* 641cdf0e10cSrcweir |* Stream::ResetError() 642cdf0e10cSrcweir |* 643cdf0e10cSrcweir |* Beschreibung STREAM.SDW 644cdf0e10cSrcweir |* Ersterstellung OV 08.06.94 645cdf0e10cSrcweir |* Letzte Aenderung OV 08.06.94 646cdf0e10cSrcweir |* 647cdf0e10cSrcweir *************************************************************************/ 648cdf0e10cSrcweir 649cdf0e10cSrcweir void SvStream::ResetError() 650cdf0e10cSrcweir { 651cdf0e10cSrcweir ClearError(); 652cdf0e10cSrcweir } 653cdf0e10cSrcweir 654cdf0e10cSrcweir /************************************************************************* 655cdf0e10cSrcweir |* 656cdf0e10cSrcweir |* Stream::ReadLine() 657cdf0e10cSrcweir |* 658cdf0e10cSrcweir |* Beschreibung STREAM.SDW 659cdf0e10cSrcweir |* Ersterstellung OV 08.06.94 660cdf0e10cSrcweir |* Letzte Aenderung OV 08.06.94 661cdf0e10cSrcweir |* 662cdf0e10cSrcweir *************************************************************************/ 663cdf0e10cSrcweir 664cdf0e10cSrcweir sal_Bool SvStream::ReadByteStringLine( String& rStr, rtl_TextEncoding eSrcCharSet ) 665cdf0e10cSrcweir { 666cdf0e10cSrcweir sal_Bool bRet; 667cdf0e10cSrcweir ByteString aStr; 668cdf0e10cSrcweir 669cdf0e10cSrcweir bRet = ReadLine(aStr); 670cdf0e10cSrcweir rStr = UniString( aStr, eSrcCharSet ); 671cdf0e10cSrcweir return bRet; 672cdf0e10cSrcweir } 673cdf0e10cSrcweir 674cdf0e10cSrcweir sal_Bool SvStream::ReadLine( ByteString& rStr ) 675cdf0e10cSrcweir { 676cdf0e10cSrcweir sal_Char buf[256+1]; 677cdf0e10cSrcweir sal_Bool bEnd = sal_False; 678cdf0e10cSrcweir sal_Size nOldFilePos = Tell(); 679cdf0e10cSrcweir sal_Char c = 0; 680cdf0e10cSrcweir sal_Size nTotalLen = 0; 681cdf0e10cSrcweir 682cdf0e10cSrcweir rStr.Erase(); 683cdf0e10cSrcweir while( !bEnd && !GetError() ) // !!! nicht auf EOF testen, 684cdf0e10cSrcweir // !!! weil wir blockweise 685cdf0e10cSrcweir // !!! lesen 686cdf0e10cSrcweir { 687cdf0e10cSrcweir sal_uInt16 nLen = (sal_uInt16)Read( buf, sizeof(buf)-1 ); 688cdf0e10cSrcweir if ( !nLen ) 689cdf0e10cSrcweir { 690cdf0e10cSrcweir if ( rStr.Len() == 0 ) 691cdf0e10cSrcweir { 692cdf0e10cSrcweir // der allererste Blockread hat fehlgeschlagen -> Abflug 693cdf0e10cSrcweir bIsEof = sal_True; 694cdf0e10cSrcweir return sal_False; 695cdf0e10cSrcweir } 696cdf0e10cSrcweir else 697cdf0e10cSrcweir break; 698cdf0e10cSrcweir } 699cdf0e10cSrcweir 700cdf0e10cSrcweir sal_uInt16 j, n; 701cdf0e10cSrcweir for( j = n = 0; j < nLen ; ++j ) 702cdf0e10cSrcweir { 703cdf0e10cSrcweir c = buf[j]; 704cdf0e10cSrcweir if ( c == '\n' || c == '\r' ) 705cdf0e10cSrcweir { 706cdf0e10cSrcweir bEnd = sal_True; 707cdf0e10cSrcweir break; 708cdf0e10cSrcweir } 709cdf0e10cSrcweir // erAck 26.02.01: Old behavior was no special treatment of '\0' 710cdf0e10cSrcweir // character here, but a following rStr+=c did ignore it. Is this 711cdf0e10cSrcweir // really intended? Or should a '\0' better terminate a line? 712cdf0e10cSrcweir // The nOldFilePos stuff wasn't correct then anyways. 713cdf0e10cSrcweir if ( c ) 714cdf0e10cSrcweir { 715cdf0e10cSrcweir if ( n < j ) 716cdf0e10cSrcweir buf[n] = c; 717cdf0e10cSrcweir ++n; 718cdf0e10cSrcweir } 719cdf0e10cSrcweir } 720cdf0e10cSrcweir if ( n ) 721cdf0e10cSrcweir rStr.Append( buf, n ); 722cdf0e10cSrcweir nTotalLen += j; 723cdf0e10cSrcweir } 724cdf0e10cSrcweir 725cdf0e10cSrcweir if ( !bEnd && !GetError() && rStr.Len() ) 726cdf0e10cSrcweir bEnd = sal_True; 727cdf0e10cSrcweir 728cdf0e10cSrcweir nOldFilePos += nTotalLen; 729cdf0e10cSrcweir if( Tell() > nOldFilePos ) 730cdf0e10cSrcweir nOldFilePos++; 731cdf0e10cSrcweir Seek( nOldFilePos ); // seeken wg. obigem BlockRead! 732cdf0e10cSrcweir 733cdf0e10cSrcweir if ( bEnd && (c=='\r' || c=='\n') ) // Sonderbehandlung DOS-Dateien 734cdf0e10cSrcweir { 735cdf0e10cSrcweir char cTemp; 736cdf0e10cSrcweir sal_Size nLen = Read((char*)&cTemp , sizeof(cTemp) ); 737cdf0e10cSrcweir if ( nLen ) { 738cdf0e10cSrcweir if( cTemp == c || (cTemp != '\n' && cTemp != '\r') ) 739cdf0e10cSrcweir Seek( nOldFilePos ); 740cdf0e10cSrcweir } 741cdf0e10cSrcweir } 742cdf0e10cSrcweir 743cdf0e10cSrcweir if ( bEnd ) 744cdf0e10cSrcweir bIsEof = sal_False; 745cdf0e10cSrcweir return bEnd; 746cdf0e10cSrcweir } 747cdf0e10cSrcweir 748cdf0e10cSrcweir sal_Bool SvStream::ReadUniStringLine( String& rStr ) 749cdf0e10cSrcweir { 750cdf0e10cSrcweir sal_Unicode buf[256+1]; 751cdf0e10cSrcweir sal_Bool bEnd = sal_False; 752cdf0e10cSrcweir sal_Size nOldFilePos = Tell(); 753cdf0e10cSrcweir sal_Unicode c = 0; 754cdf0e10cSrcweir sal_Size nTotalLen = 0; 755cdf0e10cSrcweir 756cdf0e10cSrcweir DBG_ASSERT( sizeof(sal_Unicode) == sizeof(sal_uInt16), "ReadUniStringLine: swapping sizeof(sal_Unicode) not implemented" ); 757cdf0e10cSrcweir 758cdf0e10cSrcweir rStr.Erase(); 759cdf0e10cSrcweir while( !bEnd && !GetError() ) // !!! nicht auf EOF testen, 760cdf0e10cSrcweir // !!! weil wir blockweise 761cdf0e10cSrcweir // !!! lesen 762cdf0e10cSrcweir { 763cdf0e10cSrcweir sal_uInt16 nLen = (sal_uInt16)Read( (char*)buf, sizeof(buf)-sizeof(sal_Unicode) ); 764cdf0e10cSrcweir nLen /= sizeof(sal_Unicode); 765cdf0e10cSrcweir if ( !nLen ) 766cdf0e10cSrcweir { 767cdf0e10cSrcweir if ( rStr.Len() == 0 ) 768cdf0e10cSrcweir { 769cdf0e10cSrcweir // der allererste Blockread hat fehlgeschlagen -> Abflug 770cdf0e10cSrcweir bIsEof = sal_True; 771cdf0e10cSrcweir return sal_False; 772cdf0e10cSrcweir } 773cdf0e10cSrcweir else 774cdf0e10cSrcweir break; 775cdf0e10cSrcweir } 776cdf0e10cSrcweir 777cdf0e10cSrcweir sal_uInt16 j, n; 778cdf0e10cSrcweir for( j = n = 0; j < nLen ; ++j ) 779cdf0e10cSrcweir { 780cdf0e10cSrcweir if ( bSwap ) 781cdf0e10cSrcweir SwapUShort( buf[n] ); 782cdf0e10cSrcweir c = buf[j]; 783cdf0e10cSrcweir if ( c == '\n' || c == '\r' ) 784cdf0e10cSrcweir { 785cdf0e10cSrcweir bEnd = sal_True; 786cdf0e10cSrcweir break; 787cdf0e10cSrcweir } 788cdf0e10cSrcweir // erAck 26.02.01: Old behavior was no special treatment of '\0' 789cdf0e10cSrcweir // character here, but a following rStr+=c did ignore it. Is this 790cdf0e10cSrcweir // really intended? Or should a '\0' better terminate a line? 791cdf0e10cSrcweir // The nOldFilePos stuff wasn't correct then anyways. 792cdf0e10cSrcweir if ( c ) 793cdf0e10cSrcweir { 794cdf0e10cSrcweir if ( n < j ) 795cdf0e10cSrcweir buf[n] = c; 796cdf0e10cSrcweir ++n; 797cdf0e10cSrcweir } 798cdf0e10cSrcweir } 799cdf0e10cSrcweir if ( n ) 800cdf0e10cSrcweir rStr.Append( buf, n ); 801cdf0e10cSrcweir nTotalLen += j; 802cdf0e10cSrcweir } 803cdf0e10cSrcweir 804cdf0e10cSrcweir if ( !bEnd && !GetError() && rStr.Len() ) 805cdf0e10cSrcweir bEnd = sal_True; 806cdf0e10cSrcweir 807cdf0e10cSrcweir nOldFilePos += nTotalLen * sizeof(sal_Unicode); 808cdf0e10cSrcweir if( Tell() > nOldFilePos ) 809cdf0e10cSrcweir nOldFilePos += sizeof(sal_Unicode); 810cdf0e10cSrcweir Seek( nOldFilePos ); // seeken wg. obigem BlockRead! 811cdf0e10cSrcweir 812cdf0e10cSrcweir if ( bEnd && (c=='\r' || c=='\n') ) // Sonderbehandlung DOS-Dateien 813cdf0e10cSrcweir { 814cdf0e10cSrcweir sal_Unicode cTemp; 815cdf0e10cSrcweir Read( (char*)&cTemp, sizeof(cTemp) ); 816cdf0e10cSrcweir if ( bSwap ) 817cdf0e10cSrcweir SwapUShort( cTemp ); 818cdf0e10cSrcweir if( cTemp == c || (cTemp != '\n' && cTemp != '\r') ) 819cdf0e10cSrcweir Seek( nOldFilePos ); 820cdf0e10cSrcweir } 821cdf0e10cSrcweir 822cdf0e10cSrcweir if ( bEnd ) 823cdf0e10cSrcweir bIsEof = sal_False; 824cdf0e10cSrcweir return bEnd; 825cdf0e10cSrcweir } 826cdf0e10cSrcweir 827cdf0e10cSrcweir sal_Bool SvStream::ReadUniOrByteStringLine( String& rStr, rtl_TextEncoding eSrcCharSet ) 828cdf0e10cSrcweir { 829cdf0e10cSrcweir if ( eSrcCharSet == RTL_TEXTENCODING_UNICODE ) 830cdf0e10cSrcweir return ReadUniStringLine( rStr ); 831cdf0e10cSrcweir else 832cdf0e10cSrcweir return ReadByteStringLine( rStr, eSrcCharSet ); 833cdf0e10cSrcweir } 834cdf0e10cSrcweir 835cdf0e10cSrcweir /************************************************************************* 836cdf0e10cSrcweir |* 837cdf0e10cSrcweir |* Stream::ReadCString 838cdf0e10cSrcweir |* 839cdf0e10cSrcweir *************************************************************************/ 840cdf0e10cSrcweir 841cdf0e10cSrcweir sal_Bool SvStream::ReadCString( ByteString& rStr ) 842cdf0e10cSrcweir { 843cdf0e10cSrcweir if( rStr.Len() ) 844cdf0e10cSrcweir rStr.Erase(); 845cdf0e10cSrcweir 846cdf0e10cSrcweir sal_Char buf[ 256 + 1 ]; 847cdf0e10cSrcweir sal_Bool bEnd = sal_False; 848cdf0e10cSrcweir sal_Size nFilePos = Tell(); 849cdf0e10cSrcweir 850cdf0e10cSrcweir while( !bEnd && !GetError() ) 851cdf0e10cSrcweir { 852cdf0e10cSrcweir sal_uInt16 nLen = (sal_uInt16)Read( buf, sizeof(buf)-1 ); 853cdf0e10cSrcweir sal_uInt16 nReallyRead = nLen; 854cdf0e10cSrcweir if( !nLen ) 855cdf0e10cSrcweir break; 856cdf0e10cSrcweir 857cdf0e10cSrcweir const sal_Char* pPtr = buf; 858cdf0e10cSrcweir while( *pPtr && nLen ) 859cdf0e10cSrcweir ++pPtr, --nLen; 860cdf0e10cSrcweir 861cdf0e10cSrcweir bEnd = ( nReallyRead < sizeof(buf)-1 ) // read less than attempted to read 862cdf0e10cSrcweir || ( ( nLen > 0 ) // OR it is inside the block we read 863cdf0e10cSrcweir && ( 0 == *pPtr ) // AND found a string terminator 864cdf0e10cSrcweir ); 865cdf0e10cSrcweir 866cdf0e10cSrcweir rStr.Append( buf, ::sal::static_int_cast< xub_StrLen >( pPtr - buf ) ); 867cdf0e10cSrcweir } 868cdf0e10cSrcweir 869cdf0e10cSrcweir nFilePos += rStr.Len(); 870cdf0e10cSrcweir if( Tell() > nFilePos ) 871cdf0e10cSrcweir nFilePos++; 872cdf0e10cSrcweir Seek( nFilePos ); // seeken wg. obigem BlockRead! 873cdf0e10cSrcweir return bEnd; 874cdf0e10cSrcweir } 875cdf0e10cSrcweir 876cdf0e10cSrcweir sal_Bool SvStream::ReadCString( String& rStr, rtl_TextEncoding eToEncode ) 877cdf0e10cSrcweir { 878cdf0e10cSrcweir ByteString sStr; 879cdf0e10cSrcweir sal_Bool bRet = ReadCString( sStr ); 880cdf0e10cSrcweir rStr = String( sStr, eToEncode ); 881cdf0e10cSrcweir return bRet; 882cdf0e10cSrcweir } 883cdf0e10cSrcweir 884cdf0e10cSrcweir 885cdf0e10cSrcweir /************************************************************************* 886cdf0e10cSrcweir |* 887cdf0e10cSrcweir |* Stream::WriteUnicodeText() 888cdf0e10cSrcweir |* 889cdf0e10cSrcweir *************************************************************************/ 890cdf0e10cSrcweir 891cdf0e10cSrcweir sal_Bool SvStream::WriteUnicodeText( const String& rStr ) 892cdf0e10cSrcweir { 893cdf0e10cSrcweir DBG_ASSERT( sizeof(sal_Unicode) == sizeof(sal_uInt16), "WriteUnicodeText: swapping sizeof(sal_Unicode) not implemented" ); 894cdf0e10cSrcweir if ( bSwap ) 895cdf0e10cSrcweir { 896cdf0e10cSrcweir xub_StrLen nLen = rStr.Len(); 897cdf0e10cSrcweir sal_Unicode aBuf[384]; 898cdf0e10cSrcweir sal_Unicode* const pTmp = ( nLen > 384 ? new sal_Unicode[nLen] : aBuf); 899cdf0e10cSrcweir memcpy( pTmp, rStr.GetBuffer(), nLen * sizeof(sal_Unicode) ); 900cdf0e10cSrcweir sal_Unicode* p = pTmp; 901cdf0e10cSrcweir const sal_Unicode* const pStop = pTmp + nLen; 902cdf0e10cSrcweir while ( p < pStop ) 903cdf0e10cSrcweir { 904cdf0e10cSrcweir SwapUShort( *p ); 905cdf0e10cSrcweir p++; 906cdf0e10cSrcweir } 907cdf0e10cSrcweir Write( (char*)pTmp, nLen * sizeof(sal_Unicode) ); 908cdf0e10cSrcweir if ( pTmp != aBuf ) 909cdf0e10cSrcweir delete [] pTmp; 910cdf0e10cSrcweir } 911cdf0e10cSrcweir else 912cdf0e10cSrcweir Write( (char*)rStr.GetBuffer(), rStr.Len() * sizeof(sal_Unicode) ); 913cdf0e10cSrcweir return nError == SVSTREAM_OK; 914cdf0e10cSrcweir } 915cdf0e10cSrcweir 916cdf0e10cSrcweir sal_Bool SvStream::WriteUnicodeOrByteText( const String& rStr, rtl_TextEncoding eDestCharSet ) 917cdf0e10cSrcweir { 918cdf0e10cSrcweir if ( eDestCharSet == RTL_TEXTENCODING_UNICODE ) 919cdf0e10cSrcweir return WriteUnicodeText( rStr ); 920cdf0e10cSrcweir else 921cdf0e10cSrcweir { 922cdf0e10cSrcweir ByteString aStr( rStr, eDestCharSet ); 923cdf0e10cSrcweir Write( aStr.GetBuffer(), aStr.Len() ); 924cdf0e10cSrcweir return nError == SVSTREAM_OK; 925cdf0e10cSrcweir } 926cdf0e10cSrcweir } 927cdf0e10cSrcweir 928cdf0e10cSrcweir /************************************************************************* 929cdf0e10cSrcweir |* 930cdf0e10cSrcweir |* Stream::WriteLine() 931cdf0e10cSrcweir |* 932cdf0e10cSrcweir |* Beschreibung STREAM.SDW 933cdf0e10cSrcweir |* Ersterstellung OV 08.06.94 934cdf0e10cSrcweir |* Letzte Aenderung OV 08.06.94 935cdf0e10cSrcweir |* 936cdf0e10cSrcweir *************************************************************************/ 937cdf0e10cSrcweir 938cdf0e10cSrcweir sal_Bool SvStream::WriteByteStringLine( const String& rStr, rtl_TextEncoding eDestCharSet ) 939cdf0e10cSrcweir { 940cdf0e10cSrcweir return WriteLine( ByteString( rStr, eDestCharSet ) ); 941cdf0e10cSrcweir } 942cdf0e10cSrcweir 943cdf0e10cSrcweir sal_Bool SvStream::WriteLine( const ByteString& rStr ) 944cdf0e10cSrcweir { 945cdf0e10cSrcweir Write( rStr.GetBuffer(), rStr.Len() ); 946cdf0e10cSrcweir endl(*this); 947cdf0e10cSrcweir return nError == SVSTREAM_OK; 948cdf0e10cSrcweir } 949cdf0e10cSrcweir 950cdf0e10cSrcweir sal_Bool SvStream::WriteUniStringLine( const String& rStr ) 951cdf0e10cSrcweir { 952cdf0e10cSrcweir WriteUnicodeText( rStr ); 953cdf0e10cSrcweir endlu(*this); 954cdf0e10cSrcweir return nError == SVSTREAM_OK; 955cdf0e10cSrcweir } 956cdf0e10cSrcweir 957cdf0e10cSrcweir sal_Bool SvStream::WriteUniOrByteStringLine( const String& rStr, rtl_TextEncoding eDestCharSet ) 958cdf0e10cSrcweir { 959cdf0e10cSrcweir if ( eDestCharSet == RTL_TEXTENCODING_UNICODE ) 960cdf0e10cSrcweir return WriteUniStringLine( rStr ); 961cdf0e10cSrcweir else 962cdf0e10cSrcweir return WriteByteStringLine( rStr, eDestCharSet ); 963cdf0e10cSrcweir } 964cdf0e10cSrcweir 965cdf0e10cSrcweir /************************************************************************* 966cdf0e10cSrcweir |* 967cdf0e10cSrcweir |* Stream::WriteLines() 968cdf0e10cSrcweir |* 969cdf0e10cSrcweir |* Beschreibung STREAM.SDW 970cdf0e10cSrcweir |* Ersterstellung OV 17.07.95 971cdf0e10cSrcweir |* Letzte Aenderung OV 17.07.95 972cdf0e10cSrcweir |* 973cdf0e10cSrcweir *************************************************************************/ 974cdf0e10cSrcweir 975cdf0e10cSrcweir sal_Bool SvStream::WriteByteStringLines( const String& rStr, rtl_TextEncoding eDestCharSet ) 976cdf0e10cSrcweir { 977cdf0e10cSrcweir return WriteLines( ByteString( rStr, eDestCharSet ) ); 978cdf0e10cSrcweir } 979cdf0e10cSrcweir 980cdf0e10cSrcweir sal_Bool SvStream::WriteLines( const ByteString& rStr ) 981cdf0e10cSrcweir { 982cdf0e10cSrcweir ByteString aStr( rStr ); 983cdf0e10cSrcweir aStr.ConvertLineEnd( eLineDelimiter ); 984cdf0e10cSrcweir Write( aStr.GetBuffer(), aStr.Len() ); 985cdf0e10cSrcweir endl( *this ); 986cdf0e10cSrcweir return (sal_Bool)(nError == SVSTREAM_OK); 987cdf0e10cSrcweir } 988cdf0e10cSrcweir 989cdf0e10cSrcweir sal_Bool SvStream::WriteUniStringLines( const String& rStr ) 990cdf0e10cSrcweir { 991cdf0e10cSrcweir String aStr( rStr ); 992cdf0e10cSrcweir aStr.ConvertLineEnd( eLineDelimiter ); 993cdf0e10cSrcweir WriteUniStringLine( aStr ); 994cdf0e10cSrcweir return nError == SVSTREAM_OK; 995cdf0e10cSrcweir } 996cdf0e10cSrcweir 997cdf0e10cSrcweir sal_Bool SvStream::WriteUniOrByteStringLines( const String& rStr, rtl_TextEncoding eDestCharSet ) 998cdf0e10cSrcweir { 999cdf0e10cSrcweir if ( eDestCharSet == RTL_TEXTENCODING_UNICODE ) 1000cdf0e10cSrcweir return WriteUniStringLines( rStr ); 1001cdf0e10cSrcweir else 1002cdf0e10cSrcweir return WriteByteStringLines( rStr, eDestCharSet ); 1003cdf0e10cSrcweir } 1004cdf0e10cSrcweir 1005cdf0e10cSrcweir /************************************************************************* 1006cdf0e10cSrcweir |* 1007cdf0e10cSrcweir |* Stream::WriteUniOrByteChar() 1008cdf0e10cSrcweir |* 1009cdf0e10cSrcweir *************************************************************************/ 1010cdf0e10cSrcweir 1011cdf0e10cSrcweir sal_Bool SvStream::WriteUniOrByteChar( sal_Unicode ch, rtl_TextEncoding eDestCharSet ) 1012cdf0e10cSrcweir { 1013cdf0e10cSrcweir if ( eDestCharSet == RTL_TEXTENCODING_UNICODE ) 1014cdf0e10cSrcweir *this << ch; 1015cdf0e10cSrcweir else 1016cdf0e10cSrcweir { 1017cdf0e10cSrcweir ByteString aStr( ch, eDestCharSet ); 1018cdf0e10cSrcweir Write( aStr.GetBuffer(), aStr.Len() ); 1019cdf0e10cSrcweir } 1020cdf0e10cSrcweir return nError == SVSTREAM_OK; 1021cdf0e10cSrcweir } 1022cdf0e10cSrcweir 1023cdf0e10cSrcweir /************************************************************************* 1024cdf0e10cSrcweir |* 1025cdf0e10cSrcweir |* Stream::StartWritingUnicodeText() 1026cdf0e10cSrcweir |* 1027cdf0e10cSrcweir *************************************************************************/ 1028cdf0e10cSrcweir 1029cdf0e10cSrcweir sal_Bool SvStream::StartWritingUnicodeText() 1030cdf0e10cSrcweir { 1031cdf0e10cSrcweir SetEndianSwap( sal_False ); // write native format 1032cdf0e10cSrcweir // BOM, Byte Order Mark, U+FEFF, see 1033cdf0e10cSrcweir // http://www.unicode.org/faq/utf_bom.html#BOM 1034cdf0e10cSrcweir // Upon read: 0xfeff(-257) => no swap; 0xfffe(-2) => swap 1035cdf0e10cSrcweir *this << sal_uInt16( 0xfeff ); 1036cdf0e10cSrcweir return nError == SVSTREAM_OK; 1037cdf0e10cSrcweir } 1038cdf0e10cSrcweir 1039cdf0e10cSrcweir /************************************************************************* 1040cdf0e10cSrcweir |* 1041cdf0e10cSrcweir |* Stream::StartReadingUnicodeText() 1042cdf0e10cSrcweir |* 1043cdf0e10cSrcweir *************************************************************************/ 1044cdf0e10cSrcweir 1045cdf0e10cSrcweir sal_Bool SvStream::StartReadingUnicodeText( rtl_TextEncoding eReadBomCharSet ) 1046cdf0e10cSrcweir { 1047cdf0e10cSrcweir if (!( eReadBomCharSet == RTL_TEXTENCODING_DONTKNOW || 1048cdf0e10cSrcweir eReadBomCharSet == RTL_TEXTENCODING_UNICODE || 1049cdf0e10cSrcweir eReadBomCharSet == RTL_TEXTENCODING_UTF8)) 1050cdf0e10cSrcweir return sal_True; // nothing to read 1051cdf0e10cSrcweir 1052cdf0e10cSrcweir bool bTryUtf8 = false; 1053cdf0e10cSrcweir sal_uInt16 nFlag; 1054cdf0e10cSrcweir sal_sSize nBack = sizeof(nFlag); 1055cdf0e10cSrcweir *this >> nFlag; 1056cdf0e10cSrcweir switch ( nFlag ) 1057cdf0e10cSrcweir { 1058cdf0e10cSrcweir case 0xfeff : 1059cdf0e10cSrcweir // native UTF-16 1060cdf0e10cSrcweir if ( eReadBomCharSet == RTL_TEXTENCODING_DONTKNOW || 1061cdf0e10cSrcweir eReadBomCharSet == RTL_TEXTENCODING_UNICODE) 1062cdf0e10cSrcweir nBack = 0; 1063cdf0e10cSrcweir break; 1064cdf0e10cSrcweir case 0xfffe : 1065cdf0e10cSrcweir // swapped UTF-16 1066cdf0e10cSrcweir if ( eReadBomCharSet == RTL_TEXTENCODING_DONTKNOW || 1067cdf0e10cSrcweir eReadBomCharSet == RTL_TEXTENCODING_UNICODE) 1068cdf0e10cSrcweir { 1069cdf0e10cSrcweir SetEndianSwap( !bSwap ); 1070cdf0e10cSrcweir nBack = 0; 1071cdf0e10cSrcweir } 1072cdf0e10cSrcweir break; 1073cdf0e10cSrcweir case 0xefbb : 1074cdf0e10cSrcweir if (nNumberFormatInt == NUMBERFORMAT_INT_BIGENDIAN && 1075cdf0e10cSrcweir (eReadBomCharSet == RTL_TEXTENCODING_DONTKNOW || 1076cdf0e10cSrcweir eReadBomCharSet == RTL_TEXTENCODING_UTF8)) 1077cdf0e10cSrcweir bTryUtf8 = true; 1078cdf0e10cSrcweir break; 1079cdf0e10cSrcweir case 0xbbef : 1080cdf0e10cSrcweir if (nNumberFormatInt == NUMBERFORMAT_INT_LITTLEENDIAN && 1081cdf0e10cSrcweir (eReadBomCharSet == RTL_TEXTENCODING_DONTKNOW || 1082cdf0e10cSrcweir eReadBomCharSet == RTL_TEXTENCODING_UTF8)) 1083cdf0e10cSrcweir bTryUtf8 = true; 1084cdf0e10cSrcweir break; 1085cdf0e10cSrcweir default: 1086cdf0e10cSrcweir ; // nothing 1087cdf0e10cSrcweir } 1088cdf0e10cSrcweir if (bTryUtf8) 1089cdf0e10cSrcweir { 1090cdf0e10cSrcweir sal_uChar nChar; 1091cdf0e10cSrcweir nBack += sizeof(nChar); 1092cdf0e10cSrcweir *this >> nChar; 1093cdf0e10cSrcweir if (nChar == 0xbf) 1094cdf0e10cSrcweir nBack = 0; // it is UTF-8 1095cdf0e10cSrcweir } 1096cdf0e10cSrcweir if (nBack) 1097cdf0e10cSrcweir SeekRel( -nBack ); // no BOM, pure data 1098cdf0e10cSrcweir return nError == SVSTREAM_OK; 1099cdf0e10cSrcweir } 1100cdf0e10cSrcweir 1101cdf0e10cSrcweir /************************************************************************* 1102cdf0e10cSrcweir |* 1103cdf0e10cSrcweir |* Stream::ReadCsvLine() 1104cdf0e10cSrcweir |* 1105cdf0e10cSrcweir *************************************************************************/ 1106cdf0e10cSrcweir 1107cdf0e10cSrcweir // Precondition: pStr is guaranteed to be non-NULL and points to a 0-terminated 1108cdf0e10cSrcweir // array. 1109cdf0e10cSrcweir inline const sal_Unicode* lcl_UnicodeStrChr( const sal_Unicode* pStr, 1110cdf0e10cSrcweir sal_Unicode c ) 1111cdf0e10cSrcweir { 1112cdf0e10cSrcweir while (*pStr) 1113cdf0e10cSrcweir { 1114cdf0e10cSrcweir if (*pStr == c) 1115cdf0e10cSrcweir return pStr; 1116cdf0e10cSrcweir ++pStr; 1117cdf0e10cSrcweir } 1118cdf0e10cSrcweir return 0; 1119cdf0e10cSrcweir } 1120cdf0e10cSrcweir 1121cdf0e10cSrcweir sal_Bool SvStream::ReadCsvLine( String& rStr, sal_Bool bEmbeddedLineBreak, 1122cdf0e10cSrcweir const String& rFieldSeparators, sal_Unicode cFieldQuote, 1123cdf0e10cSrcweir sal_Bool bAllowBackslashEscape) 1124cdf0e10cSrcweir { 1125cdf0e10cSrcweir ReadUniOrByteStringLine( rStr); 1126cdf0e10cSrcweir 1127cdf0e10cSrcweir if (bEmbeddedLineBreak) 1128cdf0e10cSrcweir { 1129cdf0e10cSrcweir const sal_Unicode* pSeps = rFieldSeparators.GetBuffer(); 1130cdf0e10cSrcweir xub_StrLen nLastOffset = 0; 1131*2cbc43e9Sdamjan bool isQuoted = false; 1132*2cbc43e9Sdamjan bool isFieldStarting = true; 1133cdf0e10cSrcweir while (!IsEof() && rStr.Len() < STRING_MAXLEN) 1134cdf0e10cSrcweir { 1135*2cbc43e9Sdamjan bool wasQuote = false; 1136cdf0e10cSrcweir bool bBackslashEscaped = false; 1137*2cbc43e9Sdamjan const sal_Unicode *p; 1138*2cbc43e9Sdamjan p = rStr.GetBuffer(); 1139cdf0e10cSrcweir p += nLastOffset; 1140cdf0e10cSrcweir while (*p) 1141cdf0e10cSrcweir { 1142*2cbc43e9Sdamjan if (isQuoted) 1143cdf0e10cSrcweir { 1144cdf0e10cSrcweir if (*p == cFieldQuote && !bBackslashEscaped) 1145*2cbc43e9Sdamjan wasQuote = !wasQuote; 1146*2cbc43e9Sdamjan else 1147*2cbc43e9Sdamjan { 1148*2cbc43e9Sdamjan if (bAllowBackslashEscape) 1149cdf0e10cSrcweir { 1150cdf0e10cSrcweir if (*p == '\\') 1151cdf0e10cSrcweir bBackslashEscaped = !bBackslashEscaped; 1152cdf0e10cSrcweir else 1153cdf0e10cSrcweir bBackslashEscaped = false; 1154cdf0e10cSrcweir } 1155*2cbc43e9Sdamjan if (wasQuote) 1156*2cbc43e9Sdamjan { 1157*2cbc43e9Sdamjan wasQuote = false; 1158*2cbc43e9Sdamjan isQuoted = false; 1159*2cbc43e9Sdamjan if (lcl_UnicodeStrChr( pSeps, *p )) 1160*2cbc43e9Sdamjan isFieldStarting = true; 1161cdf0e10cSrcweir } 1162*2cbc43e9Sdamjan } 1163*2cbc43e9Sdamjan } 1164*2cbc43e9Sdamjan else 1165*2cbc43e9Sdamjan { 1166*2cbc43e9Sdamjan if (isFieldStarting) 1167*2cbc43e9Sdamjan { 1168*2cbc43e9Sdamjan isFieldStarting = false; 1169*2cbc43e9Sdamjan if (*p == cFieldQuote) 1170*2cbc43e9Sdamjan isQuoted = true; 1171*2cbc43e9Sdamjan else if (lcl_UnicodeStrChr( pSeps, *p )) 1172*2cbc43e9Sdamjan isFieldStarting = true; 1173*2cbc43e9Sdamjan } 1174*2cbc43e9Sdamjan else if (lcl_UnicodeStrChr( pSeps, *p )) 1175*2cbc43e9Sdamjan isFieldStarting = true; 1176*2cbc43e9Sdamjan } 1177cdf0e10cSrcweir ++p; 1178cdf0e10cSrcweir } 1179cdf0e10cSrcweir 1180*2cbc43e9Sdamjan if (wasQuote) 1181*2cbc43e9Sdamjan isQuoted = false; 1182*2cbc43e9Sdamjan 1183*2cbc43e9Sdamjan if (isQuoted) 1184cdf0e10cSrcweir { 1185cdf0e10cSrcweir nLastOffset = rStr.Len(); 1186cdf0e10cSrcweir String aNext; 1187cdf0e10cSrcweir ReadUniOrByteStringLine( aNext); 1188cdf0e10cSrcweir rStr += sal_Unicode(_LF); 1189cdf0e10cSrcweir rStr += aNext; 1190cdf0e10cSrcweir } 1191*2cbc43e9Sdamjan else 1192*2cbc43e9Sdamjan break; 1193cdf0e10cSrcweir } 1194cdf0e10cSrcweir } 1195cdf0e10cSrcweir return nError == SVSTREAM_OK; 1196cdf0e10cSrcweir } 1197cdf0e10cSrcweir 1198cdf0e10cSrcweir /************************************************************************* 1199cdf0e10cSrcweir |* 1200cdf0e10cSrcweir |* Stream::SeekRel() 1201cdf0e10cSrcweir |* 1202cdf0e10cSrcweir |* Beschreibung STREAM.SDW 1203cdf0e10cSrcweir |* Ersterstellung OV 08.06.94 1204cdf0e10cSrcweir |* Letzte Aenderung OV 08.06.94 1205cdf0e10cSrcweir |* 1206cdf0e10cSrcweir *************************************************************************/ 1207cdf0e10cSrcweir 1208cdf0e10cSrcweir sal_Size SvStream::SeekRel( sal_sSize nPos ) 1209cdf0e10cSrcweir { 1210cdf0e10cSrcweir sal_Size nActualPos = Tell(); 1211cdf0e10cSrcweir 1212cdf0e10cSrcweir if ( nPos >= 0 ) 1213cdf0e10cSrcweir { 1214cdf0e10cSrcweir if ( SAL_MAX_SIZE - nActualPos > (sal_Size)nPos ) 1215cdf0e10cSrcweir nActualPos += nPos; 1216cdf0e10cSrcweir } 1217cdf0e10cSrcweir else 1218cdf0e10cSrcweir { 1219cdf0e10cSrcweir sal_Size nAbsPos = (sal_Size)-nPos; 1220cdf0e10cSrcweir if ( nActualPos >= nAbsPos ) 1221cdf0e10cSrcweir nActualPos -= nAbsPos; 1222cdf0e10cSrcweir } 1223cdf0e10cSrcweir 1224cdf0e10cSrcweir pBufPos = pRWBuf + nActualPos; 1225cdf0e10cSrcweir return Seek( nActualPos ); 1226cdf0e10cSrcweir } 1227cdf0e10cSrcweir 1228cdf0e10cSrcweir /************************************************************************* 1229cdf0e10cSrcweir |* 1230cdf0e10cSrcweir |* Stream::operator>>() 1231cdf0e10cSrcweir |* 1232cdf0e10cSrcweir |* Beschreibung STREAM.SDW 1233cdf0e10cSrcweir |* Ersterstellung OV 08.06.94 1234cdf0e10cSrcweir |* Letzte Aenderung OV 08.06.94 1235cdf0e10cSrcweir |* 1236cdf0e10cSrcweir *************************************************************************/ 1237cdf0e10cSrcweir 1238cdf0e10cSrcweir SvStream& SvStream::operator >> ( sal_uInt16& r ) 1239cdf0e10cSrcweir { 1240cdf0e10cSrcweir READNUMBER_WITHOUT_SWAP(sal_uInt16,r) 1241cdf0e10cSrcweir if( bSwap ) 1242cdf0e10cSrcweir SwapUShort(r); 1243cdf0e10cSrcweir return *this; 1244cdf0e10cSrcweir } 1245cdf0e10cSrcweir 1246cdf0e10cSrcweir SvStream& SvStream::operator>> ( sal_uInt32& r ) 1247cdf0e10cSrcweir { 1248cdf0e10cSrcweir READNUMBER_WITHOUT_SWAP(sal_uInt32,r) 1249cdf0e10cSrcweir if( bSwap ) 1250cdf0e10cSrcweir SwapULong(r); 1251cdf0e10cSrcweir return *this; 1252cdf0e10cSrcweir } 1253cdf0e10cSrcweir 1254cdf0e10cSrcweir SvStream& SvStream::operator >> ( long& r ) 1255cdf0e10cSrcweir { 1256cdf0e10cSrcweir #if(SAL_TYPES_SIZEOFLONG != 4) 1257cdf0e10cSrcweir int tmp = r; 1258cdf0e10cSrcweir *this >> tmp; 1259cdf0e10cSrcweir r = tmp; 1260cdf0e10cSrcweir #else 1261cdf0e10cSrcweir READNUMBER_WITHOUT_SWAP(long,r) 1262cdf0e10cSrcweir if( bSwap ) 1263cdf0e10cSrcweir SwapLong(r); 1264cdf0e10cSrcweir #endif 1265cdf0e10cSrcweir return *this; 1266cdf0e10cSrcweir } 1267cdf0e10cSrcweir 1268cdf0e10cSrcweir SvStream& SvStream::operator >> ( short& r ) 1269cdf0e10cSrcweir { 1270cdf0e10cSrcweir READNUMBER_WITHOUT_SWAP(short,r) 1271cdf0e10cSrcweir if( bSwap ) 1272cdf0e10cSrcweir SwapShort(r); 1273cdf0e10cSrcweir return *this; 1274cdf0e10cSrcweir } 1275cdf0e10cSrcweir 1276cdf0e10cSrcweir SvStream& SvStream::operator >> ( int& r ) 1277cdf0e10cSrcweir { 1278cdf0e10cSrcweir READNUMBER_WITHOUT_SWAP(int,r) 1279cdf0e10cSrcweir if( bSwap ) 1280cdf0e10cSrcweir SwapLongInt(r); 1281cdf0e10cSrcweir return *this; 1282cdf0e10cSrcweir } 1283cdf0e10cSrcweir 1284cdf0e10cSrcweir SvStream& SvStream::operator>>( signed char& r ) 1285cdf0e10cSrcweir { 1286cdf0e10cSrcweir if( (eIOMode == STREAM_IO_READ || !bIsConsistent) && 1287cdf0e10cSrcweir sizeof(signed char) <= nBufFree ) 1288cdf0e10cSrcweir { 1289cdf0e10cSrcweir r = *pBufPos; 1290cdf0e10cSrcweir nBufActualPos += sizeof(signed char); 1291cdf0e10cSrcweir pBufPos += sizeof(signed char); 1292cdf0e10cSrcweir nBufFree -= sizeof(signed char); 1293cdf0e10cSrcweir } 1294cdf0e10cSrcweir else 1295cdf0e10cSrcweir Read( (char*)&r, sizeof(signed char) ); 1296cdf0e10cSrcweir return *this; 1297cdf0e10cSrcweir } 1298cdf0e10cSrcweir 1299cdf0e10cSrcweir // Sonderbehandlung fuer Chars wegen PutBack 1300cdf0e10cSrcweir 1301cdf0e10cSrcweir SvStream& SvStream::operator>>( char& r ) 1302cdf0e10cSrcweir { 1303cdf0e10cSrcweir if( (eIOMode == STREAM_IO_READ || !bIsConsistent) && 1304cdf0e10cSrcweir sizeof(char) <= nBufFree ) 1305cdf0e10cSrcweir { 1306cdf0e10cSrcweir r = *pBufPos; 1307cdf0e10cSrcweir nBufActualPos += sizeof(char); 1308cdf0e10cSrcweir pBufPos += sizeof(char); 1309cdf0e10cSrcweir nBufFree -= sizeof(char); 1310cdf0e10cSrcweir } 1311cdf0e10cSrcweir else 1312cdf0e10cSrcweir Read( (char*)&r, sizeof(char) ); 1313cdf0e10cSrcweir return *this; 1314cdf0e10cSrcweir } 1315cdf0e10cSrcweir 1316cdf0e10cSrcweir SvStream& SvStream::operator>>( unsigned char& r ) 1317cdf0e10cSrcweir { 1318cdf0e10cSrcweir if( (eIOMode == STREAM_IO_READ || !bIsConsistent) && 1319cdf0e10cSrcweir sizeof(char) <= nBufFree ) 1320cdf0e10cSrcweir { 1321cdf0e10cSrcweir r = *pBufPos; 1322cdf0e10cSrcweir nBufActualPos += sizeof(char); 1323cdf0e10cSrcweir pBufPos += sizeof(char); 1324cdf0e10cSrcweir nBufFree -= sizeof(char); 1325cdf0e10cSrcweir } 1326cdf0e10cSrcweir else 1327cdf0e10cSrcweir Read( (char*)&r, sizeof(char) ); 1328cdf0e10cSrcweir return *this; 1329cdf0e10cSrcweir } 1330cdf0e10cSrcweir 1331cdf0e10cSrcweir SvStream& SvStream::operator>>( float& r ) 1332cdf0e10cSrcweir { 1333cdf0e10cSrcweir // Read( (char*)&r, sizeof(float) ); 1334cdf0e10cSrcweir READNUMBER_WITHOUT_SWAP(float,r) 1335cdf0e10cSrcweir #if defined UNX 1336cdf0e10cSrcweir if( bSwap ) 1337cdf0e10cSrcweir SwapFloat(r); 1338cdf0e10cSrcweir #endif 1339cdf0e10cSrcweir return *this; 1340cdf0e10cSrcweir } 1341cdf0e10cSrcweir 1342cdf0e10cSrcweir SvStream& SvStream::operator>>( double& r ) 1343cdf0e10cSrcweir { 1344cdf0e10cSrcweir // Read( (char*)&r, sizeof(double) ); 1345cdf0e10cSrcweir READNUMBER_WITHOUT_SWAP(double,r) 1346cdf0e10cSrcweir #if defined UNX 1347cdf0e10cSrcweir if( bSwap ) 1348cdf0e10cSrcweir SwapDouble(r); 1349cdf0e10cSrcweir #endif 1350cdf0e10cSrcweir return *this; 1351cdf0e10cSrcweir } 1352cdf0e10cSrcweir 1353cdf0e10cSrcweir SvStream& SvStream::operator>> ( SvStream& rStream ) 1354cdf0e10cSrcweir { 1355cdf0e10cSrcweir const sal_uInt32 cBufLen = 0x8000; 1356cdf0e10cSrcweir char* pBuf = new char[ cBufLen ]; 1357cdf0e10cSrcweir 1358cdf0e10cSrcweir sal_uInt32 nCount; 1359cdf0e10cSrcweir do { 1360cdf0e10cSrcweir nCount = Read( pBuf, cBufLen ); 1361cdf0e10cSrcweir rStream.Write( pBuf, nCount ); 1362cdf0e10cSrcweir } while( nCount == cBufLen ); 1363cdf0e10cSrcweir 1364cdf0e10cSrcweir delete[] pBuf; 1365cdf0e10cSrcweir return *this; 1366cdf0e10cSrcweir } 1367cdf0e10cSrcweir 1368cdf0e10cSrcweir /************************************************************************* 1369cdf0e10cSrcweir |* 1370cdf0e10cSrcweir |* Stream::operator<<() 1371cdf0e10cSrcweir |* 1372cdf0e10cSrcweir |* Beschreibung STREAM.SDW 1373cdf0e10cSrcweir |* Ersterstellung OV 08.06.94 1374cdf0e10cSrcweir |* Letzte Aenderung OV 08.06.94 1375cdf0e10cSrcweir |* 1376cdf0e10cSrcweir *************************************************************************/ 1377cdf0e10cSrcweir 1378cdf0e10cSrcweir SvStream& SvStream::operator<< ( sal_uInt16 v ) 1379cdf0e10cSrcweir { 1380cdf0e10cSrcweir if( bSwap ) 1381cdf0e10cSrcweir SwapUShort(v); 1382cdf0e10cSrcweir WRITENUMBER_WITHOUT_SWAP(sal_uInt16,v) 1383cdf0e10cSrcweir return *this; 1384cdf0e10cSrcweir } 1385cdf0e10cSrcweir 1386cdf0e10cSrcweir SvStream& SvStream::operator<< ( sal_uInt32 v ) 1387cdf0e10cSrcweir { 1388cdf0e10cSrcweir if( bSwap ) 1389cdf0e10cSrcweir SwapULong(v); 1390cdf0e10cSrcweir WRITENUMBER_WITHOUT_SWAP(sal_uInt32,v) 1391cdf0e10cSrcweir return *this; 1392cdf0e10cSrcweir } 1393cdf0e10cSrcweir 1394cdf0e10cSrcweir SvStream& SvStream::operator<< ( long v ) 1395cdf0e10cSrcweir { 1396cdf0e10cSrcweir #if(SAL_TYPES_SIZEOFLONG != 4) 1397cdf0e10cSrcweir int tmp = v; 1398cdf0e10cSrcweir *this << tmp; 1399cdf0e10cSrcweir #else 1400cdf0e10cSrcweir if( bSwap ) 1401cdf0e10cSrcweir SwapLong(v); 1402cdf0e10cSrcweir WRITENUMBER_WITHOUT_SWAP(long,v) 1403cdf0e10cSrcweir #endif 1404cdf0e10cSrcweir return *this; 1405cdf0e10cSrcweir } 1406cdf0e10cSrcweir 1407cdf0e10cSrcweir SvStream& SvStream::operator<< ( short v ) 1408cdf0e10cSrcweir { 1409cdf0e10cSrcweir if( bSwap ) 1410cdf0e10cSrcweir SwapShort(v); 1411cdf0e10cSrcweir WRITENUMBER_WITHOUT_SWAP(short,v) 1412cdf0e10cSrcweir return *this; 1413cdf0e10cSrcweir } 1414cdf0e10cSrcweir 1415cdf0e10cSrcweir SvStream& SvStream::operator<<( int v ) 1416cdf0e10cSrcweir { 1417cdf0e10cSrcweir if( bSwap ) 1418cdf0e10cSrcweir SwapLongInt( v ); 1419cdf0e10cSrcweir WRITENUMBER_WITHOUT_SWAP(int,v) 1420cdf0e10cSrcweir return *this; 1421cdf0e10cSrcweir } 1422cdf0e10cSrcweir 1423cdf0e10cSrcweir SvStream& SvStream::operator<< ( signed char v ) 1424cdf0e10cSrcweir { 1425cdf0e10cSrcweir //SDO 1426cdf0e10cSrcweir int tmp = eIOMode; 1427cdf0e10cSrcweir if(tmp == STREAM_IO_WRITE && sizeof(signed char) <= nBufFree ) 1428cdf0e10cSrcweir { 1429cdf0e10cSrcweir *pBufPos = v; 1430cdf0e10cSrcweir pBufPos++; // sizeof(char); 1431cdf0e10cSrcweir nBufActualPos++; 1432cdf0e10cSrcweir if( nBufActualPos > nBufActualLen ) // Append ? 1433cdf0e10cSrcweir nBufActualLen = nBufActualPos; 1434cdf0e10cSrcweir nBufFree--; // = sizeof(char); 1435cdf0e10cSrcweir bIsDirty = sal_True; 1436cdf0e10cSrcweir } 1437cdf0e10cSrcweir else 1438cdf0e10cSrcweir Write( (char*)&v, sizeof(signed char) ); 1439cdf0e10cSrcweir return *this; 1440cdf0e10cSrcweir } 1441cdf0e10cSrcweir 1442cdf0e10cSrcweir // Sonderbehandlung fuer chars wegen PutBack 1443cdf0e10cSrcweir 1444cdf0e10cSrcweir SvStream& SvStream::operator<< ( char v ) 1445cdf0e10cSrcweir { 1446cdf0e10cSrcweir //SDO 1447cdf0e10cSrcweir int tmp = eIOMode; 1448cdf0e10cSrcweir if(tmp == STREAM_IO_WRITE && sizeof(char) <= nBufFree ) 1449cdf0e10cSrcweir { 1450cdf0e10cSrcweir *pBufPos = v; 1451cdf0e10cSrcweir pBufPos++; // sizeof(char); 1452cdf0e10cSrcweir nBufActualPos++; 1453cdf0e10cSrcweir if( nBufActualPos > nBufActualLen ) // Append ? 1454cdf0e10cSrcweir nBufActualLen = nBufActualPos; 1455cdf0e10cSrcweir nBufFree--; // = sizeof(char); 1456cdf0e10cSrcweir bIsDirty = sal_True; 1457cdf0e10cSrcweir } 1458cdf0e10cSrcweir else 1459cdf0e10cSrcweir Write( (char*)&v, sizeof(char) ); 1460cdf0e10cSrcweir return *this; 1461cdf0e10cSrcweir } 1462cdf0e10cSrcweir 1463cdf0e10cSrcweir SvStream& SvStream::operator<< ( unsigned char v ) 1464cdf0e10cSrcweir { 1465cdf0e10cSrcweir //SDO 1466cdf0e10cSrcweir int tmp = eIOMode; 1467cdf0e10cSrcweir if(tmp == STREAM_IO_WRITE && sizeof(char) <= nBufFree ) 1468cdf0e10cSrcweir { 1469cdf0e10cSrcweir *(unsigned char*)pBufPos = v; 1470cdf0e10cSrcweir pBufPos++; // = sizeof(char); 1471cdf0e10cSrcweir nBufActualPos++; // = sizeof(char); 1472cdf0e10cSrcweir if( nBufActualPos > nBufActualLen ) // Append ? 1473cdf0e10cSrcweir nBufActualLen = nBufActualPos; 1474cdf0e10cSrcweir nBufFree--; 1475cdf0e10cSrcweir bIsDirty = sal_True; 1476cdf0e10cSrcweir } 1477cdf0e10cSrcweir else 1478cdf0e10cSrcweir Write( (char*)&v, sizeof(char) ); 1479cdf0e10cSrcweir return *this; 1480cdf0e10cSrcweir } 1481cdf0e10cSrcweir 1482cdf0e10cSrcweir SvStream& SvStream::operator<< ( float v ) 1483cdf0e10cSrcweir { 1484cdf0e10cSrcweir #ifdef UNX 1485cdf0e10cSrcweir if( bSwap ) 1486cdf0e10cSrcweir SwapFloat(v); 1487cdf0e10cSrcweir #endif 1488cdf0e10cSrcweir WRITENUMBER_WITHOUT_SWAP(float,v) 1489cdf0e10cSrcweir return *this; 1490cdf0e10cSrcweir } 1491cdf0e10cSrcweir 1492cdf0e10cSrcweir SvStream& SvStream::operator<< ( const double& r ) 1493cdf0e10cSrcweir { 1494cdf0e10cSrcweir // Write( (char*)&r, sizeof( double ) ); 1495cdf0e10cSrcweir #if defined UNX 1496cdf0e10cSrcweir if( bSwap ) 1497cdf0e10cSrcweir { 1498cdf0e10cSrcweir double nHelp = r; 1499cdf0e10cSrcweir SwapDouble(nHelp); 1500cdf0e10cSrcweir WRITENUMBER_WITHOUT_SWAP(double,nHelp) 1501cdf0e10cSrcweir return *this; 1502cdf0e10cSrcweir } 1503cdf0e10cSrcweir else 1504cdf0e10cSrcweir #endif 1505cdf0e10cSrcweir WRITENUMBER_WITHOUT_SWAP(double,r) 1506cdf0e10cSrcweir 1507cdf0e10cSrcweir return *this; 1508cdf0e10cSrcweir } 1509cdf0e10cSrcweir 1510cdf0e10cSrcweir SvStream& SvStream::operator<< ( const char* pBuf ) 1511cdf0e10cSrcweir { 1512cdf0e10cSrcweir Write( pBuf, strlen( pBuf ) ); 1513cdf0e10cSrcweir return *this; 1514cdf0e10cSrcweir } 1515cdf0e10cSrcweir 1516cdf0e10cSrcweir SvStream& SvStream::operator<< ( const unsigned char* pBuf ) 1517cdf0e10cSrcweir { 1518cdf0e10cSrcweir Write( (char*)pBuf, strlen( (char*)pBuf ) ); 1519cdf0e10cSrcweir return *this; 1520cdf0e10cSrcweir } 1521cdf0e10cSrcweir 1522cdf0e10cSrcweir SvStream& SvStream::operator<< ( SvStream& rStream ) 1523cdf0e10cSrcweir { 1524cdf0e10cSrcweir const sal_uInt32 cBufLen = 0x8000; 1525cdf0e10cSrcweir char* pBuf = new char[ cBufLen ]; 1526cdf0e10cSrcweir sal_uInt32 nCount; 1527cdf0e10cSrcweir do { 1528cdf0e10cSrcweir nCount = rStream.Read( pBuf, cBufLen ); 1529cdf0e10cSrcweir Write( pBuf, nCount ); 1530cdf0e10cSrcweir } while( nCount == cBufLen ); 1531cdf0e10cSrcweir 1532cdf0e10cSrcweir delete[] pBuf; 1533cdf0e10cSrcweir return *this; 1534cdf0e10cSrcweir } 1535cdf0e10cSrcweir 1536cdf0e10cSrcweir // ----------------------------------------------------------------------- 1537cdf0e10cSrcweir 1538cdf0e10cSrcweir SvStream& SvStream::ReadByteString( UniString& rStr, rtl_TextEncoding eSrcCharSet ) 1539cdf0e10cSrcweir { 1540cdf0e10cSrcweir // read UTF-16 string directly from stream ? 1541cdf0e10cSrcweir if (eSrcCharSet == RTL_TEXTENCODING_UNICODE) 1542cdf0e10cSrcweir { 1543cdf0e10cSrcweir sal_uInt32 nLen; 1544cdf0e10cSrcweir operator>> (nLen); 1545cdf0e10cSrcweir if (nLen) 1546cdf0e10cSrcweir { 1547cdf0e10cSrcweir if (nLen > STRING_MAXLEN) { 1548cdf0e10cSrcweir SetError(SVSTREAM_GENERALERROR); 1549cdf0e10cSrcweir return *this; 1550cdf0e10cSrcweir } 1551cdf0e10cSrcweir sal_Unicode *pStr = rStr.AllocBuffer( 1552cdf0e10cSrcweir static_cast< xub_StrLen >(nLen)); 1553cdf0e10cSrcweir BOOST_STATIC_ASSERT(STRING_MAXLEN <= SAL_MAX_SIZE / 2); 1554cdf0e10cSrcweir Read( pStr, nLen << 1 ); 1555cdf0e10cSrcweir 1556cdf0e10cSrcweir if (bSwap) 1557cdf0e10cSrcweir for (sal_Unicode *pEnd = pStr + nLen; pStr < pEnd; pStr++) 1558cdf0e10cSrcweir SwapUShort(*pStr); 1559cdf0e10cSrcweir } 1560cdf0e10cSrcweir else 1561cdf0e10cSrcweir rStr.Erase(); 1562cdf0e10cSrcweir 1563cdf0e10cSrcweir return *this; 1564cdf0e10cSrcweir } 1565cdf0e10cSrcweir 1566cdf0e10cSrcweir ByteString aStr; 1567cdf0e10cSrcweir ReadByteString( aStr ); 1568cdf0e10cSrcweir rStr = UniString( aStr, eSrcCharSet ); 1569cdf0e10cSrcweir return *this; 1570cdf0e10cSrcweir } 1571cdf0e10cSrcweir 1572cdf0e10cSrcweir // ----------------------------------------------------------------------- 1573cdf0e10cSrcweir 1574cdf0e10cSrcweir SvStream& SvStream::ReadByteString( ByteString& rStr ) 1575cdf0e10cSrcweir { 1576cdf0e10cSrcweir sal_uInt16 nLen = 0; 1577cdf0e10cSrcweir operator>>( nLen ); 1578cdf0e10cSrcweir if( nLen ) 1579cdf0e10cSrcweir { 1580cdf0e10cSrcweir char* pTmp = rStr.AllocBuffer( nLen ); 1581cdf0e10cSrcweir nLen = (sal_uInt16)Read( pTmp, nLen ); 1582cdf0e10cSrcweir } 1583cdf0e10cSrcweir else 1584cdf0e10cSrcweir rStr.Erase(); 1585cdf0e10cSrcweir return *this; 1586cdf0e10cSrcweir } 1587cdf0e10cSrcweir 1588cdf0e10cSrcweir // ----------------------------------------------------------------------- 1589cdf0e10cSrcweir 1590cdf0e10cSrcweir SvStream& SvStream::WriteByteString( const UniString& rStr, rtl_TextEncoding eDestCharSet ) 1591cdf0e10cSrcweir { 1592cdf0e10cSrcweir // write UTF-16 string directly into stream ? 1593cdf0e10cSrcweir if (eDestCharSet == RTL_TEXTENCODING_UNICODE) 1594cdf0e10cSrcweir { 1595cdf0e10cSrcweir sal_uInt32 nLen = rStr.Len(); 1596cdf0e10cSrcweir operator<< (nLen); 1597cdf0e10cSrcweir if (nLen) 1598cdf0e10cSrcweir { 1599cdf0e10cSrcweir if (bSwap) 1600cdf0e10cSrcweir { 1601cdf0e10cSrcweir const sal_Unicode *pStr = rStr.GetBuffer(); 1602cdf0e10cSrcweir const sal_Unicode *pEnd = pStr + nLen; 1603cdf0e10cSrcweir 1604cdf0e10cSrcweir for (; pStr < pEnd; pStr++) 1605cdf0e10cSrcweir { 1606cdf0e10cSrcweir sal_Unicode c = *pStr; 1607cdf0e10cSrcweir SwapUShort(c); 1608cdf0e10cSrcweir WRITENUMBER_WITHOUT_SWAP(sal_uInt16,c) 1609cdf0e10cSrcweir } 1610cdf0e10cSrcweir } 1611cdf0e10cSrcweir else 1612cdf0e10cSrcweir Write( rStr.GetBuffer(), nLen << 1 ); 1613cdf0e10cSrcweir } 1614cdf0e10cSrcweir 1615cdf0e10cSrcweir return *this; 1616cdf0e10cSrcweir } 1617cdf0e10cSrcweir 1618cdf0e10cSrcweir return WriteByteString(ByteString( rStr, eDestCharSet )); 1619cdf0e10cSrcweir } 1620cdf0e10cSrcweir 1621cdf0e10cSrcweir // ----------------------------------------------------------------------- 1622cdf0e10cSrcweir 1623cdf0e10cSrcweir SvStream& SvStream::WriteByteString( const ByteString& rStr) 1624cdf0e10cSrcweir { 1625cdf0e10cSrcweir sal_uInt16 nLen = rStr.Len(); 1626cdf0e10cSrcweir operator<< ( nLen ); 1627cdf0e10cSrcweir if( nLen != 0 ) 1628cdf0e10cSrcweir Write( rStr.GetBuffer(), nLen ); 1629cdf0e10cSrcweir return *this; 1630cdf0e10cSrcweir } 1631cdf0e10cSrcweir 1632cdf0e10cSrcweir /************************************************************************* 1633cdf0e10cSrcweir |* 1634cdf0e10cSrcweir |* Stream::Read() 1635cdf0e10cSrcweir |* 1636cdf0e10cSrcweir |* Beschreibung STREAM.SDW 1637cdf0e10cSrcweir |* Ersterstellung OV 08.06.94 1638cdf0e10cSrcweir |* Letzte Aenderung OV 08.06.94 1639cdf0e10cSrcweir |* 1640cdf0e10cSrcweir *************************************************************************/ 1641cdf0e10cSrcweir 1642cdf0e10cSrcweir sal_Size SvStream::Read( void* pData, sal_Size nCount ) 1643cdf0e10cSrcweir { 1644cdf0e10cSrcweir sal_Size nSaveCount = nCount; 1645cdf0e10cSrcweir if( !bIsConsistent ) 1646cdf0e10cSrcweir RefreshBuffer(); 1647cdf0e10cSrcweir 1648cdf0e10cSrcweir if( !pRWBuf ) 1649cdf0e10cSrcweir { 1650cdf0e10cSrcweir nCount = GetData( (char*)pData,nCount); 1651cdf0e10cSrcweir if( nCryptMask ) 1652cdf0e10cSrcweir EncryptBuffer(pData, nCount); 1653cdf0e10cSrcweir nBufFilePos += nCount; 1654cdf0e10cSrcweir } 1655cdf0e10cSrcweir else 1656cdf0e10cSrcweir { 1657cdf0e10cSrcweir // ist Block komplett im Puffer 1658cdf0e10cSrcweir eIOMode = STREAM_IO_READ; 1659cdf0e10cSrcweir if( nCount <= (sal_Size)(nBufActualLen - nBufActualPos ) ) 1660cdf0e10cSrcweir { 1661cdf0e10cSrcweir // Ja! 1662cdf0e10cSrcweir memcpy(pData, pBufPos, (size_t) nCount); 1663cdf0e10cSrcweir nBufActualPos = nBufActualPos + (sal_uInt16)nCount; 1664cdf0e10cSrcweir pBufPos += nCount; 1665cdf0e10cSrcweir nBufFree = nBufFree - (sal_uInt16)nCount; 1666cdf0e10cSrcweir } 1667cdf0e10cSrcweir else 1668cdf0e10cSrcweir { 1669cdf0e10cSrcweir if( bIsDirty ) // Flushen ? 1670cdf0e10cSrcweir { 1671cdf0e10cSrcweir SeekPos( nBufFilePos ); 1672cdf0e10cSrcweir if( nCryptMask ) 1673cdf0e10cSrcweir CryptAndWriteBuffer(pRWBuf, nBufActualLen); 1674cdf0e10cSrcweir else 1675cdf0e10cSrcweir PutData( pRWBuf, nBufActualLen ); 1676cdf0e10cSrcweir bIsDirty = sal_False; 1677cdf0e10cSrcweir } 1678cdf0e10cSrcweir 1679cdf0e10cSrcweir // passt der Datenblock in den Puffer ? 1680cdf0e10cSrcweir if( nCount > nBufSize ) 1681cdf0e10cSrcweir { 1682cdf0e10cSrcweir // Nein! Deshalb ohne Umweg ueber den Puffer direkt 1683cdf0e10cSrcweir // in den Zielbereich einlesen 1684cdf0e10cSrcweir 1685cdf0e10cSrcweir eIOMode = STREAM_IO_DONTKNOW; 1686cdf0e10cSrcweir 1687cdf0e10cSrcweir SeekPos( nBufFilePos + nBufActualPos ); 1688cdf0e10cSrcweir nBufActualLen = 0; 1689cdf0e10cSrcweir pBufPos = pRWBuf; 1690cdf0e10cSrcweir nCount = GetData( (char*)pData, nCount ); 1691cdf0e10cSrcweir if( nCryptMask ) 1692cdf0e10cSrcweir EncryptBuffer(pData, nCount); 1693cdf0e10cSrcweir nBufFilePos += nCount; 1694cdf0e10cSrcweir nBufFilePos += nBufActualPos; 1695cdf0e10cSrcweir nBufActualPos = 0; 1696cdf0e10cSrcweir } 1697cdf0e10cSrcweir else 1698cdf0e10cSrcweir { 1699cdf0e10cSrcweir // Der Datenblock passt komplett in den Puffer. Deshalb 1700cdf0e10cSrcweir // Puffer fuellen und dann die angeforderten Daten in den 1701cdf0e10cSrcweir // Zielbereich kopieren. 1702cdf0e10cSrcweir 1703cdf0e10cSrcweir nBufFilePos += nBufActualPos; 1704cdf0e10cSrcweir SeekPos( nBufFilePos ); 1705cdf0e10cSrcweir 1706cdf0e10cSrcweir // TODO: Typecast vor GetData, sal_uInt16 nCountTmp 1707cdf0e10cSrcweir sal_Size nCountTmp = GetData( pRWBuf, nBufSize ); 1708cdf0e10cSrcweir if( nCryptMask ) 1709cdf0e10cSrcweir EncryptBuffer(pRWBuf, nCountTmp); 1710cdf0e10cSrcweir nBufActualLen = (sal_uInt16)nCountTmp; 1711cdf0e10cSrcweir if( nCount > nCountTmp ) 1712cdf0e10cSrcweir { 1713cdf0e10cSrcweir nCount = nCountTmp; // zurueckstutzen, Eof siehe unten 1714cdf0e10cSrcweir } 1715cdf0e10cSrcweir memcpy( pData, pRWBuf, (size_t)nCount ); 1716cdf0e10cSrcweir nBufActualPos = (sal_uInt16)nCount; 1717cdf0e10cSrcweir pBufPos = pRWBuf + nCount; 1718cdf0e10cSrcweir } 1719cdf0e10cSrcweir } 1720cdf0e10cSrcweir } 1721cdf0e10cSrcweir bIsEof = sal_False; 1722cdf0e10cSrcweir nBufFree = nBufActualLen - nBufActualPos; 1723cdf0e10cSrcweir if( nCount != nSaveCount && nError != ERRCODE_IO_PENDING ) 1724cdf0e10cSrcweir bIsEof = sal_True; 1725cdf0e10cSrcweir if( nCount == nSaveCount && nError == ERRCODE_IO_PENDING ) 1726cdf0e10cSrcweir nError = ERRCODE_NONE; 1727cdf0e10cSrcweir return nCount; 1728cdf0e10cSrcweir } 1729cdf0e10cSrcweir 1730cdf0e10cSrcweir /************************************************************************* 1731cdf0e10cSrcweir |* 1732cdf0e10cSrcweir |* Stream::Write() 1733cdf0e10cSrcweir |* 1734cdf0e10cSrcweir |* Beschreibung STREAM.SDW 1735cdf0e10cSrcweir |* Ersterstellung OV 08.06.94 1736cdf0e10cSrcweir |* Letzte Aenderung OV 08.06.94 1737cdf0e10cSrcweir |* 1738cdf0e10cSrcweir *************************************************************************/ 1739cdf0e10cSrcweir 1740cdf0e10cSrcweir sal_Size SvStream::Write( const void* pData, sal_Size nCount ) 1741cdf0e10cSrcweir { 1742cdf0e10cSrcweir if( !nCount ) 1743cdf0e10cSrcweir return 0; 1744cdf0e10cSrcweir if( !bIsWritable ) 1745cdf0e10cSrcweir { 1746cdf0e10cSrcweir SetError( ERRCODE_IO_CANTWRITE ); 1747cdf0e10cSrcweir return 0; 1748cdf0e10cSrcweir } 1749cdf0e10cSrcweir if( !bIsConsistent ) 1750cdf0e10cSrcweir RefreshBuffer(); // Aenderungen des Puffers durch PutBack loeschen 1751cdf0e10cSrcweir 1752cdf0e10cSrcweir if( !pRWBuf ) 1753cdf0e10cSrcweir { 1754cdf0e10cSrcweir if( nCryptMask ) 1755cdf0e10cSrcweir nCount = CryptAndWriteBuffer( pData, nCount ); 1756cdf0e10cSrcweir else 1757cdf0e10cSrcweir nCount = PutData( (char*)pData, nCount ); 1758cdf0e10cSrcweir nBufFilePos += nCount; 1759cdf0e10cSrcweir return nCount; 1760cdf0e10cSrcweir } 1761cdf0e10cSrcweir 1762cdf0e10cSrcweir eIOMode = STREAM_IO_WRITE; 1763cdf0e10cSrcweir if( nCount <= (sal_Size)(nBufSize - nBufActualPos) ) 1764cdf0e10cSrcweir { 1765cdf0e10cSrcweir memcpy( pBufPos, pData, (size_t)nCount ); 1766cdf0e10cSrcweir nBufActualPos = nBufActualPos + (sal_uInt16)nCount; 1767cdf0e10cSrcweir // wurde der Puffer erweitert ? 1768cdf0e10cSrcweir if( nBufActualPos > nBufActualLen ) 1769cdf0e10cSrcweir nBufActualLen = nBufActualPos; 1770cdf0e10cSrcweir 1771cdf0e10cSrcweir pBufPos += nCount; 1772cdf0e10cSrcweir bIsDirty = sal_True; 1773cdf0e10cSrcweir } 1774cdf0e10cSrcweir else 1775cdf0e10cSrcweir { 1776cdf0e10cSrcweir // Flushen ? 1777cdf0e10cSrcweir if( bIsDirty ) 1778cdf0e10cSrcweir { 1779cdf0e10cSrcweir SeekPos( nBufFilePos ); 1780cdf0e10cSrcweir if( nCryptMask ) 1781cdf0e10cSrcweir CryptAndWriteBuffer( pRWBuf, (sal_Size)nBufActualLen ); 1782cdf0e10cSrcweir else 1783cdf0e10cSrcweir PutData( pRWBuf, nBufActualLen ); 1784cdf0e10cSrcweir bIsDirty = sal_False; 1785cdf0e10cSrcweir } 1786cdf0e10cSrcweir 1787cdf0e10cSrcweir // passt der Block in den Puffer ? 1788cdf0e10cSrcweir if( nCount > nBufSize ) 1789cdf0e10cSrcweir { 1790cdf0e10cSrcweir eIOMode = STREAM_IO_DONTKNOW; 1791cdf0e10cSrcweir nBufFilePos += nBufActualPos; 1792cdf0e10cSrcweir nBufActualLen = 0; 1793cdf0e10cSrcweir nBufActualPos = 0; 1794cdf0e10cSrcweir pBufPos = pRWBuf; 1795cdf0e10cSrcweir SeekPos( nBufFilePos ); 1796cdf0e10cSrcweir if( nCryptMask ) 1797cdf0e10cSrcweir nCount = CryptAndWriteBuffer( pData, nCount ); 1798cdf0e10cSrcweir else 1799cdf0e10cSrcweir nCount = PutData( (char*)pData, nCount ); 1800cdf0e10cSrcweir nBufFilePos += nCount; 1801cdf0e10cSrcweir } 1802cdf0e10cSrcweir else 1803cdf0e10cSrcweir { 1804cdf0e10cSrcweir // Block in Puffer stellen 1805cdf0e10cSrcweir memcpy( pRWBuf, pData, (size_t)nCount ); 1806cdf0e10cSrcweir 1807cdf0e10cSrcweir // Reihenfolge! 1808cdf0e10cSrcweir nBufFilePos += nBufActualPos; 1809cdf0e10cSrcweir nBufActualPos = (sal_uInt16)nCount; 1810cdf0e10cSrcweir pBufPos = pRWBuf + nCount; 1811cdf0e10cSrcweir nBufActualLen = (sal_uInt16)nCount; 1812cdf0e10cSrcweir bIsDirty = sal_True; 1813cdf0e10cSrcweir } 1814cdf0e10cSrcweir } 1815cdf0e10cSrcweir nBufFree = nBufSize - nBufActualPos; 1816cdf0e10cSrcweir return nCount; 1817cdf0e10cSrcweir } 1818cdf0e10cSrcweir 1819cdf0e10cSrcweir 1820cdf0e10cSrcweir /************************************************************************* 1821cdf0e10cSrcweir |* 1822cdf0e10cSrcweir |* Stream::Seek() 1823cdf0e10cSrcweir |* 1824cdf0e10cSrcweir |* Beschreibung STREAM.SDW 1825cdf0e10cSrcweir |* Ersterstellung OV 08.06.94 1826cdf0e10cSrcweir |* Letzte Aenderung OV 08.06.94 1827cdf0e10cSrcweir |* 1828cdf0e10cSrcweir *************************************************************************/ 1829cdf0e10cSrcweir 1830cdf0e10cSrcweir sal_Size SvStream::Seek( sal_Size nFilePos ) 1831cdf0e10cSrcweir { 1832cdf0e10cSrcweir eIOMode = STREAM_IO_DONTKNOW; 1833cdf0e10cSrcweir 1834cdf0e10cSrcweir bIsEof = sal_False; 1835cdf0e10cSrcweir if( !pRWBuf ) 1836cdf0e10cSrcweir { 1837cdf0e10cSrcweir nBufFilePos = SeekPos( nFilePos ); 1838cdf0e10cSrcweir DBG_ASSERT(Tell()==nBufFilePos,"Out Of Sync!"); 1839cdf0e10cSrcweir return nBufFilePos; 1840cdf0e10cSrcweir } 1841cdf0e10cSrcweir 1842cdf0e10cSrcweir // Ist Position im Puffer ? 1843cdf0e10cSrcweir if( nFilePos >= nBufFilePos && nFilePos <= (nBufFilePos + nBufActualLen)) 1844cdf0e10cSrcweir { 1845cdf0e10cSrcweir nBufActualPos = (sal_uInt16)(nFilePos - nBufFilePos); 1846cdf0e10cSrcweir pBufPos = pRWBuf + nBufActualPos; 1847cdf0e10cSrcweir // nBufFree korrigieren, damit wir nicht von einem 1848cdf0e10cSrcweir // PutBack (ignoriert den StreamMode) getoetet werden 1849cdf0e10cSrcweir nBufFree = nBufActualLen - nBufActualPos; 1850cdf0e10cSrcweir } 1851cdf0e10cSrcweir else 1852cdf0e10cSrcweir { 1853cdf0e10cSrcweir if( bIsDirty && bIsConsistent) 1854cdf0e10cSrcweir { 1855cdf0e10cSrcweir SeekPos( nBufFilePos ); 1856cdf0e10cSrcweir if( nCryptMask ) 1857cdf0e10cSrcweir CryptAndWriteBuffer( pRWBuf, nBufActualLen ); 1858cdf0e10cSrcweir else 1859cdf0e10cSrcweir PutData( pRWBuf, nBufActualLen ); 1860cdf0e10cSrcweir bIsDirty = sal_False; 1861cdf0e10cSrcweir } 1862cdf0e10cSrcweir nBufActualLen = 0; 1863cdf0e10cSrcweir nBufActualPos = 0; 1864cdf0e10cSrcweir pBufPos = pRWBuf; 1865cdf0e10cSrcweir nBufFilePos = SeekPos( nFilePos ); 1866cdf0e10cSrcweir } 1867cdf0e10cSrcweir #ifdef OV_DEBUG 1868cdf0e10cSrcweir { 1869cdf0e10cSrcweir sal_Size nDebugTemp = nBufFilePos + nBufActualPos; 1870cdf0e10cSrcweir DBG_ASSERT(Tell()==nDebugTemp,"Sync?"); 1871cdf0e10cSrcweir } 1872cdf0e10cSrcweir #endif 1873cdf0e10cSrcweir return nBufFilePos + nBufActualPos; 1874cdf0e10cSrcweir } 1875cdf0e10cSrcweir 1876cdf0e10cSrcweir /************************************************************************* 1877cdf0e10cSrcweir |* 1878cdf0e10cSrcweir |* Stream::Flush() 1879cdf0e10cSrcweir |* 1880cdf0e10cSrcweir |* Beschreibung STREAM.SDW 1881cdf0e10cSrcweir |* Ersterstellung OV 08.06.94 1882cdf0e10cSrcweir |* Letzte Aenderung OV 08.06.94 1883cdf0e10cSrcweir |* 1884cdf0e10cSrcweir *************************************************************************/ 1885cdf0e10cSrcweir 1886cdf0e10cSrcweir void SvStream::Flush() 1887cdf0e10cSrcweir { 1888cdf0e10cSrcweir if( bIsDirty && bIsConsistent ) 1889cdf0e10cSrcweir { 1890cdf0e10cSrcweir SeekPos( nBufFilePos ); 1891cdf0e10cSrcweir if( nCryptMask ) 1892cdf0e10cSrcweir CryptAndWriteBuffer( pRWBuf, (sal_Size)nBufActualLen ); 1893cdf0e10cSrcweir else 1894cdf0e10cSrcweir if( PutData( pRWBuf, nBufActualLen ) != nBufActualLen ) 1895cdf0e10cSrcweir SetError( SVSTREAM_WRITE_ERROR ); 1896cdf0e10cSrcweir bIsDirty = sal_False; 1897cdf0e10cSrcweir } 1898cdf0e10cSrcweir if( bIsWritable ) 1899cdf0e10cSrcweir FlushData(); 1900cdf0e10cSrcweir } 1901cdf0e10cSrcweir 1902cdf0e10cSrcweir 1903cdf0e10cSrcweir /************************************************************************* 1904cdf0e10cSrcweir |* 1905cdf0e10cSrcweir |* Stream::PutBack() 1906cdf0e10cSrcweir |* 1907cdf0e10cSrcweir |* Beschreibung STREAM.SDW 1908cdf0e10cSrcweir |* Ersterstellung OV 01.08.94 1909cdf0e10cSrcweir |* Letzte Aenderung OV 01.08.94 1910cdf0e10cSrcweir |* 1911cdf0e10cSrcweir *************************************************************************/ 1912cdf0e10cSrcweir 1913cdf0e10cSrcweir /* 1914cdf0e10cSrcweir 4 Faelle : 1915cdf0e10cSrcweir 1916cdf0e10cSrcweir 1. Datenzeiger steht mitten im Puffer (nBufActualPos >= 1) 1917cdf0e10cSrcweir 2. Datenzeiger auf Position 0, Puffer ist voll 1918cdf0e10cSrcweir 3. Datenzeiger auf Position 0, Puffer ist teilweise gefuellt 1919cdf0e10cSrcweir 4. Datenzeiger auf Position 0, Puffer ist leer -> Fehler! 1920cdf0e10cSrcweir */ 1921cdf0e10cSrcweir 1922cdf0e10cSrcweir SvStream& SvStream::PutBack( char aCh ) 1923cdf0e10cSrcweir { 1924cdf0e10cSrcweir // wenn kein Buffer oder Zurueckscrollen nicht moeglich -> Fehler 1925cdf0e10cSrcweir if( !pRWBuf || !nBufActualLen || ( !nBufActualPos && !nBufFilePos ) ) 1926cdf0e10cSrcweir { 1927cdf0e10cSrcweir // 4. Fall 1928cdf0e10cSrcweir SetError( SVSTREAM_GENERALERROR ); 1929cdf0e10cSrcweir return *this; 1930cdf0e10cSrcweir } 1931cdf0e10cSrcweir 1932cdf0e10cSrcweir // Flush() (Phys. Flushen aber nicht notwendig, deshalb selbst schreiben) 1933cdf0e10cSrcweir if( bIsConsistent && bIsDirty ) 1934cdf0e10cSrcweir { 1935cdf0e10cSrcweir SeekPos( nBufFilePos ); 1936cdf0e10cSrcweir if( nCryptMask ) 1937cdf0e10cSrcweir CryptAndWriteBuffer( pRWBuf, nBufActualLen ); 1938cdf0e10cSrcweir else 1939cdf0e10cSrcweir PutData( pRWBuf, nBufActualLen ); 1940cdf0e10cSrcweir bIsDirty = sal_False; 1941cdf0e10cSrcweir } 1942cdf0e10cSrcweir bIsConsistent = sal_False; // Puffer enthaelt jetzt TRASH 1943cdf0e10cSrcweir if( nBufActualPos ) 1944cdf0e10cSrcweir { 1945cdf0e10cSrcweir // 1. Fall 1946cdf0e10cSrcweir nBufActualPos--; 1947cdf0e10cSrcweir pBufPos--; 1948cdf0e10cSrcweir *pBufPos = aCh; 1949cdf0e10cSrcweir nBufFree++; 1950cdf0e10cSrcweir } 1951cdf0e10cSrcweir else // Puffer muss verschoben werden 1952cdf0e10cSrcweir { 1953cdf0e10cSrcweir // Ist Puffer am Anschlag ? 1954cdf0e10cSrcweir if( nBufSize == nBufActualLen ) 1955cdf0e10cSrcweir { 1956cdf0e10cSrcweir // 2. Fall 1957cdf0e10cSrcweir memmove( pRWBuf+1, pRWBuf, nBufSize-1 ); 1958cdf0e10cSrcweir // nBufFree behaelt den Wert! 1959cdf0e10cSrcweir } 1960cdf0e10cSrcweir else 1961cdf0e10cSrcweir { 1962cdf0e10cSrcweir // 3. Fall -> Puffer vergroessern 1963cdf0e10cSrcweir memmove( pRWBuf+1, pRWBuf, (sal_uInt16)nBufActualLen ); 1964cdf0e10cSrcweir nBufActualLen++; 1965cdf0e10cSrcweir nBufFree++; 1966cdf0e10cSrcweir } 1967cdf0e10cSrcweir nBufFilePos--; 1968cdf0e10cSrcweir *pRWBuf = aCh; 1969cdf0e10cSrcweir } 1970cdf0e10cSrcweir eIOMode = STREAM_IO_DONTKNOW; 1971cdf0e10cSrcweir bIsEof = sal_False; 1972cdf0e10cSrcweir return *this; 1973cdf0e10cSrcweir } 1974cdf0e10cSrcweir 1975cdf0e10cSrcweir /************************************************************************* 1976cdf0e10cSrcweir |* 1977cdf0e10cSrcweir |* Stream::EatWhite() 1978cdf0e10cSrcweir |* 1979cdf0e10cSrcweir |* Beschreibung STREAM.SDW 1980cdf0e10cSrcweir |* Ersterstellung OV 01.08.94 1981cdf0e10cSrcweir |* Letzte Aenderung OV 01.08.94 1982cdf0e10cSrcweir |* 1983cdf0e10cSrcweir *************************************************************************/ 1984cdf0e10cSrcweir 1985cdf0e10cSrcweir void SvStream::EatWhite() 1986cdf0e10cSrcweir { 1987cdf0e10cSrcweir char aCh; 1988cdf0e10cSrcweir Read(&aCh, sizeof(char) ); 1989cdf0e10cSrcweir while( !bIsEof && isspace((int)aCh) ) //( aCh == ' ' || aCh == '\t' ) ) 1990cdf0e10cSrcweir Read(&aCh, sizeof(char) ); 1991cdf0e10cSrcweir if( !bIsEof ) // konnte das letzte Char gelesen werden ? 1992cdf0e10cSrcweir SeekRel( -1L ); 1993cdf0e10cSrcweir } 1994cdf0e10cSrcweir 1995cdf0e10cSrcweir /************************************************************************* 1996cdf0e10cSrcweir |* 1997cdf0e10cSrcweir |* Stream::RefreshBuffer() 1998cdf0e10cSrcweir |* 1999cdf0e10cSrcweir |* Beschreibung STREAM.SDW 2000cdf0e10cSrcweir |* Ersterstellung OV 01.08.94 2001cdf0e10cSrcweir |* Letzte Aenderung OV 01.08.94 2002cdf0e10cSrcweir |* 2003cdf0e10cSrcweir *************************************************************************/ 2004cdf0e10cSrcweir 2005cdf0e10cSrcweir void SvStream::RefreshBuffer() 2006cdf0e10cSrcweir { 2007cdf0e10cSrcweir if( bIsDirty && bIsConsistent ) 2008cdf0e10cSrcweir { 2009cdf0e10cSrcweir SeekPos( nBufFilePos ); 2010cdf0e10cSrcweir if( nCryptMask ) 2011cdf0e10cSrcweir CryptAndWriteBuffer( pRWBuf, (sal_Size)nBufActualLen ); 2012cdf0e10cSrcweir else 2013cdf0e10cSrcweir PutData( pRWBuf, nBufActualLen ); 2014cdf0e10cSrcweir bIsDirty = sal_False; 2015cdf0e10cSrcweir } 2016cdf0e10cSrcweir SeekPos( nBufFilePos ); 2017cdf0e10cSrcweir nBufActualLen = (sal_uInt16)GetData( pRWBuf, nBufSize ); 2018cdf0e10cSrcweir if( nBufActualLen && nError == ERRCODE_IO_PENDING ) 2019cdf0e10cSrcweir nError = ERRCODE_NONE; 2020cdf0e10cSrcweir if( nCryptMask ) 2021cdf0e10cSrcweir EncryptBuffer(pRWBuf, (sal_Size)nBufActualLen); 2022cdf0e10cSrcweir bIsConsistent = sal_True; 2023cdf0e10cSrcweir eIOMode = STREAM_IO_DONTKNOW; 2024cdf0e10cSrcweir } 2025cdf0e10cSrcweir 2026cdf0e10cSrcweir 2027cdf0e10cSrcweir /************************************************************************* 2028cdf0e10cSrcweir |* 2029cdf0e10cSrcweir |* Stream::CreateFormatString() 2030cdf0e10cSrcweir |* 2031cdf0e10cSrcweir |* Beschreibung Baut Formatstring zusammen 2032cdf0e10cSrcweir |* Ersterstellung OV 08.06.94 2033cdf0e10cSrcweir |* Letzte Aenderung OV 08.06.94 2034cdf0e10cSrcweir |* 2035cdf0e10cSrcweir *************************************************************************/ 2036cdf0e10cSrcweir 2037cdf0e10cSrcweir void SvStream::CreateFormatString() 2038cdf0e10cSrcweir { 2039cdf0e10cSrcweir aFormatString = '%'; 2040cdf0e10cSrcweir nPrintfParams = SPECIAL_PARAM_NONE; 2041cdf0e10cSrcweir 2042cdf0e10cSrcweir if( nJustification ) 2043cdf0e10cSrcweir { 2044cdf0e10cSrcweir aFormatString += '-'; 2045cdf0e10cSrcweir } 2046cdf0e10cSrcweir 2047cdf0e10cSrcweir if( nWidth ) 2048cdf0e10cSrcweir { 2049cdf0e10cSrcweir if( cFiller != ' ' ) 2050cdf0e10cSrcweir aFormatString += '0'; 2051cdf0e10cSrcweir aFormatString += '*'; 2052cdf0e10cSrcweir nPrintfParams = SPECIAL_PARAM_WIDTH; 2053cdf0e10cSrcweir } 2054cdf0e10cSrcweir 2055cdf0e10cSrcweir if( nPrecision ) 2056cdf0e10cSrcweir { 2057cdf0e10cSrcweir aFormatString += ".*"; 2058cdf0e10cSrcweir if( nWidth ) 2059cdf0e10cSrcweir nPrintfParams = SPECIAL_PARAM_BOTH; 2060cdf0e10cSrcweir else 2061cdf0e10cSrcweir nPrintfParams = SPECIAL_PARAM_PRECISION; 2062cdf0e10cSrcweir } 2063cdf0e10cSrcweir } 2064cdf0e10cSrcweir 2065cdf0e10cSrcweir /************************************************************************* 2066cdf0e10cSrcweir |* 2067cdf0e10cSrcweir |* Stream::ReadNumber() 2068cdf0e10cSrcweir |* 2069cdf0e10cSrcweir |* Beschreibung STREAM.SDW 2070cdf0e10cSrcweir |* Ersterstellung OV 08.06.94 2071cdf0e10cSrcweir |* Letzte Aenderung OV 08.06.94 2072cdf0e10cSrcweir |* 2073cdf0e10cSrcweir *************************************************************************/ 2074cdf0e10cSrcweir 2075cdf0e10cSrcweir #define BUFSIZE_LONG 21 // log( 2 hoch 64 ) + 1 2076cdf0e10cSrcweir 2077cdf0e10cSrcweir SvStream& SvStream::ReadNumber( long& rLong ) 2078cdf0e10cSrcweir { 2079cdf0e10cSrcweir EatWhite(); 2080cdf0e10cSrcweir if( bIsEof || nError ) 2081cdf0e10cSrcweir { 2082cdf0e10cSrcweir SetError( SVSTREAM_GENERALERROR ); 2083cdf0e10cSrcweir return *this; 2084cdf0e10cSrcweir } 2085cdf0e10cSrcweir sal_Size nFPtr = Tell(); 2086cdf0e10cSrcweir char buf[ BUFSIZE_LONG ]; 2087cdf0e10cSrcweir memset( buf, 0, BUFSIZE_LONG ); 2088cdf0e10cSrcweir sal_Size nTemp = Read( buf, BUFSIZE_LONG-1 ); 2089cdf0e10cSrcweir if( !nTemp || nError ) 2090cdf0e10cSrcweir { 2091cdf0e10cSrcweir SetError( SVSTREAM_GENERALERROR ); 2092cdf0e10cSrcweir return *this; 2093cdf0e10cSrcweir } 2094cdf0e10cSrcweir char *pEndPtr; 2095cdf0e10cSrcweir rLong = strtol( buf, &pEndPtr, (int)nRadix ); 2096cdf0e10cSrcweir nFPtr += ( (sal_Size)pEndPtr - (sal_Size)(&(buf[0])) ); 2097cdf0e10cSrcweir Seek( nFPtr ); 2098cdf0e10cSrcweir bIsEof = sal_False; 2099cdf0e10cSrcweir return *this; 2100cdf0e10cSrcweir } 2101cdf0e10cSrcweir 2102cdf0e10cSrcweir SvStream& SvStream::ReadNumber( sal_uInt32& rUInt32 ) 2103cdf0e10cSrcweir { 2104cdf0e10cSrcweir EatWhite(); 2105cdf0e10cSrcweir if( bIsEof || nError ) 2106cdf0e10cSrcweir { 2107cdf0e10cSrcweir SetError( SVSTREAM_GENERALERROR ); 2108cdf0e10cSrcweir return *this; 2109cdf0e10cSrcweir } 2110cdf0e10cSrcweir sal_Size nFPtr = Tell(); 2111cdf0e10cSrcweir char buf[ BUFSIZE_LONG ]; 2112cdf0e10cSrcweir memset( buf, 0, BUFSIZE_LONG ); 2113cdf0e10cSrcweir sal_Size nTemp = Read( buf, BUFSIZE_LONG-1 ); 2114cdf0e10cSrcweir if( !nTemp || nError ) 2115cdf0e10cSrcweir { 2116cdf0e10cSrcweir SetError( SVSTREAM_GENERALERROR ); 2117cdf0e10cSrcweir return *this; 2118cdf0e10cSrcweir } 2119cdf0e10cSrcweir char *pEndPtr; 2120cdf0e10cSrcweir rUInt32 = strtoul( buf, &pEndPtr, (int)nRadix ); 2121cdf0e10cSrcweir nFPtr += ( (sal_uIntPtr)pEndPtr - (sal_uIntPtr)buf ); 2122cdf0e10cSrcweir Seek( nFPtr ); 2123cdf0e10cSrcweir bIsEof = sal_False; 2124cdf0e10cSrcweir return *this; 2125cdf0e10cSrcweir } 2126cdf0e10cSrcweir 2127cdf0e10cSrcweir SvStream& SvStream::ReadNumber( double& rDouble ) 2128cdf0e10cSrcweir { 2129cdf0e10cSrcweir EatWhite(); 2130cdf0e10cSrcweir if( bIsEof || nError ) 2131cdf0e10cSrcweir { 2132cdf0e10cSrcweir SetError( SVSTREAM_GENERALERROR ); 2133cdf0e10cSrcweir return *this; 2134cdf0e10cSrcweir } 2135cdf0e10cSrcweir sal_Size nFPtr = Tell(); 2136cdf0e10cSrcweir char buf[ BUFSIZE_LONG ]; 2137cdf0e10cSrcweir memset( buf, 0, BUFSIZE_LONG ); 2138cdf0e10cSrcweir sal_Size nTemp = Read( buf, BUFSIZE_LONG-1 ); 2139cdf0e10cSrcweir if( !nTemp || nError ) 2140cdf0e10cSrcweir { 2141cdf0e10cSrcweir SetError( SVSTREAM_GENERALERROR ); 2142cdf0e10cSrcweir return *this; 2143cdf0e10cSrcweir } 2144cdf0e10cSrcweir char *pEndPtr; 2145cdf0e10cSrcweir rDouble = strtod( buf, &pEndPtr ); 2146cdf0e10cSrcweir nFPtr += ( (sal_Size)pEndPtr - (sal_Size)buf ); 2147cdf0e10cSrcweir Seek( nFPtr ); 2148cdf0e10cSrcweir bIsEof = sal_False; 2149cdf0e10cSrcweir return *this; 2150cdf0e10cSrcweir } 2151cdf0e10cSrcweir 2152cdf0e10cSrcweir 2153cdf0e10cSrcweir /************************************************************************* 2154cdf0e10cSrcweir |* 2155cdf0e10cSrcweir |* Stream::WriteNumber() 2156cdf0e10cSrcweir |* 2157cdf0e10cSrcweir |* Beschreibung STREAM.SDW 2158cdf0e10cSrcweir |* Ersterstellung OV 08.06.94 2159cdf0e10cSrcweir |* Letzte Aenderung OV 08.06.94 2160cdf0e10cSrcweir |* 2161cdf0e10cSrcweir *************************************************************************/ 2162cdf0e10cSrcweir 2163cdf0e10cSrcweir SvStream& SvStream::WriteNumber( long nLong ) 2164cdf0e10cSrcweir { 2165cdf0e10cSrcweir char buffer[256+12]; 2166cdf0e10cSrcweir char pType[] = "ld"; // Nicht static! 2167cdf0e10cSrcweir if( nRadix == 16 ) 2168cdf0e10cSrcweir pType[1] = 'x'; 2169cdf0e10cSrcweir else if( nRadix == 8 ) 2170cdf0e10cSrcweir pType[1] = 'o'; 2171cdf0e10cSrcweir ByteString aFStr( aFormatString); 2172cdf0e10cSrcweir aFStr += pType; 2173cdf0e10cSrcweir int nLen; 2174cdf0e10cSrcweir switch ( nPrintfParams ) 2175cdf0e10cSrcweir { 2176cdf0e10cSrcweir case SPECIAL_PARAM_NONE : 2177cdf0e10cSrcweir nLen = sprintf( buffer, aFStr.GetBuffer(), nLong ); 2178cdf0e10cSrcweir break; 2179cdf0e10cSrcweir case SPECIAL_PARAM_WIDTH : 2180cdf0e10cSrcweir nLen = sprintf( buffer, aFStr.GetBuffer(), nWidth, nLong ); 2181cdf0e10cSrcweir break; 2182cdf0e10cSrcweir case SPECIAL_PARAM_PRECISION : 2183cdf0e10cSrcweir nLen = sprintf( buffer, aFStr.GetBuffer(), nPrecision,nLong); 2184cdf0e10cSrcweir break; 2185cdf0e10cSrcweir default: 2186cdf0e10cSrcweir nLen=sprintf(buffer, aFStr.GetBuffer(),nWidth,nPrecision,nLong); 2187cdf0e10cSrcweir } 2188cdf0e10cSrcweir Write( buffer, (long)nLen ); 2189cdf0e10cSrcweir return *this; 2190cdf0e10cSrcweir } 2191cdf0e10cSrcweir 2192cdf0e10cSrcweir SvStream& SvStream::WriteNumber( sal_uInt32 nUInt32 ) 2193cdf0e10cSrcweir { 2194cdf0e10cSrcweir char buffer[256+12]; 2195cdf0e10cSrcweir char pType[] = "lu"; // Nicht static! 2196cdf0e10cSrcweir if( nRadix == 16 ) 2197cdf0e10cSrcweir pType[1] = 'x'; 2198cdf0e10cSrcweir else if( nRadix == 8 ) 2199cdf0e10cSrcweir pType[1] = 'o'; 2200cdf0e10cSrcweir ByteString aFStr( aFormatString); 2201cdf0e10cSrcweir aFStr += pType; 2202cdf0e10cSrcweir int nLen; 2203cdf0e10cSrcweir switch ( nPrintfParams ) 2204cdf0e10cSrcweir { 2205cdf0e10cSrcweir case SPECIAL_PARAM_NONE : 2206cdf0e10cSrcweir nLen = sprintf( buffer, aFStr.GetBuffer(), nUInt32 ); 2207cdf0e10cSrcweir break; 2208cdf0e10cSrcweir case SPECIAL_PARAM_WIDTH : 2209cdf0e10cSrcweir nLen = sprintf( buffer, aFStr.GetBuffer(), nWidth, nUInt32 ); 2210cdf0e10cSrcweir break; 2211cdf0e10cSrcweir case SPECIAL_PARAM_PRECISION : 2212cdf0e10cSrcweir nLen = sprintf( buffer, aFStr.GetBuffer(), nPrecision, nUInt32 ); 2213cdf0e10cSrcweir break; 2214cdf0e10cSrcweir default: 2215cdf0e10cSrcweir nLen=sprintf(buffer,aFStr.GetBuffer(),nWidth,nPrecision,nUInt32 ); 2216cdf0e10cSrcweir } 2217cdf0e10cSrcweir Write( buffer, (long)nLen ); 2218cdf0e10cSrcweir return *this; 2219cdf0e10cSrcweir } 2220cdf0e10cSrcweir 2221cdf0e10cSrcweir 2222cdf0e10cSrcweir SvStream& SvStream::WriteNumber( const double& rDouble ) 2223cdf0e10cSrcweir { 2224cdf0e10cSrcweir char buffer[256+24]; 2225cdf0e10cSrcweir ByteString aFStr( aFormatString); 2226cdf0e10cSrcweir aFStr += "lf"; 2227cdf0e10cSrcweir int nLen; 2228cdf0e10cSrcweir switch ( nPrintfParams ) 2229cdf0e10cSrcweir { 2230cdf0e10cSrcweir case SPECIAL_PARAM_NONE : 2231cdf0e10cSrcweir nLen = sprintf( buffer, aFStr.GetBuffer(), rDouble ); 2232cdf0e10cSrcweir break; 2233cdf0e10cSrcweir case SPECIAL_PARAM_WIDTH : 2234cdf0e10cSrcweir nLen = sprintf( buffer, aFStr.GetBuffer(), nWidth, rDouble ); 2235cdf0e10cSrcweir break; 2236cdf0e10cSrcweir case SPECIAL_PARAM_PRECISION : 2237cdf0e10cSrcweir nLen = sprintf( buffer, aFStr.GetBuffer(), nPrecision, rDouble); 2238cdf0e10cSrcweir break; 2239cdf0e10cSrcweir default: 2240cdf0e10cSrcweir nLen=sprintf(buffer, aFStr.GetBuffer(),nWidth,nPrecision,rDouble); 2241cdf0e10cSrcweir } 2242cdf0e10cSrcweir Write( buffer, (long)nLen ); 2243cdf0e10cSrcweir return *this; 2244cdf0e10cSrcweir } 2245cdf0e10cSrcweir 2246cdf0e10cSrcweir /************************************************************************* 2247cdf0e10cSrcweir |* 2248cdf0e10cSrcweir |* Stream::CryptAndWriteBuffer() 2249cdf0e10cSrcweir |* 2250cdf0e10cSrcweir |* Beschreibung Verschluesseln und Schreiben 2251cdf0e10cSrcweir |* Ersterstellung OV 08.06.94 2252cdf0e10cSrcweir |* Letzte Aenderung OV 08.06.94 2253cdf0e10cSrcweir |* 2254cdf0e10cSrcweir *************************************************************************/ 2255cdf0e10cSrcweir 2256cdf0e10cSrcweir #define CRYPT_BUFSIZE 1024 2257cdf0e10cSrcweir 2258cdf0e10cSrcweir sal_Size SvStream::CryptAndWriteBuffer( const void* pStart, sal_Size nLen) 2259cdf0e10cSrcweir { 2260cdf0e10cSrcweir unsigned char pTemp[CRYPT_BUFSIZE]; 2261cdf0e10cSrcweir unsigned char* pDataPtr = (unsigned char*)pStart; 2262cdf0e10cSrcweir sal_Size nCount = 0; 2263cdf0e10cSrcweir sal_Size nBufCount; 2264cdf0e10cSrcweir unsigned char nMask = nCryptMask; 2265cdf0e10cSrcweir do 2266cdf0e10cSrcweir { 2267cdf0e10cSrcweir if( nLen >= CRYPT_BUFSIZE ) 2268cdf0e10cSrcweir nBufCount = CRYPT_BUFSIZE; 2269cdf0e10cSrcweir else 2270cdf0e10cSrcweir nBufCount = nLen; 2271cdf0e10cSrcweir nLen -= nBufCount; 2272cdf0e10cSrcweir memcpy( pTemp, pDataPtr, (sal_uInt16)nBufCount ); 2273cdf0e10cSrcweir // **** Verschluesseln ***** 2274cdf0e10cSrcweir for ( sal_uInt16 n=0; n < CRYPT_BUFSIZE; n++ ) 2275cdf0e10cSrcweir { 2276cdf0e10cSrcweir unsigned char aCh = pTemp[n]; 2277cdf0e10cSrcweir aCh ^= nMask; 2278cdf0e10cSrcweir SWAPNIBBLES(aCh) 2279cdf0e10cSrcweir pTemp[n] = aCh; 2280cdf0e10cSrcweir } 2281cdf0e10cSrcweir // ************************* 2282cdf0e10cSrcweir nCount += PutData( (char*)pTemp, nBufCount ); 2283cdf0e10cSrcweir pDataPtr += nBufCount; 2284cdf0e10cSrcweir } 2285cdf0e10cSrcweir while ( nLen ); 2286cdf0e10cSrcweir return nCount; 2287cdf0e10cSrcweir } 2288cdf0e10cSrcweir 2289cdf0e10cSrcweir /************************************************************************* 2290cdf0e10cSrcweir |* 2291cdf0e10cSrcweir |* Stream::EncryptBuffer() 2292cdf0e10cSrcweir |* 2293cdf0e10cSrcweir |* Beschreibung Buffer entschluesseln 2294cdf0e10cSrcweir |* Ersterstellung OV 08.06.94 2295cdf0e10cSrcweir |* Letzte Aenderung OV 08.06.94 2296cdf0e10cSrcweir |* 2297cdf0e10cSrcweir *************************************************************************/ 2298cdf0e10cSrcweir 2299cdf0e10cSrcweir sal_Bool SvStream::EncryptBuffer(void* pStart, sal_Size nLen) 2300cdf0e10cSrcweir { 2301cdf0e10cSrcweir unsigned char* pTemp = (unsigned char*)pStart; 2302cdf0e10cSrcweir unsigned char nMask = nCryptMask; 2303cdf0e10cSrcweir 2304cdf0e10cSrcweir for ( sal_Size n=0; n < nLen; n++, pTemp++ ) 2305cdf0e10cSrcweir { 2306cdf0e10cSrcweir unsigned char aCh = *pTemp; 2307cdf0e10cSrcweir SWAPNIBBLES(aCh) 2308cdf0e10cSrcweir aCh ^= nMask; 2309cdf0e10cSrcweir *pTemp = aCh; 2310cdf0e10cSrcweir } 2311cdf0e10cSrcweir return sal_True; 2312cdf0e10cSrcweir } 2313cdf0e10cSrcweir 2314cdf0e10cSrcweir /************************************************************************* 2315cdf0e10cSrcweir |* 2316cdf0e10cSrcweir |* Stream::SetKey() 2317cdf0e10cSrcweir |* 2318cdf0e10cSrcweir |* Beschreibung STREAM.SDW 2319cdf0e10cSrcweir |* Ersterstellung OV 08.06.94 2320cdf0e10cSrcweir |* Letzte Aenderung OV 08.06.94 2321cdf0e10cSrcweir |* 2322cdf0e10cSrcweir *************************************************************************/ 2323cdf0e10cSrcweir 2324cdf0e10cSrcweir unsigned char implGetCryptMask(const sal_Char* pStr, sal_Int32 nLen, long nVersion) 2325cdf0e10cSrcweir { 2326cdf0e10cSrcweir unsigned char nCryptMask = 0; 2327cdf0e10cSrcweir 2328cdf0e10cSrcweir if (!nLen) 2329cdf0e10cSrcweir return nCryptMask; 2330cdf0e10cSrcweir 2331cdf0e10cSrcweir if( nVersion <= SOFFICE_FILEFORMAT_31 ) 2332cdf0e10cSrcweir { 2333cdf0e10cSrcweir while( nLen ) 2334cdf0e10cSrcweir { 2335cdf0e10cSrcweir nCryptMask ^= *pStr; 2336cdf0e10cSrcweir pStr++; 2337cdf0e10cSrcweir nLen--; 2338cdf0e10cSrcweir } 2339cdf0e10cSrcweir } 2340cdf0e10cSrcweir else // BugFix #25888# 2341cdf0e10cSrcweir { 2342cdf0e10cSrcweir for( sal_uInt16 i = 0; i < nLen; i++ ) { 2343cdf0e10cSrcweir nCryptMask ^= pStr[i]; 2344cdf0e10cSrcweir if( nCryptMask & 0x80 ) { 2345cdf0e10cSrcweir nCryptMask <<= 1; 2346cdf0e10cSrcweir nCryptMask++; 2347cdf0e10cSrcweir } 2348cdf0e10cSrcweir else 2349cdf0e10cSrcweir nCryptMask <<= 1; 2350cdf0e10cSrcweir } 2351cdf0e10cSrcweir } 2352cdf0e10cSrcweir 2353cdf0e10cSrcweir if( !nCryptMask ) 2354cdf0e10cSrcweir nCryptMask = 67; 2355cdf0e10cSrcweir 2356cdf0e10cSrcweir return nCryptMask; 2357cdf0e10cSrcweir } 2358cdf0e10cSrcweir 2359cdf0e10cSrcweir void SvStream::SetKey( const ByteString& rKey ) 2360cdf0e10cSrcweir { 2361cdf0e10cSrcweir aKey = rKey; 2362cdf0e10cSrcweir nCryptMask = implGetCryptMask( aKey.GetBuffer(), aKey.Len(), GetVersion() ); 2363cdf0e10cSrcweir } 2364cdf0e10cSrcweir 2365cdf0e10cSrcweir /************************************************************************* 2366cdf0e10cSrcweir |* 2367cdf0e10cSrcweir |* Stream::SyncSvStream() 2368cdf0e10cSrcweir |* 2369cdf0e10cSrcweir |* Beschreibung STREAM.SDW 2370cdf0e10cSrcweir |* Ersterstellung OV 08.06.94 2371cdf0e10cSrcweir |* Letzte Aenderung OV 08.06.94 2372cdf0e10cSrcweir |* 2373cdf0e10cSrcweir *************************************************************************/ 2374cdf0e10cSrcweir 2375cdf0e10cSrcweir void SvStream::SyncSvStream( sal_Size nNewStreamPos ) 2376cdf0e10cSrcweir { 2377cdf0e10cSrcweir ClearBuffer(); 2378cdf0e10cSrcweir SvStream::nBufFilePos = nNewStreamPos; 2379cdf0e10cSrcweir } 2380cdf0e10cSrcweir 2381cdf0e10cSrcweir /************************************************************************* 2382cdf0e10cSrcweir |* 2383cdf0e10cSrcweir |* Stream::SyncSysStream() 2384cdf0e10cSrcweir |* 2385cdf0e10cSrcweir |* Beschreibung STREAM.SDW 2386cdf0e10cSrcweir |* Ersterstellung OV 08.06.94 2387cdf0e10cSrcweir |* Letzte Aenderung OV 08.06.94 2388cdf0e10cSrcweir |* 2389cdf0e10cSrcweir *************************************************************************/ 2390cdf0e10cSrcweir 2391cdf0e10cSrcweir void SvStream::SyncSysStream() 2392cdf0e10cSrcweir { 2393cdf0e10cSrcweir Flush(); 2394cdf0e10cSrcweir SeekPos( Tell() ); 2395cdf0e10cSrcweir } 2396cdf0e10cSrcweir 2397cdf0e10cSrcweir /************************************************************************* 2398cdf0e10cSrcweir |* 2399cdf0e10cSrcweir |* Stream::SetStreamSize() 2400cdf0e10cSrcweir |* 2401cdf0e10cSrcweir |* Beschreibung STREAM.SDW 2402cdf0e10cSrcweir |* Ersterstellung OV 08.06.94 2403cdf0e10cSrcweir |* Letzte Aenderung OV 08.06.94 2404cdf0e10cSrcweir |* 2405cdf0e10cSrcweir *************************************************************************/ 2406cdf0e10cSrcweir 2407cdf0e10cSrcweir sal_Bool SvStream::SetStreamSize( sal_Size nSize ) 2408cdf0e10cSrcweir { 2409cdf0e10cSrcweir #ifdef DBG_UTIL 2410cdf0e10cSrcweir sal_Size nFPos = Tell(); 2411cdf0e10cSrcweir #endif 2412cdf0e10cSrcweir sal_uInt16 nBuf = nBufSize; 2413cdf0e10cSrcweir SetBufferSize( 0 ); 2414cdf0e10cSrcweir SetSize( nSize ); 2415cdf0e10cSrcweir SetBufferSize( nBuf ); 2416cdf0e10cSrcweir DBG_ASSERT(Tell()==nFPos,"SetStreamSize failed"); 2417cdf0e10cSrcweir return (sal_Bool)(nError == 0); 2418cdf0e10cSrcweir } 2419cdf0e10cSrcweir 2420cdf0e10cSrcweir //============================================================================ 2421cdf0e10cSrcweir 2422cdf0e10cSrcweir void SvStream::AddMark( sal_Size ) 2423cdf0e10cSrcweir { 2424cdf0e10cSrcweir } 2425cdf0e10cSrcweir 2426cdf0e10cSrcweir //============================================================================ 2427cdf0e10cSrcweir 2428cdf0e10cSrcweir void SvStream::RemoveMark( sal_Size ) 2429cdf0e10cSrcweir { 2430cdf0e10cSrcweir } 2431cdf0e10cSrcweir 2432cdf0e10cSrcweir /************************************************************************* 2433cdf0e10cSrcweir |* 2434cdf0e10cSrcweir |* endl() 2435cdf0e10cSrcweir |* 2436cdf0e10cSrcweir |* Beschreibung STREAM.SDW 2437cdf0e10cSrcweir |* Ersterstellung OV 08.06.94 2438cdf0e10cSrcweir |* Letzte Aenderung TH 13.11.96 2439cdf0e10cSrcweir |* 2440cdf0e10cSrcweir *************************************************************************/ 2441cdf0e10cSrcweir 2442cdf0e10cSrcweir SvStream& endl( SvStream& rStr ) 2443cdf0e10cSrcweir { 2444cdf0e10cSrcweir LineEnd eDelim = rStr.GetLineDelimiter(); 2445cdf0e10cSrcweir if ( eDelim == LINEEND_CR ) 2446cdf0e10cSrcweir rStr << _CR; 2447cdf0e10cSrcweir else if( eDelim == LINEEND_LF ) 2448cdf0e10cSrcweir rStr << _LF; 2449cdf0e10cSrcweir else 2450cdf0e10cSrcweir rStr << _CR << _LF; 2451cdf0e10cSrcweir return rStr; 2452cdf0e10cSrcweir } 2453cdf0e10cSrcweir 2454cdf0e10cSrcweir SvStream& endlu( SvStream& rStrm ) 2455cdf0e10cSrcweir { 2456cdf0e10cSrcweir switch ( rStrm.GetLineDelimiter() ) 2457cdf0e10cSrcweir { 2458cdf0e10cSrcweir case LINEEND_CR : 2459cdf0e10cSrcweir rStrm << sal_Unicode(_CR); 2460cdf0e10cSrcweir break; 2461cdf0e10cSrcweir case LINEEND_LF : 2462cdf0e10cSrcweir rStrm << sal_Unicode(_LF); 2463cdf0e10cSrcweir break; 2464cdf0e10cSrcweir default: 2465cdf0e10cSrcweir rStrm << sal_Unicode(_CR) << sal_Unicode(_LF); 2466cdf0e10cSrcweir } 2467cdf0e10cSrcweir return rStrm; 2468cdf0e10cSrcweir } 2469cdf0e10cSrcweir 2470cdf0e10cSrcweir SvStream& endlub( SvStream& rStrm ) 2471cdf0e10cSrcweir { 2472cdf0e10cSrcweir if ( rStrm.GetStreamCharSet() == RTL_TEXTENCODING_UNICODE ) 2473cdf0e10cSrcweir return endlu( rStrm ); 2474cdf0e10cSrcweir else 2475cdf0e10cSrcweir return endl( rStrm ); 2476cdf0e10cSrcweir } 2477cdf0e10cSrcweir 2478cdf0e10cSrcweir /************************************************************************* 2479cdf0e10cSrcweir |* 2480cdf0e10cSrcweir |* SvMemoryStream::SvMemoryStream() 2481cdf0e10cSrcweir |* 2482cdf0e10cSrcweir |* Beschreibung STREAM.SDW 2483cdf0e10cSrcweir |* Ersterstellung OV 20.06.94 2484cdf0e10cSrcweir |* Letzte Aenderung OV 20.06.94 2485cdf0e10cSrcweir |* 2486cdf0e10cSrcweir *************************************************************************/ 2487cdf0e10cSrcweir 2488cdf0e10cSrcweir SvMemoryStream::SvMemoryStream( void* pBuffer, sal_Size bufSize, 2489cdf0e10cSrcweir StreamMode eMode ) 2490cdf0e10cSrcweir { 2491cdf0e10cSrcweir if( eMode & STREAM_WRITE ) 2492cdf0e10cSrcweir bIsWritable = sal_True; 2493cdf0e10cSrcweir else 2494cdf0e10cSrcweir bIsWritable = sal_False; 2495cdf0e10cSrcweir nEndOfData = bufSize; 2496cdf0e10cSrcweir bOwnsData = sal_False; 2497cdf0e10cSrcweir pBuf = (sal_uInt8 *) pBuffer; 2498cdf0e10cSrcweir nResize = 0L; 2499cdf0e10cSrcweir nSize = bufSize; 2500cdf0e10cSrcweir nPos = 0L; 2501cdf0e10cSrcweir SetBufferSize( 0 ); 2502cdf0e10cSrcweir } 2503cdf0e10cSrcweir 2504cdf0e10cSrcweir /************************************************************************* 2505cdf0e10cSrcweir |* 2506cdf0e10cSrcweir |* SvMemoryStream::SvMemoryStream() 2507cdf0e10cSrcweir |* 2508cdf0e10cSrcweir |* Beschreibung STREAM.SDW 2509cdf0e10cSrcweir |* Ersterstellung OV 20.06.94 2510cdf0e10cSrcweir |* Letzte Aenderung OV 20.06.94 2511cdf0e10cSrcweir |* 2512cdf0e10cSrcweir *************************************************************************/ 2513cdf0e10cSrcweir 2514cdf0e10cSrcweir SvMemoryStream::SvMemoryStream( sal_Size nInitSize, sal_Size nResizeOffset ) 2515cdf0e10cSrcweir { 2516cdf0e10cSrcweir bIsWritable = sal_True; 2517cdf0e10cSrcweir bOwnsData = sal_True; 2518cdf0e10cSrcweir nEndOfData = 0L; 2519cdf0e10cSrcweir nResize = nResizeOffset; 2520cdf0e10cSrcweir nPos = 0; 2521cdf0e10cSrcweir pBuf = 0; 2522cdf0e10cSrcweir if( nResize != 0 && nResize < 16 ) 2523cdf0e10cSrcweir nResize = 16; 2524cdf0e10cSrcweir if( nInitSize && !AllocateMemory( nInitSize ) ) 2525cdf0e10cSrcweir { 2526cdf0e10cSrcweir SetError( SVSTREAM_OUTOFMEMORY ); 2527cdf0e10cSrcweir nSize = 0; 2528cdf0e10cSrcweir } 2529cdf0e10cSrcweir else 2530cdf0e10cSrcweir nSize = nInitSize; 2531cdf0e10cSrcweir SetBufferSize( 64 ); 2532cdf0e10cSrcweir } 2533cdf0e10cSrcweir 2534cdf0e10cSrcweir /************************************************************************* 2535cdf0e10cSrcweir |* 2536cdf0e10cSrcweir |* SvMemoryStream::~SvMemoryStream() 2537cdf0e10cSrcweir |* 2538cdf0e10cSrcweir |* Beschreibung STREAM.SDW 2539cdf0e10cSrcweir |* Ersterstellung OV 20.06.94 2540cdf0e10cSrcweir |* Letzte Aenderung OV 20.06.94 2541cdf0e10cSrcweir |* 2542cdf0e10cSrcweir *************************************************************************/ 2543cdf0e10cSrcweir 2544cdf0e10cSrcweir SvMemoryStream::~SvMemoryStream() 2545cdf0e10cSrcweir { 2546cdf0e10cSrcweir if( pBuf ) 2547cdf0e10cSrcweir { 2548cdf0e10cSrcweir if( bOwnsData ) 2549cdf0e10cSrcweir FreeMemory(); 2550cdf0e10cSrcweir else 2551cdf0e10cSrcweir Flush(); 2552cdf0e10cSrcweir } 2553cdf0e10cSrcweir } 2554cdf0e10cSrcweir 2555cdf0e10cSrcweir /************************************************************************* 2556cdf0e10cSrcweir |* 2557cdf0e10cSrcweir |* SvMemoryStream::IsA() 2558cdf0e10cSrcweir |* 2559cdf0e10cSrcweir |* Beschreibung STREAM.SDW 2560cdf0e10cSrcweir |* Ersterstellung OV 20.06.94 2561cdf0e10cSrcweir |* Letzte Aenderung OV 20.06.94 2562cdf0e10cSrcweir |* 2563cdf0e10cSrcweir *************************************************************************/ 2564cdf0e10cSrcweir 2565cdf0e10cSrcweir sal_uInt16 SvMemoryStream::IsA() const 2566cdf0e10cSrcweir { 2567cdf0e10cSrcweir return (sal_uInt16)ID_MEMORYSTREAM; 2568cdf0e10cSrcweir } 2569cdf0e10cSrcweir 2570cdf0e10cSrcweir /************************************************************************* 2571cdf0e10cSrcweir |* 2572cdf0e10cSrcweir |* SvMemoryStream::SetBuffer() 2573cdf0e10cSrcweir |* 2574cdf0e10cSrcweir |* Beschreibung STREAM.SDW 2575cdf0e10cSrcweir |* Ersterstellung OV 20.06.94 2576cdf0e10cSrcweir |* Letzte Aenderung OV 20.06.94 2577cdf0e10cSrcweir |* 2578cdf0e10cSrcweir *************************************************************************/ 2579cdf0e10cSrcweir 2580cdf0e10cSrcweir void* SvMemoryStream::SetBuffer( void* pNewBuf, sal_Size nCount, 2581cdf0e10cSrcweir sal_Bool bOwnsDat, sal_Size nEOF ) 2582cdf0e10cSrcweir { 2583cdf0e10cSrcweir void* pResult; 2584cdf0e10cSrcweir SetBufferSize( 0 ); // Buffering in der Basisklasse initialisieren 2585cdf0e10cSrcweir Seek( 0 ); 2586cdf0e10cSrcweir if( bOwnsData ) 2587cdf0e10cSrcweir { 2588cdf0e10cSrcweir pResult = 0; 2589cdf0e10cSrcweir if( pNewBuf != pBuf ) 2590cdf0e10cSrcweir FreeMemory(); 2591cdf0e10cSrcweir } 2592cdf0e10cSrcweir else 2593cdf0e10cSrcweir pResult = pBuf; 2594cdf0e10cSrcweir 2595cdf0e10cSrcweir pBuf = (sal_uInt8 *) pNewBuf; 2596cdf0e10cSrcweir nPos = 0; 2597cdf0e10cSrcweir nSize = nCount; 2598cdf0e10cSrcweir nResize = 0; 2599cdf0e10cSrcweir bOwnsData = bOwnsDat; 2600cdf0e10cSrcweir 2601cdf0e10cSrcweir if( nEOF > nCount ) 2602cdf0e10cSrcweir nEOF = nCount; 2603cdf0e10cSrcweir nEndOfData = nEOF; 2604cdf0e10cSrcweir 2605cdf0e10cSrcweir ResetError(); 2606cdf0e10cSrcweir 2607cdf0e10cSrcweir DBG_ASSERT( nEndOfData<STREAM_SEEK_TO_END,"Invalid EOF"); 2608cdf0e10cSrcweir return pResult; 2609cdf0e10cSrcweir } 2610cdf0e10cSrcweir 2611cdf0e10cSrcweir /************************************************************************* 2612cdf0e10cSrcweir |* 2613cdf0e10cSrcweir |* SvMemoryStream::GetData() 2614cdf0e10cSrcweir |* 2615cdf0e10cSrcweir |* Beschreibung STREAM.SDW 2616cdf0e10cSrcweir |* Ersterstellung OV 20.06.94 2617cdf0e10cSrcweir |* Letzte Aenderung OV 20.06.94 2618cdf0e10cSrcweir |* 2619cdf0e10cSrcweir *************************************************************************/ 2620cdf0e10cSrcweir 2621cdf0e10cSrcweir sal_Size SvMemoryStream::GetData( void* pData, sal_Size nCount ) 2622cdf0e10cSrcweir { 2623cdf0e10cSrcweir sal_Size nMaxCount = nEndOfData-nPos; 2624cdf0e10cSrcweir if( nCount > nMaxCount ) 2625cdf0e10cSrcweir nCount = nMaxCount; 2626cdf0e10cSrcweir memcpy( pData, pBuf+nPos, (size_t)nCount ); 2627cdf0e10cSrcweir nPos += nCount; 2628cdf0e10cSrcweir return nCount; 2629cdf0e10cSrcweir } 2630cdf0e10cSrcweir 2631cdf0e10cSrcweir /************************************************************************* 2632cdf0e10cSrcweir |* 2633cdf0e10cSrcweir |* SvMemoryStream::PutData() 2634cdf0e10cSrcweir |* 2635cdf0e10cSrcweir |* Beschreibung STREAM.SDW 2636cdf0e10cSrcweir |* Ersterstellung OV 20.06.94 2637cdf0e10cSrcweir |* Letzte Aenderung OV 20.06.94 2638cdf0e10cSrcweir |* 2639cdf0e10cSrcweir *************************************************************************/ 2640cdf0e10cSrcweir 2641cdf0e10cSrcweir sal_Size SvMemoryStream::PutData( const void* pData, sal_Size nCount ) 2642cdf0e10cSrcweir { 2643cdf0e10cSrcweir if( GetError() ) 2644cdf0e10cSrcweir return 0L; 2645cdf0e10cSrcweir 2646cdf0e10cSrcweir sal_Size nMaxCount = nSize-nPos; 2647cdf0e10cSrcweir 2648cdf0e10cSrcweir // auf Ueberlauf testen 2649cdf0e10cSrcweir if( nCount > nMaxCount ) 2650cdf0e10cSrcweir { 2651cdf0e10cSrcweir if( nResize == 0 ) 2652cdf0e10cSrcweir { 2653cdf0e10cSrcweir // soviel wie moeglich rueberschaufeln 2654cdf0e10cSrcweir nCount = nMaxCount; 2655cdf0e10cSrcweir SetError( SVSTREAM_OUTOFMEMORY ); 2656cdf0e10cSrcweir } 2657cdf0e10cSrcweir else 2658cdf0e10cSrcweir { 2659cdf0e10cSrcweir long nNewResize; 2660cdf0e10cSrcweir if( nSize && nSize > nResize ) 2661cdf0e10cSrcweir nNewResize = nSize; 2662cdf0e10cSrcweir else 2663cdf0e10cSrcweir nNewResize = nResize; 2664cdf0e10cSrcweir 2665cdf0e10cSrcweir if( (nCount-nMaxCount) < nResize ) 2666cdf0e10cSrcweir { 2667cdf0e10cSrcweir // fehlender Speicher ist kleiner als Resize-Offset, 2668cdf0e10cSrcweir // deshalb um Resize-Offset vergroessern 2669cdf0e10cSrcweir if( !ReAllocateMemory( nNewResize) ) 2670cdf0e10cSrcweir { 2671cdf0e10cSrcweir nCount = 0; 2672cdf0e10cSrcweir SetError( SVSTREAM_WRITE_ERROR ); 2673cdf0e10cSrcweir } 2674cdf0e10cSrcweir } 2675cdf0e10cSrcweir else 2676cdf0e10cSrcweir { 2677cdf0e10cSrcweir // fehlender Speicher ist groesser als Resize-Offset 2678cdf0e10cSrcweir // deshalb um Differenz+ResizeOffset vergroessern 2679cdf0e10cSrcweir if( !ReAllocateMemory( nCount-nMaxCount+nNewResize ) ) 2680cdf0e10cSrcweir { 2681cdf0e10cSrcweir nCount = 0; 2682cdf0e10cSrcweir SetError( SVSTREAM_WRITE_ERROR ); 2683cdf0e10cSrcweir } 2684cdf0e10cSrcweir } 2685cdf0e10cSrcweir } 2686cdf0e10cSrcweir } 2687cdf0e10cSrcweir DBG_ASSERT(pBuf,"Possibly Reallocate failed"); 2688cdf0e10cSrcweir memcpy( pBuf+nPos, pData, (size_t)nCount); 2689cdf0e10cSrcweir 2690cdf0e10cSrcweir nPos += nCount; 2691cdf0e10cSrcweir if( nPos > nEndOfData ) 2692cdf0e10cSrcweir nEndOfData = nPos; 2693cdf0e10cSrcweir return nCount; 2694cdf0e10cSrcweir } 2695cdf0e10cSrcweir 2696cdf0e10cSrcweir /************************************************************************* 2697cdf0e10cSrcweir |* 2698cdf0e10cSrcweir |* SvMemoryStream::SeekPos() 2699cdf0e10cSrcweir |* 2700cdf0e10cSrcweir |* Beschreibung STREAM.SDW 2701cdf0e10cSrcweir |* Ersterstellung OV 20.06.94 2702cdf0e10cSrcweir |* Letzte Aenderung OV 20.06.94 2703cdf0e10cSrcweir |* 2704cdf0e10cSrcweir *************************************************************************/ 2705cdf0e10cSrcweir 2706cdf0e10cSrcweir // nEndOfData: Erste Position im Stream, die nicht gelesen werden darf 2707cdf0e10cSrcweir // nSize: Groesse des allozierten Speichers 2708cdf0e10cSrcweir 2709cdf0e10cSrcweir sal_Size SvMemoryStream::SeekPos( sal_Size nNewPos ) 2710cdf0e10cSrcweir { 2711cdf0e10cSrcweir if( nNewPos < nEndOfData ) 2712cdf0e10cSrcweir nPos = nNewPos; 2713cdf0e10cSrcweir else if( nNewPos == STREAM_SEEK_TO_END ) 2714cdf0e10cSrcweir nPos = nEndOfData; 2715cdf0e10cSrcweir else 2716cdf0e10cSrcweir { 2717cdf0e10cSrcweir if( nNewPos >= nSize ) // muss Buffer vergroessert werden ? 2718cdf0e10cSrcweir { 2719cdf0e10cSrcweir if( nResize ) // ist vergroeseern erlaubt ? 2720cdf0e10cSrcweir { 2721cdf0e10cSrcweir long nDiff = (long)(nNewPos - nSize + 1); 2722cdf0e10cSrcweir nDiff += (long)nResize; 2723cdf0e10cSrcweir ReAllocateMemory( nDiff ); 2724cdf0e10cSrcweir nPos = nNewPos; 2725cdf0e10cSrcweir nEndOfData = nNewPos; 2726cdf0e10cSrcweir } 2727cdf0e10cSrcweir else // vergroessern ist nicht erlaubt -> ans Ende setzen 2728cdf0e10cSrcweir { 2729cdf0e10cSrcweir // SetError( SVSTREAM_OUTOFMEMORY ); 2730cdf0e10cSrcweir nPos = nEndOfData; 2731cdf0e10cSrcweir } 2732cdf0e10cSrcweir } 2733cdf0e10cSrcweir else // gueltigen Bereich innerhalb des Buffers vergroessern 2734cdf0e10cSrcweir { 2735cdf0e10cSrcweir nPos = nNewPos; 2736cdf0e10cSrcweir nEndOfData = nNewPos; 2737cdf0e10cSrcweir } 2738cdf0e10cSrcweir } 2739cdf0e10cSrcweir return nPos; 2740cdf0e10cSrcweir } 2741cdf0e10cSrcweir 2742cdf0e10cSrcweir /************************************************************************* 2743cdf0e10cSrcweir |* 2744cdf0e10cSrcweir |* SvMemoryStream::FlushData() 2745cdf0e10cSrcweir |* 2746cdf0e10cSrcweir |* Beschreibung STREAM.SDW 2747cdf0e10cSrcweir |* Ersterstellung OV 20.06.94 2748cdf0e10cSrcweir |* Letzte Aenderung OV 20.06.94 2749cdf0e10cSrcweir |* 2750cdf0e10cSrcweir *************************************************************************/ 2751cdf0e10cSrcweir 2752cdf0e10cSrcweir void SvMemoryStream::FlushData() 2753cdf0e10cSrcweir { 2754cdf0e10cSrcweir } 2755cdf0e10cSrcweir 2756cdf0e10cSrcweir /************************************************************************* 2757cdf0e10cSrcweir |* 2758cdf0e10cSrcweir |* SvMemoryStream::ResetError() 2759cdf0e10cSrcweir |* 2760cdf0e10cSrcweir |* Beschreibung STREAM.SDW 2761cdf0e10cSrcweir |* Ersterstellung OV 20.06.94 2762cdf0e10cSrcweir |* Letzte Aenderung OV 20.06.94 2763cdf0e10cSrcweir |* 2764cdf0e10cSrcweir *************************************************************************/ 2765cdf0e10cSrcweir 2766cdf0e10cSrcweir void SvMemoryStream::ResetError() 2767cdf0e10cSrcweir { 2768cdf0e10cSrcweir SvStream::ClearError(); 2769cdf0e10cSrcweir } 2770cdf0e10cSrcweir 2771cdf0e10cSrcweir /************************************************************************* 2772cdf0e10cSrcweir |* 2773cdf0e10cSrcweir |* SvMemoryStream::AllocateMemory() 2774cdf0e10cSrcweir |* 2775cdf0e10cSrcweir |* Beschreibung STREAM.SDW 2776cdf0e10cSrcweir |* Ersterstellung OV 20.06.94 2777cdf0e10cSrcweir |* Letzte Aenderung OV 20.06.94 2778cdf0e10cSrcweir |* 2779cdf0e10cSrcweir *************************************************************************/ 2780cdf0e10cSrcweir 2781cdf0e10cSrcweir sal_Bool SvMemoryStream::AllocateMemory( sal_Size nNewSize ) 2782cdf0e10cSrcweir { 2783cdf0e10cSrcweir pBuf = new sal_uInt8[nNewSize]; 2784cdf0e10cSrcweir return( pBuf != 0 ); 2785cdf0e10cSrcweir } 2786cdf0e10cSrcweir 2787cdf0e10cSrcweir /************************************************************************* 2788cdf0e10cSrcweir |* 2789cdf0e10cSrcweir |* SvMemoryStream::ReAllocateMemory() (Bozo-Algorithmus) 2790cdf0e10cSrcweir |* 2791cdf0e10cSrcweir |* Beschreibung STREAM.SDW 2792cdf0e10cSrcweir |* Ersterstellung OV 20.06.94 2793cdf0e10cSrcweir |* Letzte Aenderung OV 20.06.94 2794cdf0e10cSrcweir |* 2795cdf0e10cSrcweir *************************************************************************/ 2796cdf0e10cSrcweir 2797cdf0e10cSrcweir sal_Bool SvMemoryStream::ReAllocateMemory( long nDiff ) 2798cdf0e10cSrcweir { 2799cdf0e10cSrcweir sal_Bool bRetVal = sal_False; 2800cdf0e10cSrcweir long nTemp = (long)nSize; 2801cdf0e10cSrcweir nTemp += nDiff; 2802cdf0e10cSrcweir sal_Size nNewSize = (sal_Size)nTemp; 2803cdf0e10cSrcweir 2804cdf0e10cSrcweir if( nNewSize ) 2805cdf0e10cSrcweir { 2806cdf0e10cSrcweir sal_uInt8* pNewBuf = new sal_uInt8[nNewSize]; 2807cdf0e10cSrcweir 2808cdf0e10cSrcweir if( pNewBuf ) 2809cdf0e10cSrcweir { 2810cdf0e10cSrcweir bRetVal = sal_True; // Success! 2811cdf0e10cSrcweir if( nNewSize < nSize ) // Verkleinern ? 2812cdf0e10cSrcweir { 2813cdf0e10cSrcweir memcpy( pNewBuf, pBuf, (size_t)nNewSize ); 2814cdf0e10cSrcweir if( nPos > nNewSize ) 2815cdf0e10cSrcweir nPos = 0L; 2816cdf0e10cSrcweir if( nEndOfData >= nNewSize ) 2817cdf0e10cSrcweir nEndOfData = nNewSize-1L; 2818cdf0e10cSrcweir } 2819cdf0e10cSrcweir else 2820cdf0e10cSrcweir { 2821cdf0e10cSrcweir memcpy( pNewBuf, pBuf, (size_t)nSize ); 2822cdf0e10cSrcweir } 2823cdf0e10cSrcweir 2824cdf0e10cSrcweir FreeMemory(); 2825cdf0e10cSrcweir 2826cdf0e10cSrcweir pBuf = pNewBuf; 2827cdf0e10cSrcweir nSize = nNewSize; 2828cdf0e10cSrcweir } 2829cdf0e10cSrcweir } 2830cdf0e10cSrcweir else 2831cdf0e10cSrcweir { 2832cdf0e10cSrcweir bRetVal = sal_True; 2833cdf0e10cSrcweir FreeMemory(); 2834cdf0e10cSrcweir pBuf = 0; 2835cdf0e10cSrcweir nSize = 0; 2836cdf0e10cSrcweir nEndOfData = 0; 2837cdf0e10cSrcweir nPos = 0; 2838cdf0e10cSrcweir } 2839cdf0e10cSrcweir 2840cdf0e10cSrcweir return bRetVal; 2841cdf0e10cSrcweir } 2842cdf0e10cSrcweir 2843cdf0e10cSrcweir void SvMemoryStream::FreeMemory() 2844cdf0e10cSrcweir { 2845cdf0e10cSrcweir delete[] pBuf; 2846cdf0e10cSrcweir } 2847cdf0e10cSrcweir 2848cdf0e10cSrcweir /************************************************************************* 2849cdf0e10cSrcweir |* 2850cdf0e10cSrcweir |* SvMemoryStream::SwitchBuffer() 2851cdf0e10cSrcweir |* 2852cdf0e10cSrcweir |* Beschreibung STREAM.SDW 2853cdf0e10cSrcweir |* Ersterstellung OV 26.07.94 2854cdf0e10cSrcweir |* Letzte Aenderung OV 26.07.94 2855cdf0e10cSrcweir |* 2856cdf0e10cSrcweir *************************************************************************/ 2857cdf0e10cSrcweir 2858cdf0e10cSrcweir void* SvMemoryStream::SwitchBuffer( sal_Size nInitSize, sal_Size nResizeOffset) 2859cdf0e10cSrcweir { 2860cdf0e10cSrcweir Flush(); 2861cdf0e10cSrcweir if( !bOwnsData ) 2862cdf0e10cSrcweir return 0; 2863cdf0e10cSrcweir Seek( STREAM_SEEK_TO_BEGIN ); 2864cdf0e10cSrcweir 2865cdf0e10cSrcweir void* pRetVal = pBuf; 2866cdf0e10cSrcweir pBuf = 0; 2867cdf0e10cSrcweir nEndOfData = 0L; 2868cdf0e10cSrcweir nResize = nResizeOffset; 2869cdf0e10cSrcweir nPos = 0; 2870cdf0e10cSrcweir 2871cdf0e10cSrcweir if( nResize != 0 && nResize < 16 ) 2872cdf0e10cSrcweir nResize = 16; 2873cdf0e10cSrcweir 2874cdf0e10cSrcweir ResetError(); 2875cdf0e10cSrcweir 2876cdf0e10cSrcweir if( nInitSize && !AllocateMemory(nInitSize) ) 2877cdf0e10cSrcweir { 2878cdf0e10cSrcweir SetError( SVSTREAM_OUTOFMEMORY ); 2879cdf0e10cSrcweir nSize = 0; 2880cdf0e10cSrcweir } 2881cdf0e10cSrcweir else 2882cdf0e10cSrcweir nSize = nInitSize; 2883cdf0e10cSrcweir 2884cdf0e10cSrcweir SetBufferSize( 64 ); 2885cdf0e10cSrcweir return pRetVal; 2886cdf0e10cSrcweir } 2887cdf0e10cSrcweir 2888cdf0e10cSrcweir void SvMemoryStream::SetSize( sal_Size nNewSize ) 2889cdf0e10cSrcweir { 2890cdf0e10cSrcweir long nDiff = (long)nNewSize - (long)nSize; 2891cdf0e10cSrcweir ReAllocateMemory( nDiff ); 2892cdf0e10cSrcweir } 2893cdf0e10cSrcweir 2894cdf0e10cSrcweir TYPEINIT0 ( SvDataCopyStream ) 2895cdf0e10cSrcweir 2896cdf0e10cSrcweir void SvDataCopyStream::Assign( const SvDataCopyStream& ) 2897cdf0e10cSrcweir { 2898cdf0e10cSrcweir } 2899