21#include <config_options.h>
27#include <rtl/string.hxx>
28#include <rtl/strbuf.hxx>
37 if ( eEncoding == RTL_TEXTENCODING_ISO_8859_1 )
38 return RTL_TEXTENCODING_MS_1252;
72#define STREAM_SEEK_TO_BEGIN 0L
73#define STREAM_SEEK_TO_END SAL_MAX_UINT64
116 m_pStream(pTheStream), m_bOwner(bTheOwner), m_bSync(false) {}
125 virtual ErrCode ReadAt(sal_uInt64 nPos,
void * pBuffer, std::size_t nCount,
126 std::size_t * pRead)
const;
127 virtual ErrCode WriteAt(sal_uInt64 nPos,
const void * pBuffer, std::size_t nCount,
128 std::size_t * pWritten);
132 virtual ErrCode SetSize(sal_uInt64 nSize);
149 std::unique_ptr<sal_uInt8[]>
184 virtual std::size_t
GetData(
void* pData, std::size_t nSize );
185 virtual std::size_t
PutData(
const void* pData, std::size_t nSize );
186 virtual sal_uInt64 SeekPos( sal_uInt64 nPos );
187 virtual void FlushData();
188 virtual void SetSize(sal_uInt64 nSize);
190 SAL_DLLPRIVATE
void ClearError();
191 SAL_DLLPRIVATE
void ClearBuffer();
194 SAL_DLLPRIVATE std::size_t CryptAndWriteBuffer(
const void* pStart, std::size_t nLen );
195 SAL_DLLPRIVATE
void EncryptBuffer(
void* pStart, std::size_t nLen )
const;
207 virtual void ResetError();
215 { m_nCompressMode = nNewMode; }
218 void SetCryptMaskKey(
const OString& rCryptMaskKey);
221 { m_eStreamCharSet = eCharSet; }
225 { m_eLineDelimiter = eLineEnd; }
228 SvStream& ReadUInt16( sal_uInt16& rUInt16 );
229 SvStream& ReadUInt32( sal_uInt32& rUInt32 );
230 SvStream& ReadUInt64( sal_uInt64& rUInt64 );
231 SvStream& ReadInt16( sal_Int16& rInt16 );
232 SvStream& ReadInt32( sal_Int32& rInt32 );
233 SvStream& ReadInt64(sal_Int64 & rInt64);
234 SvStream& ReadSChar(
signed char& rChar );
236 SvStream& ReadUChar(
unsigned char& rChar );
238 SvStream& ReadCharAsBool(
bool& rBool );
239 SvStream& ReadFloat(
float& rFloat );
240 SvStream& ReadDouble(
double& rDouble );
243 SvStream& WriteUInt16( sal_uInt16 nUInt16 );
244 SvStream& WriteUInt32( sal_uInt32 nUInt32 );
245 SvStream& WriteUInt64( sal_uInt64 nuInt64 );
246 SvStream& WriteInt16( sal_Int16 nInt16 );
247 SvStream& WriteInt32( sal_Int32 nInt32 );
248 SvStream& WriteInt64( sal_Int64 nInt64 );
252 { WriteBytes(rStr.data(), rStr.size());
return *
this; }
254 sal_uInt64 WriteStream(
SvStream& rStream, sal_uInt64 nSize );
257 {
return WriteUChar(
static_cast<unsigned char>(b)); }
258 SvStream& WriteSChar(
signed char nChar );
260 SvStream& WriteUChar(
unsigned char nChar );
261 SvStream& WriteFloat(
float nFloat );
262 SvStream& WriteDouble(
const double& rDouble );
264 template <
typename N>
267 std::size_t ReadBytes(
void* pData, std::size_t nSize );
268 std::size_t WriteBytes(
const void* pData, std::size_t nSize );
269 sal_uInt64 Seek( sal_uInt64 nPos );
270 sal_uInt64 SeekRel( sal_Int64 nPos );
271 sal_uInt64
Tell()
const {
return m_nBufFilePos + m_nBufActualPos; }
272 virtual sal_uInt64 TellEnd();
274 sal_uInt64 remainingSize();
280 bool SetStreamSize( sal_uInt64 nSize );
296 bool ReadLine( OStringBuffer& rStr, sal_Int32 nMaxBytesToRead = 0xFFFE );
297 bool ReadLine( OString& rStr, sal_Int32 nMaxBytesToRead = 0xFFFE );
298 bool WriteLine( std::string_view rStr );
314 bool ReadByteStringLine( OUString& rStr, rtl_TextEncoding eSrcCharSet,
315 sal_Int32 nMaxBytesToRead = 0xFFFE );
316 bool WriteByteStringLine( std::u16string_view rStr, rtl_TextEncoding eDestCharSet );
319 void StartWritingUnicodeText();
330 void StartReadingUnicodeText( rtl_TextEncoding eReadBomCharSet );
338 SAL_DLLPRIVATE
bool ReadUniStringLine(OUString& rStr, sal_Int32 nMaxCodepointsToRead);
342 OUString ReadUniOrByteString(rtl_TextEncoding eSrcCharSet);
346 SvStream& WriteUniOrByteString( std::u16string_view rStr, rtl_TextEncoding eDestCharSet );
363 bool ReadUniOrByteStringLine( OUString& rStr, rtl_TextEncoding eSrcCharSet,
364 sal_Int32 nMaxCodepointsToRead = 0xFFFE );
368 bool WriteUnicodeOrByteText(std::u16string_view rStr, rtl_TextEncoding eDestCharSet );
370 {
return WriteUnicodeOrByteText( rStr, GetStreamCharSet() ); }
377 bool WriteUniOrByteChar(
sal_Unicode ch, rtl_TextEncoding eDestCharSet );
379 {
return WriteUniOrByteChar(
ch, GetStreamCharSet() ); }
381 void SetBufferSize( sal_uInt16 m_nBufSize );
384 void RefreshBuffer();
395 bool eof()
const {
return m_isEof; }
413 bool good()
const {
return !(eof() || bad()); }
416 template <
typename T>
SvStream& ReadNumber(T& r);
417 template <
typename T>
SvStream& WriteNumber(T n);
421 { readNumberWithoutSwap_(&rDataDest,
sizeof(rDataDest)); }
423 SAL_DLLPRIVATE
void readNumberWithoutSwap_(
void * pDataDest,
int nDataSize);
427 { writeNumberWithoutSwap_(&rDataSrc,
sizeof(rDataSrc)); }
429 SAL_DLLPRIVATE
void writeNumberWithoutSwap_(
const void * pDataSrc,
int nDataSize);
451 std::size_t nUnits, rtl_TextEncoding eEnc)
466 sal_uInt16 nUnits = 0;
473 sal_uInt32 nUnits = 0;
481 std::u16string_view rStr, std::size_t nUnits);
484 std::u16string_view rStr)
493 std::u16string_view rStr);
499 std::u16string_view rStr);
517 sal_uInt32 nUnits = 0;
523 sal_uInt16 nUnits = 0;
536 rtl_TextEncoding eEnc)
542 rtl_TextEncoding eEnc)
564 std::string_view rStr);
570 std::u16string_view rStr,
571 rtl_TextEncoding eEnc)
589 void* mxFileHandle =
nullptr;
591 sal_uInt16 nLockCounter;
602 virtual std::size_t
GetData(
void* pData, std::size_t nSize )
override;
603 virtual std::size_t
PutData(
const void* pData, std::size_t nSize )
override;
604 virtual sal_uInt64 SeekPos( sal_uInt64 nPos )
override;
605 virtual void SetSize( sal_uInt64 nSize )
override;
606 virtual void FlushData()
override;
614 virtual void ResetError()
override;
638 virtual std::size_t
GetData(
void* pData, std::size_t nSize )
override;
639 virtual std::size_t
PutData(
const void* pData, std::size_t nSize )
override;
640 virtual sal_uInt64 SeekPos( sal_uInt64 nPos )
override;
641 virtual void SetSize( sal_uInt64 nSize )
override;
642 virtual void FlushData()
override;
646 void AllocateMemory( std::size_t nSize );
662 SvMemoryStream( std::size_t nInitSize=512, std::size_t nResize=64 );
665 virtual void ResetError()
override;
669 const void*
GetData() { FlushBuffer();
return pBuf; }
672 void* SwitchBuffer();
674 void SetBuffer(
void* pBuf, std::size_t nSize, std::size_t nEOF );
682 virtual sal_uInt64
TellEnd()
override { FlushBuffer();
return nEndOfData; }
ErrCode IgnoreWarning() const
const OUString & GetFileName() const
SvFileStream(const SvFileStream &)=delete
void SetSynchronMode(bool bTheSync=true)
SvLockBytes(SvStream *pTheStream, bool bTheOwner=false)
bool IsSynchronMode() const
const SvStream * GetStream() const
virtual ~SvLockBytes() override
std::size_t GetEndOfData() const
SvMemoryStream(const SvMemoryStream &)=delete
virtual sal_uInt64 TellEnd() override
void SetResizeOffset(std::size_t nNewResize)
void ObjectOwnsMemory(bool bOwn)
Classes that want to be referenced-counted via SvRef<T>, should extend this base class.
SvRefBase & operator=(const SvRefBase &)
void SetCompressMode(SvStreamCompressFlags nNewMode)
SvStream(const SvStream &rStream)=delete
bool good() const
Get state.
sal_uInt16 m_nBufFree
number of free slots in buffer to IO of type eIOMode
SvStream & WriteNumberAsString(N n)
void readNumberWithoutSwap(T &rDataDest)
bool WriteUniOrByteChar(sal_Unicode ch)
SvStream & operator=(const SvStream &rStream)=delete
SvLockBytesRef m_xLockBytes
Default implementation.
sal_uInt8 * m_pBufPos
m_pRWBuf + m_nBufActualPos
sal_uInt16 m_nBufActualPos
current position in buffer (0..m_nBufSize-1)
sal_uInt16 GetBufferSize() const
SvStreamCompressFlags GetCompressMode() const
LineEnd GetLineDelimiter() const
std::size_t WriteBytes(const void *pData, std::size_t nSize)
bool IsEndianSwap() const
returns status of endian swap flag
SvStream & WriteBool(bool b)
bool eof() const
end of input seen during previous i/o operation
bool bad() const
stream is broken
void SetLineDelimiter(LineEnd eLineEnd)
sal_uInt64 m_nBufFilePos
File position of pBuf[0].
SvStream & WriteOString(std::string_view rStr)
rtl_TextEncoding m_eStreamCharSet
std::unique_ptr< sal_uInt8[]> m_pRWBuf
Points to read/write buffer.
unsigned char m_nCryptMask
sal_Int32 GetVersion() const
bool m_isDirty
true: Stream != buffer content
StreamMode GetStreamMode() const
SvStream & ReadUInt32(sal_uInt32 &rUInt32)
sal_uInt16 m_nBufActualLen
Length of used segment of buffer.
void writeNumberWithoutSwap(T const &rDataSrc)
void SetVersion(sal_Int32 n)
SvLockBytes * GetLockBytes() const
bool WriteUnicodeOrByteText(std::u16string_view rStr)
void SetStreamCharSet(rtl_TextEncoding eCharSet)
rtl_TextEncoding GetStreamCharSet() const
SvStreamCompressFlags m_nCompressMode
SvStream & ReadUInt16(sal_uInt16 &rUInt16)
ErrCode const & GetErrorCode() const
sal_uInt16 m_nBufSize
Allocated size of buffer.
SvStream & ReadUChar(unsigned char &rChar)
GtkMediaStream * m_pStream
class SAL_WARN_UNUSED UNLESS_MERGELIBS(TOOLS_DLLPUBLIC) INetMIMEMessage
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
std::size_t write_uInt16_lenPrefixed_uInt16s_FromOUString(SvStream &rStrm, std::u16string_view rStr)
TOOLS_DLLPUBLIC OString read_uInt8s_ToOString(SvStream &rStrm, std::size_t nUnits)
Attempt to read nUnits 8bit units to an OString, returned OString's length is number of units success...
OString read_uInt16_lenPrefixed_uInt8s_ToOString(SvStream &rStrm)
TOOLS_DLLPUBLIC SvStream & endlub(SvStream &rStr)
call endlu() if m_eStreamCharSet==RTL_TEXTECODING_UNICODE otherwise endl()
OUString read_uInt8_lenPrefixed_uInt8s_ToOUString(SvStream &rStrm, rtl_TextEncoding eEnc)
OUString read_uInt16_lenPrefixed_uInt8s_ToOUString(SvStream &rStrm, rtl_TextEncoding eEnc)
UNLESS_MERGELIBS(TOOLS_DLLPUBLIC) std TOOLS_DLLPUBLIC OString read_zeroTerminated_uInt8s_ToOString(SvStream &rStrm)
Attempt to write a pascal-style length (of type prefix) prefixed sequence of 16bit units from an OUSt...
TOOLS_DLLPUBLIC OUString read_uInt16s_ToOUString(SvStream &rStrm, std::size_t nUnits)
Attempt to read nUnits 16bit units to an OUString, returned OUString's length is number of units succ...
SvStream & operator<<(SvStream &rStr, SvStrPtr f)
@ READ
allow read accesses
@ COPY_ON_SYMLINK
copy-on-write for symlinks (Unix-only)
@ TEMPORARY
temporary file attribute (Windows-only)
@ TRUNC
Truncate existing file to zero length.
@ NOCREATE
1 == Don't create file
@ DELETE_ON_CLOSE
only for temporary files (Windows-only)
OUString read_uInt16_lenPrefixed_uInt16s_ToOUString(SvStream &rStrm)
Attempt to read a pascal-style length (of type prefix) prefixed sequence of 16bit units to an OUStrin...
SvStream &(* SvStrPtr)(SvStream &)
rtl_TextEncoding GetStoreCharSet(rtl_TextEncoding eEncoding)
TOOLS_DLLPUBLIC OUString read_zeroTerminated_uInt8s_ToOUString(SvStream &rStrm, rtl_TextEncoding eEnc)
Attempt to read 8bit units assuming source encoding eEnc to an OUString until a zero terminator is en...
OString read_uInt8_lenPrefixed_uInt8s_ToOString(SvStream &rStrm)
OUString read_uInt32_lenPrefixed_uInt16s_ToOUString(SvStream &rStrm)
std::size_t write_uInt8s_FromOString(SvStream &rStrm, std::string_view rStr, std::size_t nUnits)
Attempt to write a prefixed sequence of nUnits 8bit units from an OString, returned value is number o...
OString read_uInt32_lenPrefixed_uInt8s_ToOString(SvStream &rStrm)
Attempt to read a pascal-style length (of type prefix) prefixed sequence of 8bit units to an OString,...
tools::SvRef< SvLockBytes > SvLockBytesRef
TOOLS_DLLPUBLIC SvStream & endl(SvStream &rStr)
TOOLS_DLLPUBLIC std::size_t write_uInt16s_FromOUString(SvStream &rStrm, std::u16string_view rStr, std::size_t nUnits)
Attempt to write a prefixed sequence of nUnits 16bit units from an OUString, returned value is number...
OUString read_uInt8s_ToOUString(SvStream &rStrm, std::size_t nUnits, rtl_TextEncoding eEnc)
Attempt to read nUnits 8bit units to an OUString.
TOOLS_DLLPUBLIC std::size_t write_uInt16_lenPrefixed_uInt8s_FromOString(SvStream &rStrm, std::string_view rStr)
Attempt to write a pascal-style length (of type prefix) prefixed sequence of units from a string-type...
std::size_t write_uInt16_lenPrefixed_uInt8s_FromOUString(SvStream &rStrm, std::u16string_view rStr, rtl_TextEncoding eEnc)
Attempt to write a pascal-style length (of type prefix) prefixed sequence of 8bit units from an OUStr...
TOOLS_DLLPUBLIC bool checkSeek(SvStream &rSt, sal_uInt64 nOffset)
std::size_t write_uInt32_lenPrefixed_uInt16s_FromOUString(SvStream &rStrm, std::u16string_view rStr)
Attempt to write a pascal-style length (of type prefix) prefixed sequence of 16bit units from an OUSt...
TOOLS_DLLPUBLIC SvStream & endlu(SvStream &rStr)
same as endl() but Unicode
UcbLockBytesRef m_xLockBytes