DCL 3.7.4
Loading...
Searching...
No Matches
InputStreamReader Class Reference

#include <InputStreamReader.h>

Inheritance diagram for InputStreamReader:
Reader Object FileReader

Public Member Functions

virtual String toString () const
 InputStreamReader (InputStream &__noclose__ _input, CharsetDecoder &_decoder)
 InputStreamReader (InputStream *__destroy__ _pInput, CharsetDecoder *__destroy__ _pDecoder=NULL) __DCL_THROWS1(IOException *)
virtual ~InputStreamReader ()
virtual void close () __DCL_THROWS1(IOException *)
virtual size_t read (wchar_t *_buf, size_t _n) __DCL_THROWS1(IOException *)
Public Member Functions inherited from Object
virtual void destroy ()
String className () const
bool isInstanceOf (const std::type_info &typeinfo) const
virtual const std::type_info & typeInfo () const

Protected Attributes

InputStream__input
CharsetDecoder__decoder
bool __closeDestroy

Additional Inherited Members

Protected Member Functions inherited from Object
virtual ~Object ()
 Object ()

Detailed Description

Definition at line 25 of file InputStreamReader.h.

Constructor & Destructor Documentation

◆ InputStreamReader() [1/2]

InputStreamReader::InputStreamReader ( InputStream &__noclose__ _input,
CharsetDecoder & _decoder )

참조된 스트림과 디코더로 객체를 구성한다. _input과 _decoder는 객체의 생명주기동안 유효해야 하며, _input은 close()에서 close하지 않는다.

Parameters
_inputA InputStream
_decoderA CharsetDecoder

Definition at line 46 of file InputStreamReader.cpp.

50{
51 __input = &_input;
52 __decoder = &_decoder;
53 __closeDestroy = false;
54 __extraBytes = 0;
55}
CharsetDecoder * __decoder
InputStream * __input

◆ InputStreamReader() [2/2]

InputStreamReader::InputStreamReader ( InputStream *__destroy__ _pInput,
CharsetDecoder *__destroy__ _pDecoder = NULL )

넘겨받은 스트림과 디코더로 객체를 구성한다. close()에서 _pInput의 close()가 호출되고 pInput과 _pDecoder는 파괴된다.

Parameters
_pInputA InputStream
_pDecoderNULL이면 처음 읽는 2~4바이트를 사용하여 BOM을 검사 한 후, 확인이 안되면 LocaleEncoder를 사용한다.

Definition at line 57 of file InputStreamReader.cpp.

61{
62 __DCL_ASSERT_PARAM(_pInput != NULL);
63
64 __input = _pInput;
65 __decoder = _pDecoder;
66 __closeDestroy = true;
67 __extraBytes = 0;
68}
#define NULL
Definition Config.h:312
#define __DCL_ASSERT_PARAM(expr)
Definition Object.h:409

◆ ~InputStreamReader()

InputStreamReader::~InputStreamReader ( )
virtual

객체의 파괴를 수행한다. close하지 않았으면 close()하며 예외가 발생하면 무시한다.

Definition at line 70 of file InputStreamReader.cpp.

71{
72 if (__input) {
73 try {
74 close();
75 }
76 catch (Exception* e) {
77 __DCL_TRACE1(L"%ls\n", e->toString().data());
78 e->destroy();
79 }
80 }
81}
#define __DCL_TRACE1(fmt, arg1)
Definition Object.h:399
virtual String toString() const
Definition Exception.cpp:40
virtual void destroy()
Definition Exception.cpp:74
virtual void close() __DCL_THROWS1(IOException *)

Member Function Documentation

◆ close()

void InputStreamReader::close ( )
virtual

객체를 닫는다. 넘겨받은 InputStream과 CharsetDecoder는 파괴된다.

Definition at line 83 of file InputStreamReader.cpp.

85{
87
88 Exception* e = NULL;
89 InputStream* input = __input;
90 CharsetDecoder* decoder = __decoder;
91 __input = NULL;
93 __extraBytes = 0;
94
95 if (__closeDestroy) {
96 if (decoder)
97 decoder->destroy();
98
99 try {
100 input->close();
101 }
102 catch (Exception* cause) {
103 e = cause;
104 }
105 input->destroy();
106 }
107
108 if (e)
109 throw e;
110}
#define __DCL_ASSERT_HANDLE(expr)
Definition Object.h:408
virtual void destroy()
Definition Object.cpp:192

◆ read()

size_t InputStreamReader::read ( wchar_t * _buf,
size_t _n )
virtual

텍스트를 읽는다.

Parameters
_buf버퍼
_n_buf의 길이, _buf가 가리키는 버퍼의 wchar_t의 개수

Implements Reader.

Definition at line 112 of file InputStreamReader.cpp.

114{
116 __DCL_ASSERT_PARAM(_buf != NULL);
117
118 if (!_n)
119 return 0;
120
121 if (!__decoder) {
122 char bom[4];
123 if (__input->available() >= sizeof(bom)) {
124 size_t readCount = __input->read(bom, sizeof(bom));
125 if ((readCount == 4) && IS_UTF32(bom))
126 __decoder = new UTF32Decoder();
127 else if ((readCount >= 3) && IS_UTF8(bom))
128 __decoder = new UTF8Decoder();
129 else if ((readCount >= 2) && IS_UTF16(bom))
130 __decoder = new UTF16Decoder();
131
132 memcpy(__extra, bom, readCount);
133 __extraBytes = readCount;
134 }
135
136 if (!__decoder)
137 __decoder = new LocaleDecoder();
138 }
139
140 wchar_t* outCur = _buf;
141 wchar_t* outEnd = _buf + _n;
142
143#define __BUFFER_SIZE__ 1024
145 size_t extraCount = __extraBytes;
146
147 // Non-Block이 가능한 양 만큼
148 size_t availCount = __input->available();
149 memcpy(inBuf, __extra, extraCount);
150
151 size_t outCount;
152 while ((outCount = outEnd - outCur) && availCount) {
153 size_t readCount = __MIN(__MAX(outCount, __EXTRA_MAX), availCount, __BUFFER_SIZE__);
154 readCount = __input->read(inBuf + extraCount, readCount);
155 availCount -= readCount;
156
157 size_t inCount = readCount + extraCount;
158 if (!inCount)
159 break;
160
161 size_t inCountSave = inCount;
162 int r = __decoder->decode(inBuf, inCount, outCur, outCount);
163 /*__DCL_TRACE4(__T("%ls read[%d], extra[%d], out[%d]\n"),
164 __decoder->className(), readCount, extraCount, outCount);*/
165 extraCount = inCountSave - inCount;
166 switch (r) {
167 case CS_SOURCE_FEW: {
168 __DCL_ASSERT(extraCount <= __EXTRA_MAX);
169 if (inCount > 0)
170 memmove(inBuf, inBuf + inCount, extraCount);
171 break;
172 }
173 case CS_NOERROR: {
174 __DCL_ASSERT(extraCount == 0);
175 break;
176 }
177 default: {
178 throw(new IOException(toString(), new CharsetConvertException(r)));
179 }
180 }
181 outCur += outCount;
182 }
183
184 // 이곳에서 Block 될 수 있다.
185 if ((outCount = outEnd - outCur) > 0) {
186 size_t readCount = __MIN(__MAX(outCount, __EXTRA_MAX), __BUFFER_SIZE__);
187 readCount = __input->read(inBuf + extraCount, readCount);
188 size_t inCount = readCount + extraCount;
189
190 if (inCount) {
191 size_t inCountSave = inCount;
192 int r = __decoder->decode(inBuf, inCount, outCur, outCount);
193 /*__DCL_TRACE4(__T("%ls read[%d], extra[%d], out[%d]\n"),
194 __decoder->className(), readCount, extraCount, outCount);*/
195 extraCount = inCountSave - inCount;
196 switch (r) {
197 case CS_SOURCE_FEW: {
198 __DCL_ASSERT(extraCount <= __EXTRA_MAX);
199 if (inCount > 0)
200 memmove(inBuf, inBuf + inCount, extraCount);
201 break;
202 }
203 case CS_NOERROR: {
204 __DCL_ASSERT(extraCount == 0);
205 break;
206 }
207 default: {
208 throw(new IOException(className(), new CharsetConvertException(r)));
209 }
210 }
211 outCur += outCount;
212 }
213 }
214
215 memcpy(__extra, inBuf, extraCount);
216 __extraBytes = extraCount;
217
218 return outCur - _buf;
219}
#define IS_UTF16(bom)
Definition Charset.h:41
#define IS_UTF8(bom)
Definition Charset.h:37
#define IS_UTF32(bom)
Definition Charset.h:46
@ CS_SOURCE_FEW
Definition Charset.h:70
@ CS_NOERROR
Definition Charset.h:66
unsigned char byte_t
Definition Config.h:246
#define __BUFFER_SIZE__
#define __EXTRA_MAX
IOException *size_t r
Definition MediaInfo.cpp:82
#define __DCL_ASSERT(expr)
Definition Object.h:394
virtual String toString() const
String className() const
Definition Object.cpp:163
size_t __MAX(size_t x, size_t y)
Definition size_t.h:43
size_t __MIN(size_t x, size_t y)
Definition size_t.h:27

◆ toString()

virtual String InputStreamReader::toString ( ) const
virtual

파생클래스를 위한 생성자이다. 객체의 구성에 대하여 간략한 요약을 리턴한다.

Reimplemented from Object.

Member Data Documentation

◆ __closeDestroy

bool InputStreamReader::__closeDestroy
protected

Definition at line 95 of file InputStreamReader.h.

◆ __decoder

CharsetDecoder* InputStreamReader::__decoder
protected

Definition at line 94 of file InputStreamReader.h.

◆ __input

InputStream* InputStreamReader::__input
protected

Definition at line 93 of file InputStreamReader.h.


The documentation for this class was generated from the following files: