22#include <com/sun/star/io/XInputStream.hpp>
23#include <com/sun/star/io/XSeekable.hpp>
27#include <rtl/ustrbuf.hxx>
28#include <osl/diagnose.h>
38const sal_Int32 INPUTSTREAM_BUFFERSIZE = 0x8000;
48 if (
mbEof || (nChar == 0) )
break;
51 return aBuffer.makeStringAndClear();
59 ::std::vector< sal_uInt8 >
aBuffer;
64 aBuffer.resize(
static_cast< size_t >( nCharsRead ) );
68 return OString(
reinterpret_cast<char*
>(
aBuffer.data()), nCharsRead);
73 return OStringToOUString(
readCharArray( nChars ), eTextEnc );
81 ::std::vector< sal_uInt16 >
aBuffer;
86 aBuffer.resize(
static_cast< size_t >( nCharsRead ) );
88 ::std::replace(
aBuffer.begin(),
aBuffer.begin() + nCharsRead,
'\0',
'?' );
90 OUStringBuffer aStringBuffer;
91 aStringBuffer.ensureCapacity( nCharsRead );
92 for (
auto const& elem :
aBuffer)
93 aStringBuffer.append(
static_cast< sal_Unicode >(elem) );
94 return aStringBuffer.makeStringAndClear();
108 sal_Int32 nBufferSize = INPUTSTREAM_BUFFERSIZE;
112 sal_Int32 nReadSize = getLimitedValue< sal_Int32, sal_Int64 >( nBytes, 0, nBufferSize );
115 if( nReadSize == nBytesRead )
125 maBuffer( INPUTSTREAM_BUFFERSIZE ),
126 mxInStrm( rxInStrm ),
127 mbAutoClose( bAutoClose && rxInStrm.is() )
146 OSL_FAIL(
"BinaryXInputStream::close - closing input stream failed" );
156 if( !
mbEof && (nBytes > 0) )
try
158 nRet =
mxInStrm->readBytes( orData, nBytes );
159 mbEof = nRet != nBytes;
171 if( !
mbEof && (nBytes > 0) )
173 sal_Int32 nBufferSize = getLimitedValue< sal_Int32, sal_Int32 >( nBytes, 0, INPUTSTREAM_BUFFERSIZE );
175 while( !
mbEof && (nBytes > 0) )
177 sal_Int32 nReadSize = getLimitedValue< sal_Int32, sal_Int32 >( nBytes, 0, nBufferSize );
180 memcpy( opnMem,
maBuffer.getConstArray(),
static_cast< size_t >( nBytesRead ) );
181 opnMem += nBytesRead;
182 nBytes -= nBytesRead;
209 sal_Int32 nReadBytes = 0;
213 orData.realloc( nReadBytes );
215 memcpy( orData.getArray(),
mpData->getConstArray() +
mnPos,
static_cast< size_t >( nReadBytes ) );
217 mbEof = nReadBytes < nBytes;
224 sal_Int32 nReadBytes = 0;
229 memcpy( opMem,
mpData->getConstArray() +
mnPos,
static_cast< size_t >( nReadBytes ) );
231 mbEof = nReadBytes < nBytes;
242 mbEof = nSkipBytes < nBytes;
248 mpInStrm( &rInStrm ),
249 mnStartPos( rInStrm.tell() ),
253 mnSize = (nRemaining >= 0) ? ::std::min( nSize, nRemaining ) : nSize;
285 sal_Int32 nReadBytes = 0;
298 sal_Int32 nReadBytes = 0;
316 mbEof = nSkipBytes < nBytes;
Interface for binary output stream classes.
virtual void writeData(const StreamDataSequence &rData, size_t nAtomSize=1)=0
Derived classes implement writing the contents of the passed data sequence.
Base class for binary stream classes.
bool isSeekable() const
Returns true, if the implementation supports the seek() operation.
sal_Int64 getRemaining() const
Returns the size of the remaining data available in the stream, if stream supports size() and tell(),...
bool isEof() const
Returns true, if the stream position is invalid (EOF).
virtual void seek(sal_Int64 nPos)=0
Implementations seek the stream to the passed position, if the stream is seekable.
bool mbEof
End of stream flag.
Base class for binary input and output streams wrapping a UNO stream, seekable via the com....
virtual void close() override
Releases the reference to the UNO XSeekable interface.
Base class for binary input and output streams wrapping a StreamDataSequence, which is always seekabl...
sal_Int32 mnPos
Current position in the sequence.
const StreamDataSequence * mpData
Wrapped data sequence.
css::uno::Sequence< sal_Int8 > StreamDataSequence
std::unique_ptr< char[]> aBuffer