public abstract class BasicWriter extends Logging implements java.io.Closeable
BasicWriter implements the internal Logging interface for reporting the context of errors, and manages the encapsulated XMLStreamer, and the Lexicon used by its descendants. The Lexicon defines the mapping from XML entity references to escaped characters or abbreviated boilerplate text. BasicWriter implements the Closeable interface, so may be used in try-with-resources blocks (since JDK 1.7).
Modifier and Type | Field and Description |
---|---|
protected Lexicon |
lexicon
The Lexicon used by this BasicWriter to encode escaped character data.
|
protected XMLStreamer |
streamer
The XMLStreamer used by this BasicWriter to stream the output data.
|
Constructor and Description |
---|
BasicWriter(XMLStreamer streamer)
Creates a BasicWriter using a XMLStreamer to stream the written data.
|
Modifier and Type | Method and Description |
---|---|
protected void |
checkEncoding(java.lang.String declared,
java.lang.String actual)
Checks that the declared character encoding matches the actual
character encoding used to encode the XML file.
|
void |
close()
Closes this BasicWriter writer.
|
protected boolean |
endOfStream()
Secretly reports whether the end of the underlying XMLStreamer was
reached prematurely.
|
void |
flush()
Flushes this BasicWriter writer.
|
protected java.lang.String |
getContext()
Returns the XML context in which any kind of error was detected.
|
java.lang.String |
getEncoding()
Reports the character encoding used by this BasicWriter.
|
Lexicon |
getLexicon()
Returns the Lexicon used by this BasicWriter for encoding escaped
characters and boilerplate text.
|
int |
getLineNumber()
Reports the current line number of this BasicWriter.
|
void |
setLexicon(Lexicon lexicon)
Replaces the Lexicon used by this BasicWriter for encoding escaped
characters and boilerplate text.
|
encodingError, semanticError, syntaxError
protected XMLStreamer streamer
protected Lexicon lexicon
public BasicWriter(XMLStreamer streamer)
streamer
- the underlying character streamer.public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
- if an I/O fault occurs during closing.public void flush() throws java.io.IOException
java.io.IOException
- if an I/O fault occurs during flushing.public java.lang.String getEncoding()
public int getLineNumber()
getLineNumber
in class Logging
protected java.lang.String getContext()
getContext
in class Logging
protected boolean endOfStream()
endOfStream
in class Logging
public Lexicon getLexicon()
public void setLexicon(Lexicon lexicon)
lexicon
- the Lexicon to use instead.protected void checkEncoding(java.lang.String declared, java.lang.String actual) throws java.io.UnsupportedEncodingException
declared
- the character encoding in the XML declaration.actual
- the character encoding used by the streamer.java.io.UnsupportedEncodingException
- if the encodings don't match.