22#include <com/sun/star/io/NotConnectedException.hpp>
23#include <com/sun/star/io/TextInputStream.hpp>
25#include <osl/diagnose.h>
26#include <rtl/tencinfo.h>
39class UnoBinaryInputStream :
public ::cppu::WeakImplHelper< XInputStream >
42 explicit UnoBinaryInputStream( BinaryInputStream& rInStrm );
44 virtual sal_Int32 SAL_CALL readBytes(
Sequence< sal_Int8 >& rData, sal_Int32 nBytesToRead )
override;
45 virtual sal_Int32 SAL_CALL readSomeBytes(
Sequence< sal_Int8 >& rData, sal_Int32 nMaxBytesToRead )
override;
46 virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip )
override;
47 virtual sal_Int32 SAL_CALL available()
override;
48 virtual void SAL_CALL closeInput()
override;
52 void ensureConnected()
const;
55 BinaryInputStream* mpInStrm;
58UnoBinaryInputStream::UnoBinaryInputStream( BinaryInputStream& rInStrm ) :
63sal_Int32 SAL_CALL UnoBinaryInputStream::readBytes(
Sequence< sal_Int8 >& rData, sal_Int32 nBytesToRead )
66 return mpInStrm->readData( rData, nBytesToRead );
69sal_Int32 SAL_CALL UnoBinaryInputStream::readSomeBytes(
Sequence< sal_Int8 >& rData, sal_Int32 nMaxBytesToRead )
72 return mpInStrm->readData( rData, nMaxBytesToRead );
75void SAL_CALL UnoBinaryInputStream::skipBytes( sal_Int32 nBytesToSkip )
78 mpInStrm->skip( nBytesToSkip );
81sal_Int32 SAL_CALL UnoBinaryInputStream::available()
84 throw RuntimeException(
"Functionality not supported", Reference< XInputStream >() );
87void SAL_CALL UnoBinaryInputStream::closeInput()
94void UnoBinaryInputStream::ensureConnected()
const
97 throw NotConnectedException(
"Stream closed" );
102TextInputStream::TextInputStream(
const Reference< XComponentContext >& rxContext,
const Reference< XInputStream >& rxInStrm, rtl_TextEncoding eTextEnc )
104 init( rxContext, rxInStrm, eTextEnc );
107TextInputStream::TextInputStream(
const Reference< XComponentContext >& rxContext, BinaryInputStream& rInStrm, rtl_TextEncoding eTextEnc )
109 init( rxContext,
new UnoBinaryInputStream( rInStrm ), eTextEnc );
112TextInputStream::~TextInputStream()
116bool TextInputStream::isEof()
const
118 if( mxTextStrm.is() )
try
120 return mxTextStrm->isEOF();
128OUString TextInputStream::readLine()
130 if( mxTextStrm.is() )
try
134 return createFinalString( mxTextStrm->readLine() );
143OUString TextInputStream::readToChar(
sal_Unicode cChar,
bool bIncludeChar )
145 if( mxTextStrm.is() )
try
147 Sequence< sal_Unicode > aDelimiters{ cChar };
154 OUString aString = createFinalString( mxTextStrm->readString( aDelimiters,
false ) );
156 if( !bIncludeChar && !aString.isEmpty() && (aString[ aString.getLength() - 1 ] == cChar) )
158 mcPendingChar = cChar;
159 aString = aString.copy( 0, aString.getLength() - 1 );
170Reference< XTextInputStream2 > TextInputStream::createXTextInputStream(
171 const Reference< XComponentContext >& rxContext,
const Reference< XInputStream >& rxInStrm, rtl_TextEncoding eTextEnc )
173 Reference< XTextInputStream2 > xTextStrm;
174 const char* pcCharset = rtl_getBestMimeCharsetFromTextEncoding( eTextEnc );
175 OSL_ENSURE( pcCharset,
"TextInputStream::createXTextInputStream - unsupported text encoding" );
176 if( rxContext.is() && rxInStrm.is() && pcCharset )
try
178 xTextStrm = css::io::TextInputStream::create( rxContext );
179 xTextStrm->setInputStream( rxInStrm );
180 xTextStrm->setEncoding( OUString::createFromAscii( pcCharset ) );
190OUString TextInputStream::createFinalString(
const OUString& rString )
192 if( mcPendingChar == 0 )
195 OUString aString = OUStringChar( mcPendingChar ) + rString;
200void TextInputStream::init(
const Reference< XComponentContext >& rxContext,
const Reference< XInputStream >& rxInStrm, rtl_TextEncoding eTextEnc )
203 mxTextStrm = createXTextInputStream( rxContext, rxInStrm, eTextEnc );
FILE * init(int, char **)