Package net.sf.saxon.serialize
Class UTF8Writer
java.lang.Object
java.io.Writer
net.sf.saxon.serialize.UTF8Writer
- All Implemented Interfaces:
Closeable
,Flushable
,Appendable
,AutoCloseable
,UnicodeWriter
Specialized buffering UTF-8 writer.
The main reason for custom version is to allow for efficient
buffer recycling; the second benefit is that encoder has less
overhead for short content encoding (compared to JDK default
codecs).
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Complete the writing of characters to the result.void
flush()
Flush the contents of any buffers.void
write
(char[] cbuf) void
write
(char[] cbuf, int off, int len) void
write
(int c) Write a single char.void
Process a supplied stringvoid
void
write
(UnicodeString chars) Process a supplied stringvoid
writeAscii
(byte[] content) Write a sequence of ASCII characters.void
writeAscii
(byte[] chars, int off, int len) Write a sequence of ASCII characters.void
writeCodePoint
(int codepoint) Process a single character.void
writeLatin1
(byte[] bytes, int off, int len) void
writeRepeatedAscii
(byte ch, int repeat) Write an ASCII character repeatedly.Methods inherited from class java.io.Writer
append, append, append, nullWriter
-
Constructor Details
-
UTF8Writer
-
UTF8Writer
-
-
Method Details
-
close
Description copied from interface:UnicodeWriter
Complete the writing of characters to the result. The default implementation does nothing.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceUnicodeWriter
- Specified by:
close
in classWriter
- Throws:
IOException
- if processing fails for any reason
-
flush
Description copied from interface:UnicodeWriter
Flush the contents of any buffers. The default implementation does nothing.- Specified by:
flush
in interfaceFlushable
- Specified by:
flush
in interfaceUnicodeWriter
- Specified by:
flush
in classWriter
- Throws:
IOException
- if processing fails for any reason
-
write
- Overrides:
write
in classWriter
- Throws:
IOException
-
write
- Specified by:
write
in classWriter
- Throws:
IOException
-
writeLatin1
- Throws:
IOException
-
writeAscii
Write a sequence of ASCII characters. The caller is responsible for ensuring that each byte represents a character in the range 1-127- Specified by:
writeAscii
in interfaceUnicodeWriter
- Parameters:
content
- the content to be written- Throws:
IOException
- if processing fails for any reason
-
writeAscii
Write a sequence of ASCII characters. The caller is responsible for ensuring that each byte represents a character in the range 1-127- Parameters:
chars
- the characters to be writtenoff
- the offset of the first character to be includedlen
- the number of characters to be written- Throws:
IOException
-
writeRepeatedAscii
Write an ASCII character repeatedly. Used for serializing whitespace.- Specified by:
writeRepeatedAscii
in interfaceUnicodeWriter
- Parameters:
ch
- the ASCII character to be serialized (must be less than 0x7f)repeat
- the number of occurrences to output- Throws:
IOException
- if it fails
-
writeCodePoint
Process a single character. Default implementation wraps the codepoint into a single-characterUnicodeString
- Specified by:
writeCodePoint
in interfaceUnicodeWriter
- Parameters:
codepoint
- the character to be processed. Must not be a surrogate- Throws:
IOException
- if processing fails for any reason
-
write
Write a single char.Note (MHK) Although the Writer interface says that the top half of the int is ignored, this implementation appears to accept a Unicode codepoint which is output as a 4-byte UTF-8 sequence.
- Overrides:
write
in classWriter
- Parameters:
c
- the char to be written- Throws:
IOException
- If an I/O error occurs
-
write
Process a supplied string- Specified by:
write
in interfaceUnicodeWriter
- Parameters:
chars
- the characters to be processed- Throws:
IOException
- if processing fails for any reason
-
write
Description copied from interface:UnicodeWriter
Process a supplied string- Specified by:
write
in interfaceUnicodeWriter
- Overrides:
write
in classWriter
- Parameters:
str
- the characters to be processed- Throws:
IOException
- if processing fails for any reason
-
write
- Overrides:
write
in classWriter
- Throws:
IOException
-