Xalan-C++ API Reference 1.12.0
XalanOutputStream.hpp
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18#if !defined(XALANOUTPUTSTREAM_HEADER_GUARD_1357924680)
19#define XALANOUTPUTSTREAM_HEADER_GUARD_1357924680
20
21
22
23// Base include file. Must be first.
25
26
27
29
30
31
33
34
35
38
39
40
41namespace XALAN_CPP_NAMESPACE {
42
43
44
45class XalanOutputTranscoder;
46
47
48
50{
51public :
52
53 enum { eDefaultBufferSize = 512u, eDefaultTranscoderBlockSize = 1024u };
54
58
59 /**
60 * Constructor.
61 *
62 * @param theBufferSize the size of the transcoding buffer
63 * @param theTranscoderBlockSize the size of the block used by the transcoder
64 * @param fThrowTranscodeException If true, an error transcoding will result in an exception being thrown.
65 */
66 explicit
68 MemoryManager& theManager,
69 size_type theBufferSize = eDefaultBufferSize,
70 size_type theTranscoderBlockSize = eDefaultTranscoderBlockSize,
71 bool fThrowTranscodeException = true);
72
73 virtual
75
76 MemoryManager&
78 {
79 return m_buffer.getMemoryManager();
80 }
81
82 static const XalanDOMChar*
84 {
85#if defined(XALAN_NEWLINE_IS_CRLF)
86 return s_nlCRString;
87#else
88 return s_nlString;
89#endif
90 }
91
92 /**
93 * Write the appropriate newline character(s) to the stream.
94 */
95 virtual void
97
98 /**
99 * Get the string which is appropriate for inserting a line feed in the stream.
100 */
101 virtual const XalanDOMChar*
103
104 /**
105 * Flush the stream's transcoding buffer, but do not request
106 * the implementation class to flush its buffer.
107 * .
108 */
109 void
111
112 /**
113 * Flush the stream's buffer.
114 */
115 void
117 {
118 flushBuffer();
119
120 doFlush();
121 }
122
123 /**
124 * Write a character to the output stream. The character
125 * will not be transcoded.
126 *
127 * @param theChar the character to write
128 */
129 void
131 {
132 write(&theChar, 1);
133 }
134
135 /**
136 * Write a wide character to the output stream. The character
137 * will be transcoded, if an output encoding is specified.
138 *
139 * @param theChar the character to write
140 */
141 void
143 {
144 assert(m_bufferSize > 0);
145
146 if (m_buffer.size() == m_bufferSize)
147 {
148 flushBuffer();
149 }
150
151 m_buffer.push_back(theChar);
152 }
153
154 /**
155 * Write a null-terminated string to the output file. The character
156 * will not be transcoded. The caller is responsible for making sure the
157 * buffer is flushed before calling this member function.
158 *
159 * @param theBuffer character buffer to write
160 */
161 void
162 write(const char* theBuffer)
163 {
164 assert(theBuffer != 0);
165 assert(m_buffer.empty() == true);
166
167 write(theBuffer, length(theBuffer));
168 }
169
170 /**
171 * Write a null-terminated wide string to the output file. The string
172 * will be transcoded, if an output encoding is specified.
173 *
174 * @param theBuffer character buffer to write
175 */
176 void
178 {
179 write(theBuffer, length(theBuffer));
180 }
181
182 /**
183 * Write a specified number of characters to the output stream. The string
184 * will not be transcoded. The caller is responsible for making sure the
185 * buffer is flushed before calling this member function.
186 *
187 * @param theBuffer character buffer to write
188 * @param theBufferLength number of characters to write
189 */
190 void
192 const char* theBuffer,
194 {
195 assert(theBuffer != 0);
196 assert(m_buffer.empty() == true);
197
198 writeData(theBuffer,
200 }
201
202 /**
203 * Write a specified number of characters to the output stream. The string
204 * will be transcoded, if an output encoding is specified.
205 *
206 * @param theBuffer character buffer to write
207 * @param theBufferLength number of characters to write
208 */
209 void
211 const XalanDOMChar* theBuffer,
213
214 /**
215 * Get the output encoding for the stream.
216 *
217 * @return The encoding name
218 */
219 const XalanDOMString&
221 {
222 return m_encoding;
223 }
224
225 /**
226 * Set the output encoding for the stream.
227 *
228 * @param theEncoding The encoding name
229 */
230 void
232
233 /**
234 * Determine if a given value can be represented in
235 * the output encoding.
236 *
237 * @return true if the value can be represented, and false if not.
238 */
239 bool
241
242
245 {
246 return m_transcoder;
247 }
248
249 /**
250 * Set the flag that indicates whether a transcoding
251 * error should throw an exception. The default is
252 * to throw an exception. If this flag is false, and
253 * and an error occurs transcoding, then data will
254 * likely be lost.
255 *
256 * @return the value of the flag.
257 */
258 bool
260 {
261 return m_throwTranscodeException;
262 }
263
264 /**
265 * Set the flag that indicates whether a transcoding
266 * error should throw an exception. The default is
267 * to throw an exception. If this flag is false, and
268 * and an error occurs transcoding, then data will
269 * likely be lost.
270 *
271 * @param the new value of the flag.
272 */
273 void
275 {
276 m_throwTranscodeException = flag;
277 }
278
279 /**
280 * Set the size of the output buffer.
281 *
282 * @param theBufferSize The buffer size.
283 */
284 void
286
287
289 {
290 public:
291
294 MemoryManager& theManager,
295 const Locator* theLocator);
296
299 MemoryManager& theManager);
300
302
303 virtual
305
306 virtual const XalanDOMChar*
307 getType() const;
308
309 private:
310 };
311
313 {
314 public:
315
319 const Locator* theLocator);
320
324
327 m_encoding(
328 other.m_encoding,
329 other.m_memoryManager)
330 {
331 }
332
333 virtual
335
336 const XalanDOMString&
338 {
339 return m_encoding;
340 }
341
342 virtual const XalanDOMChar*
343 getType() const;
344
345 private:
346
347 const XalanDOMString m_encoding;
348 };
349
381
401
402 static XalanDOMString&
405 int theErrorCode,
407
408protected:
409
410 /**
411 * Transcode a wide string.
412 *
413 * @param theBuffer The string to transcode.
414 * @param theBufferLength The length of the string.
415 * @param theDestination The destination vector.
416 */
417 void
419 const XalanDOMChar* theBuffer,
422
423 /**
424 * Write the data in the buffer
425 *
426 * @param theBuffer The data to write
427 * @param theBufferLength The length of theBuffer.
428 */
429 virtual void
431 const char* theBuffer,
433
434 /**
435 * Flush the stream.
436 */
437 virtual void
438 doFlush() = 0;
439
440 static const XalanDOMChar s_nlString[];
441 static const XalanDOMChar s_nlCRString[];
442
445
446private:
447
448 // These are not implemented...
450
452 operator=(const XalanOutputStream&);
453
454 bool
455 operator==(const XalanOutputStream&) const;
456
457 void
458 doWrite(
459 const XalanDOMChar* theBuffer,
461
462
463 const size_type m_transcoderBlockSize;
464
465 XalanOutputTranscoder* m_transcoder;
466
467 size_type m_bufferSize;
468
469 BufferType m_buffer;
470
471 XalanDOMString m_encoding;
472
473 bool m_writeAsUTF16;
474
475 bool m_throwTranscodeException;
476
477 TranscodeVectorType m_transcodingBuffer;
478};
479
480
481
482}
483
484
485
486#endif // XALANOUTPUTSTREAM_HEADER_GUARD_1357924680
#define XALAN_PLATFORMSUPPORT_EXPORT
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
virtual const XalanDOMChar * getType() const
Retrieve type of exception.
TranscoderInternalFailureException(const TranscoderInternalFailureException &other)
TranscoderInternalFailureException(const XalanDOMString &theEncoding, XalanDOMString &theBuffer, const Locator *theLocator)
TranscoderInternalFailureException(const XalanDOMString &theEncoding, XalanDOMString &theBuffer)
TranscodingException(XalanDOMString &theBuffer, const Locator *theLocator)
TranscodingException(const TranscodingException &other)
virtual const XalanDOMChar * getType() const
Retrieve type of exception.
TranscodingException(XalanDOMString &theBuffer)
UnsupportedEncodingException(const XalanDOMString &theEncoding, XalanDOMString &theBuffer, const Locator *theLocator)
UnsupportedEncodingException(const XalanDOMString &theEncoding, XalanDOMString &theBuffer)
UnsupportedEncodingException(const UnsupportedEncodingException &other)
virtual const XalanDOMChar * getType() const
Retrieve type of exception.
XalanOutputStreamException(const XalanDOMString &theMessage, MemoryManager &theManager)
XalanOutputStreamException(const XalanDOMString &theMessage, MemoryManager &theManager, const Locator *theLocator)
virtual const XalanDOMChar * getType() const
Retrieve type of exception.
XalanOutputStreamException(const XalanOutputStreamException &other)
void write(char theChar)
Write a character to the output stream.
void write(const XalanDOMChar *theBuffer, size_type theBufferLength)
Write a specified number of characters to the output stream.
void transcode(const XalanDOMChar *theBuffer, size_type theBufferLength, TranscodeVectorType &theDestination)
Transcode a wide string.
static const XalanDOMChar * defaultNewlineString()
void setOutputEncoding(const XalanDOMString &theEncoding)
Set the output encoding for the stream.
const XalanDOMString & getOutputEncoding() const
Get the output encoding for the stream.
const XalanOutputTranscoder * getTranscoder() const
MemoryManager & getMemoryManager()
XalanVector< char > TranscodeVectorType
virtual void doFlush()=0
Flush the stream.
XalanTranscodingServices::size_type size_type
bool canTranscodeTo(XalanUnicodeChar theChar) const
Determine if a given value can be represented in the output encoding.
bool getThrowTranscodeException() const
Set the flag that indicates whether a transcoding error should throw an exception.
virtual void writeData(const char *theBuffer, size_type theBufferLength)=0
Write the data in the buffer.
XalanOutputStream(MemoryManager &theManager, size_type theBufferSize=eDefaultBufferSize, size_type theTranscoderBlockSize=eDefaultTranscoderBlockSize, bool fThrowTranscodeException=true)
Constructor.
static XalanDOMString & formatMessage(const XalanDOMString &theMessage, int theErrorCode, XalanDOMString &theBuffer)
static const XalanDOMString::size_type s_nlStringLength
void setBufferSize(size_type theBufferSize)
Set the size of the output buffer.
void write(const char *theBuffer, size_type theBufferLength)
Write a specified number of characters to the output stream.
void write(const XalanDOMChar *theBuffer)
Write a null-terminated wide string to the output file.
void write(XalanDOMChar theChar)
Write a wide character to the output stream.
void flush()
Flush the stream's buffer.
virtual const XalanDOMChar * getNewlineString() const
Get the string which is appropriate for inserting a line feed in the stream.
void write(const char *theBuffer)
Write a null-terminated string to the output file.
void flushBuffer()
Flush the stream's transcoding buffer, but do not request the implementation class to flush its buffe...
XalanVector< XalanDOMChar > BufferType
void setThrowTranscodeException(bool flag)
Set the flag that indicates whether a transcoding error should throw an exception.
static const XalanDOMString::size_type s_nlCRStringLength
virtual void newline()
Write the appropriate newline character(s) to the stream.
XalanDOMString::size_type length(const XalanDOMString &theString)
Get the length of a XalanDOMString.
bool operator==(const XalanVector< Type > &theLHS, const XalanVector< Type > &theRHS)