com.sun.xml.bind.v2.runtime.output
Class UTF8XmlOutput

java.lang.Object
  extended by com.sun.xml.bind.v2.runtime.output.XmlOutputAbstractImpl
      extended by com.sun.xml.bind.v2.runtime.output.UTF8XmlOutput
All Implemented Interfaces:
XmlOutput
Direct Known Subclasses:
C14nXmlOutput, IndentingUTF8XmlOutput

public class UTF8XmlOutput
extends XmlOutputAbstractImpl

XmlOutput implementation specialized for UTF-8.


Field Summary
protected  boolean closeStartTagPending
          Set to true to indicate that we need to write '>' to close a start tag.
protected  byte[] octetBuffer
          Buffer of octets for writing.
protected  int octetBufferIndex
          Index in buffer to write to.
protected  OutputStream out
           
 
Fields inherited from class com.sun.xml.bind.v2.runtime.output.XmlOutputAbstractImpl
nsContext, nsUriIndex2prefixIndex, serializer
 
Constructor Summary
UTF8XmlOutput(OutputStream out, Encoded[] localNames)
           
 
Method Summary
 void attribute(int prefix, String localName, String value)
           
 void attribute(Name name, String value)
           
 void beginStartTag(int prefix, String localName)
           
 void beginStartTag(Name name)
          Writes a start tag.
protected  void closeStartTag()
          Writes '>' to close the start tag, if necessary.
 void endDocument(boolean fragment)
          Called at the very end.
 void endStartTag()
           
 void endTag(int prefix, String localName)
           
 void endTag(Name name)
           
protected  void flushBuffer()
           
 void setHeader(String header)
           
 void startDocument(XMLSerializer serializer, boolean fragment, int[] nsUriIndex2prefixIndex, NamespaceContextImpl nsContext)
          Called at the very beginning.
 void text(byte[] data, int dataLen)
          Writes the given byte[] as base64 encoded binary to the output.
 void text(int value)
           
 void text(Pcdata value, boolean needSP)
          Writes XML text with character escaping, if necessary.
 void text(String value, boolean needSP)
          Writes XML text with character escaping, if necessary.
(package private) static byte[] toBytes(String s)
           
protected  void write(byte[] b)
           
protected  void write(byte[] b, int start, int length)
           
 void write(int i)
          Writes one byte directly into the buffer.
protected  void writeNsDecl(int prefixIndex)
          Writes a single namespace declaration for the specified prefix.
protected  void writeNsDecls(int base)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

out

protected final OutputStream out

octetBuffer

protected final byte[] octetBuffer
Buffer of octets for writing.


octetBufferIndex

protected int octetBufferIndex
Index in buffer to write to.


closeStartTagPending

protected boolean closeStartTagPending
Set to true to indicate that we need to write '>' to close a start tag. Deferring the write of this char allows us to write "/>" for empty elements.

Constructor Detail

UTF8XmlOutput

public UTF8XmlOutput(OutputStream out,
                     Encoded[] localNames)
Parameters:
localNames - local names encoded in UTF-8.
Method Detail

setHeader

public void setHeader(String header)

startDocument

public void startDocument(XMLSerializer serializer,
                          boolean fragment,
                          int[] nsUriIndex2prefixIndex,
                          NamespaceContextImpl nsContext)
                   throws IOException,
                          SAXException,
                          javax.xml.stream.XMLStreamException
Description copied from class: XmlOutputAbstractImpl
Called at the very beginning.

Specified by:
startDocument in interface XmlOutput
Overrides:
startDocument in class XmlOutputAbstractImpl
Parameters:
serializer - the XMLSerializer that coordinates this whole marshalling episode.
fragment - true if we are marshalling a fragment.
Throws:
IOException
SAXException
javax.xml.stream.XMLStreamException

endDocument

public void endDocument(boolean fragment)
                 throws IOException,
                        SAXException,
                        javax.xml.stream.XMLStreamException
Description copied from class: XmlOutputAbstractImpl
Called at the very end.

Specified by:
endDocument in interface XmlOutput
Overrides:
endDocument in class XmlOutputAbstractImpl
Parameters:
fragment - false if we are writing the whole document.
Throws:
IOException
SAXException
javax.xml.stream.XMLStreamException

closeStartTag

protected final void closeStartTag()
                            throws IOException
Writes '>' to close the start tag, if necessary.

Throws:
IOException

beginStartTag

public void beginStartTag(int prefix,
                          String localName)
                   throws IOException
Specified by:
beginStartTag in interface XmlOutput
Specified by:
beginStartTag in class XmlOutputAbstractImpl
Throws:
IOException

beginStartTag

public void beginStartTag(Name name)
                   throws IOException
Description copied from class: XmlOutputAbstractImpl
Writes a start tag.

At this point XmlOutputAbstractImpl.nsContext holds namespace declarations needed for this new element.

This method is used for writing tags that are indexed.

Specified by:
beginStartTag in interface XmlOutput
Overrides:
beginStartTag in class XmlOutputAbstractImpl
Throws:
IOException

writeNsDecls

protected void writeNsDecls(int base)
                     throws IOException
Throws:
IOException

writeNsDecl

protected final void writeNsDecl(int prefixIndex)
                          throws IOException
Writes a single namespace declaration for the specified prefix.

Throws:
IOException

attribute

public void attribute(Name name,
                      String value)
               throws IOException
Specified by:
attribute in interface XmlOutput
Overrides:
attribute in class XmlOutputAbstractImpl
Throws:
IOException

attribute

public void attribute(int prefix,
                      String localName,
                      String value)
               throws IOException
Specified by:
attribute in interface XmlOutput
Specified by:
attribute in class XmlOutputAbstractImpl
Parameters:
prefix - -1 if this attribute does not have a prefix (this handling differs from that of elements.)
Throws:
IOException

endStartTag

public void endStartTag()
                 throws IOException
Specified by:
endStartTag in interface XmlOutput
Specified by:
endStartTag in class XmlOutputAbstractImpl
Throws:
IOException

endTag

public void endTag(Name name)
            throws IOException
Specified by:
endTag in interface XmlOutput
Overrides:
endTag in class XmlOutputAbstractImpl
Throws:
IOException

endTag

public void endTag(int prefix,
                   String localName)
            throws IOException
Specified by:
endTag in interface XmlOutput
Specified by:
endTag in class XmlOutputAbstractImpl
Throws:
IOException

text

public void text(String value,
                 boolean needSP)
          throws IOException
Description copied from interface: XmlOutput
Writes XML text with character escaping, if necessary.

Parameters:
value - this string can contain characters that might need escaping (such as '&' or '>')
Throws:
IOException

text

public void text(Pcdata value,
                 boolean needSP)
          throws IOException
Description copied from interface: XmlOutput
Writes XML text with character escaping, if necessary.

Parameters:
value - this string can contain characters that might need escaping (such as '&' or '>')
Throws:
IOException

text

public final void text(int value)
                throws IOException
Throws:
IOException

text

public void text(byte[] data,
                 int dataLen)
          throws IOException
Writes the given byte[] as base64 encoded binary to the output.

Being defined on this class allows this method to access the buffer directly, which translates to a better performance.

Throws:
IOException

write

public final void write(int i)
                 throws IOException
Writes one byte directly into the buffer.

This method can be used somewhat like the text method, but it doesn't perform character escaping.

Throws:
IOException

write

protected final void write(byte[] b)
                    throws IOException
Throws:
IOException

write

protected final void write(byte[] b,
                           int start,
                           int length)
                    throws IOException
Throws:
IOException

flushBuffer

protected final void flushBuffer()
                          throws IOException
Throws:
IOException

toBytes

static byte[] toBytes(String s)