Package org.jibx.runtime.impl
Class StreamWriterBase
java.lang.Object
org.jibx.runtime.impl.XMLWriterNamespaceBase
org.jibx.runtime.impl.XMLWriterBase
org.jibx.runtime.impl.StreamWriterBase
- All Implemented Interfaces:
IExtensibleWriter
,IXMLWriter
- Direct Known Subclasses:
ISO88591StreamWriter
,UTF8StreamWriter
Base handler for marshalling text document to an output stream. This needs to
be subclassed with implementation methods specific to the encoding used.
- Author:
- Dennis M. Sosnoski
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final byte[]
private final StreamWriterBase
Original writer (only used when created using copy constructor,null
otherwise).protected byte[]
Cached reference to byte array used by buffer.private IOutByteBuffer
Output buffer.protected final byte[]
protected final byte[]
private final String
Name of encoding used for stream.protected byte[][][]
Byte sequences for prefixes of extension namespaces in scope.protected int
Current fill offset in buffer byte array.protected final byte[]
private boolean
Indent tags for pretty-printed text.private int
Base number of characters in indent sequence (end of line only).private int
Number of extra characters in indent sequence per level of nesting.private byte[]
Raw text for indentation sequences.protected final byte[]
protected byte[][]
Byte sequences for prefixes of namespaces in scope.protected final byte[]
Fields inherited from class org.jibx.runtime.impl.XMLWriterNamespaceBase
m_prefixes, m_uris
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
StreamWriterBase
(String enc, String[] uris) Constructor with supplied buffer.StreamWriterBase
(StreamWriterBase base, String[] uris) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close document output.void
flush()
Flush document output.Get the name of the character encoding used by this writer.void
indent()
Request output indent.void
indent
(int bias) Request output indent.protected void
makeSpace
(int length) Make at least the requested number of bytes available in the output buffer.void
Remove extension namespace URIs.void
pushExtensionNamespaces
(String[] uris) Append extension namespace URIs to those in mapping.void
setBuffer
(IOutByteBuffer buff) Set the byte buffer.void
setIndentSpaces
(int count, String newline, char indent) Set nesting indentation.void
setNamespaceUris
(String[] uris) Set namespace URIs.protected void
undefineNamespace
(int index) Report that namespace has been undefined.protected int
writeEntity
(byte[] bytes, int offset) Write entity bytes to output.protected void
writePrefix
(int index) Write namespace prefix to output.Methods inherited from class org.jibx.runtime.impl.XMLWriterBase
addAttribute, closeEmptyTag, closeStartTag, endTag, flagContent, flagTextContent, init, reset, startTagClosed, startTagNamespaces, startTagOpen, writeAttributeText, writeComment, writeDocType, writeEntityRef, writeMarkup, writeMarkup, writePI, writeXMLDecl
Methods inherited from class org.jibx.runtime.impl.XMLWriterNamespaceBase
decrementNesting, defineNamespace, getExtensionNamespaces, getNamespaceCount, getNamespacePrefix, getNamespaces, getNamespaceUri, getNestingDepth, getPrefixIndex, growArray, incrementNesting, internalNamespacePrefix, internalNamespaceUri, internalSetUris, openNamespaces, popTranslationTable, pushTranslationTable, shrinkArray, translateNamespace
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.jibx.runtime.IExtensibleWriter
createChildWriter
Methods inherited from interface org.jibx.runtime.IXMLWriter
getExtensionNamespaces, getNamespaceCount, getNamespacePrefix, getNamespaces, getNamespaceUri, getNestingDepth, getPrefixIndex, openNamespaces, popTranslationTable, pushTranslationTable, writeCData, writeTextContent
-
Field Details
-
m_quotEntityBytes
protected final byte[] m_quotEntityBytes -
m_ampEntityBytes
protected final byte[] m_ampEntityBytes -
m_gtEntityBytes
protected final byte[] m_gtEntityBytes -
m_ltEntityBytes
protected final byte[] m_ltEntityBytes -
m_cdataStartBytes
protected final byte[] m_cdataStartBytes -
m_cdataEndBytes
protected final byte[] m_cdataEndBytes -
m_byteBuffer
Output buffer. -
m_encodingName
Name of encoding used for stream. -
m_baseWriter
Original writer (only used when created using copy constructor,null
otherwise). -
m_buffer
protected byte[] m_bufferCached reference to byte array used by buffer. -
m_fillOffset
protected int m_fillOffsetCurrent fill offset in buffer byte array. -
m_prefixBytes
protected byte[][] m_prefixBytesByte sequences for prefixes of namespaces in scope. -
m_extensionBytes
protected byte[][][] m_extensionBytesByte sequences for prefixes of extension namespaces in scope. -
m_indent
private boolean m_indentIndent tags for pretty-printed text. -
m_indentBase
private int m_indentBaseBase number of characters in indent sequence (end of line only). -
m_indentPerLevel
private int m_indentPerLevelNumber of extra characters in indent sequence per level of nesting. -
m_indentSequence
private byte[] m_indentSequenceRaw text for indentation sequences.
-
-
Constructor Details
-
StreamWriterBase
Constructor with supplied buffer.- Parameters:
enc
- character encoding used for output to streams (upper case)uris
- ordered array of URIs for namespaces used in document (must be constant; the value in position 0 must always be the empty string "", and the value in position 1 must always be the XML namespace "http://www.w3.org/XML/1998/namespace")
-
StreamWriterBase
Copy constructor. This takes the stream and encoding information from a supplied instance, while setting a new array of namespace URIs. It's intended for use when invoking one binding from within another binding.- Parameters:
base
- instance to be used as base for writeruris
- ordered array of URIs for namespaces used in document (seeStreamWriterBase(String, String[])
)
-
-
Method Details
-
setBuffer
Set the byte buffer.- Parameters:
buff
-
-
getEncodingName
Get the name of the character encoding used by this writer.- Returns:
- encoding
-
setNamespaceUris
Set namespace URIs. This forces a reset of the writer, clearing any buffered output. It is intended to be used only for reconfiguring an existing writer for reuse.- Parameters:
uris
- ordered array of URIs for namespaces used in document- Throws:
IOException
-
setIndentSpaces
Set nesting indentation. This is advisory only, and implementations of this interface are free to ignore it. The intent is to indicate that the generated output should use indenting to illustrate element nesting.- Parameters:
count
- number of character to indent per level, or disable indentation if negative (zero means new line only)newline
- sequence of characters used for a line ending (null
means use the single character '\n')indent
- whitespace character used for indentation
-
makeSpace
Make at least the requested number of bytes available in the output buffer. If necessary, the output buffer will be replaced by a larger buffer.- Parameters:
length
- number of bytes space to be made available- Throws:
IOException
- if error writing to document
-
undefineNamespace
protected void undefineNamespace(int index) Report that namespace has been undefined.- Specified by:
undefineNamespace
in classXMLWriterNamespaceBase
- Parameters:
index
- post-translation namespace URI index number
-
writePrefix
Write namespace prefix to output. This internal method is used to throw an exception when an undeclared prefix is used.- Specified by:
writePrefix
in classXMLWriterBase
- Parameters:
index
- namespace URI index number- Throws:
IOException
- if error writing to document
-
writeEntity
protected int writeEntity(byte[] bytes, int offset) Write entity bytes to output.- Parameters:
bytes
- actual bytes to be writtenoffset
- starting offset in buffer- Returns:
- offset for next data byte in buffer
-
pushExtensionNamespaces
Append extension namespace URIs to those in mapping.- Specified by:
pushExtensionNamespaces
in interfaceIXMLWriter
- Overrides:
pushExtensionNamespaces
in classXMLWriterNamespaceBase
- Parameters:
uris
- namespace URIs to extend those in mapping
-
popExtensionNamespaces
public void popExtensionNamespaces()Remove extension namespace URIs. This removes the last set of extension namespaces pushed usingpushExtensionNamespaces(java.lang.String[])
.- Specified by:
popExtensionNamespaces
in interfaceIXMLWriter
- Overrides:
popExtensionNamespaces
in classXMLWriterNamespaceBase
-
indent
Request output indent. Output the line end sequence followed by the appropriate number of indent characters.- Specified by:
indent
in classXMLWriterBase
- Parameters:
bias
- indent depth difference (positive or negative) from current element nesting depth- Throws:
IOException
- on error writing to document
-
indent
Request output indent. Output the line end sequence followed by the appropriate number of indent characters for the current nesting level.- Throws:
IOException
- on error writing to document
-
flush
Flush document output. Forces out all output generated to this point.- Specified by:
flush
in interfaceIXMLWriter
- Specified by:
flush
in classXMLWriterBase
- Throws:
IOException
- on error writing to document
-
close
Close document output. Completes writing of document output, including closing the output medium.- Specified by:
close
in interfaceIXMLWriter
- Specified by:
close
in classXMLWriterBase
- Throws:
IOException
- on error writing to document
-