Package net.sf.saxon.serialize
Class UTF8Writer
- java.lang.Object
-
- java.io.Writer
-
- net.sf.saxon.serialize.UTF8Writer
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.Appendable,java.lang.AutoCloseable,UnicodeWriter
public final class UTF8Writer extends java.io.Writer implements 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).
-
-
Constructor Summary
Constructors Constructor Description UTF8Writer(java.io.OutputStream out)UTF8Writer(java.io.OutputStream out, int bufferLength)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Complete the writing of characters to the result.voidflush()Flush the contents of any buffers.voidwrite(char[] cbuf)voidwrite(char[] cbuf, int off, int len)voidwrite(int c)Write a single char.voidwrite(java.lang.String str)Process a supplied stringvoidwrite(java.lang.String str, int off, int len)voidwrite(UnicodeString chars)Process a supplied stringvoidwriteAscii(byte[] content)Write a sequence of ASCII characters.voidwriteAscii(byte[] chars, int off, int len)Write a sequence of ASCII characters.voidwriteCodePoint(int codepoint)Process a single character.voidwriteLatin1(byte[] bytes, int off, int len)voidwriteRepeatedAscii(byte ch, int repeat)Write an ASCII character repeatedly.
-
-
-
Method Detail
-
close
public void close() throws java.io.IOExceptionDescription copied from interface:UnicodeWriterComplete the writing of characters to the result. The default implementation does nothing.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfaceUnicodeWriter- Specified by:
closein classjava.io.Writer- Throws:
java.io.IOException- if processing fails for any reason
-
flush
public void flush() throws java.io.IOExceptionDescription copied from interface:UnicodeWriterFlush the contents of any buffers. The default implementation does nothing.- Specified by:
flushin interfacejava.io.Flushable- Specified by:
flushin interfaceUnicodeWriter- Specified by:
flushin classjava.io.Writer- Throws:
java.io.IOException- if processing fails for any reason
-
write
public void write(char[] cbuf) throws java.io.IOException- Overrides:
writein classjava.io.Writer- Throws:
java.io.IOException
-
write
public void write(char[] cbuf, int off, int len) throws java.io.IOException- Specified by:
writein classjava.io.Writer- Throws:
java.io.IOException
-
writeLatin1
public void writeLatin1(byte[] bytes, int off, int len) throws java.io.IOException- Throws:
java.io.IOException
-
writeAscii
public void writeAscii(byte[] content) throws java.io.IOExceptionWrite a sequence of ASCII characters. The caller is responsible for ensuring that each byte represents a character in the range 1-127- Specified by:
writeAsciiin interfaceUnicodeWriter- Parameters:
content- the content to be written- Throws:
java.io.IOException- if processing fails for any reason
-
writeAscii
public void writeAscii(byte[] chars, int off, int len) throws java.io.IOExceptionWrite 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:
java.io.IOException
-
writeRepeatedAscii
public void writeRepeatedAscii(byte ch, int repeat) throws java.io.IOExceptionWrite an ASCII character repeatedly. Used for serializing whitespace.- Specified by:
writeRepeatedAsciiin interfaceUnicodeWriter- Parameters:
ch- the ASCII character to be serialized (must be less than 0x7f)repeat- the number of occurrences to output- Throws:
java.io.IOException- if it fails
-
writeCodePoint
public void writeCodePoint(int codepoint) throws java.io.IOExceptionProcess a single character. Default implementation wraps the codepoint into a single-characterUnicodeString- Specified by:
writeCodePointin interfaceUnicodeWriter- Parameters:
codepoint- the character to be processed. Must not be a surrogate- Throws:
java.io.IOException- if processing fails for any reason
-
write
public void write(int c) throws java.io.IOExceptionWrite 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:
writein classjava.io.Writer- Parameters:
c- the char to be written- Throws:
java.io.IOException- If an I/O error occurs
-
write
public void write(UnicodeString chars) throws java.io.IOException
Process a supplied string- Specified by:
writein interfaceUnicodeWriter- Parameters:
chars- the characters to be processed- Throws:
java.io.IOException- if processing fails for any reason
-
write
public void write(java.lang.String str) throws java.io.IOExceptionDescription copied from interface:UnicodeWriterProcess a supplied string- Specified by:
writein interfaceUnicodeWriter- Overrides:
writein classjava.io.Writer- Parameters:
str- the characters to be processed- Throws:
java.io.IOException- if processing fails for any reason
-
write
public void write(java.lang.String str, int off, int len) throws java.io.IOException- Overrides:
writein classjava.io.Writer- Throws:
java.io.IOException
-
-