com.objsys.asn1j.runtime
Class Asn1XmlOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by com.objsys.asn1j.runtime.Asn1OutputStream
          extended by com.objsys.asn1j.runtime.Asn1XmlOutputStream
All Implemented Interfaces:
Asn1XmlEncoder, Asn1XmlXerEncoder, java.io.Closeable, java.io.Flushable

public class Asn1XmlOutputStream
extends Asn1OutputStream
implements Asn1XmlEncoder

This class implements the output stream to encode ASN.1 messages as specified in the XML Encoding as specified in the XML schema standard. A reference to an object of this type is passed to each of the ASN.1 type encode methods involved in encoding a particular message type.


Field Summary
 
Fields inherited from class com.objsys.asn1j.runtime.Asn1OutputStream
os
 
Fields inherited from interface com.objsys.asn1j.runtime.Asn1XmlEncoder
XMLDATA, XMLEND, XMLINDENT, XMLINIT, XMLSTART
 
Constructor Summary
Asn1XmlOutputStream(java.io.OutputStream os)
          This constructor creates a buffered XML output stream object with default size of buffer.
Asn1XmlOutputStream(java.io.OutputStream os, int bufSize)
          This constructor creates a buffered XML output stream object.
 
Method Summary
 void copy(byte value)
          This method is used to copy a single byte to the output stream.
 void copy(byte[] value)
          This method copies multiple bytes to the output stream.
 void copy(byte[] value, int off, int len)
          This method copies multiple bytes to the output stream.
 void copy(java.lang.String value)
          This method copies a character string to the output stream.
 void decrLevel()
          This method decrements the element nesting level counter.
 void encodeAttr(java.lang.String qname, java.lang.String value)
          This method encodes an XML attribute value.
 void encodeBinStrValue(byte[] bits, int nbits)
          This method encodes XML binary string data
 void encodeData(java.lang.String value)
          This method encodes XML string data
 void encodeDoubleValue(double value, java.lang.String elemName, java.lang.String nsPrefix)
          This method encodes an XML REAL (double) value (with start and end tags).
 void encodeEmptyElement(java.lang.String elemName, java.lang.String nsPrefix)
          This method encodes an XML empty element tag
 void encodeEndDocument()
          This method encodes standard trailor information at the end of the XML document.
 void encodeEndElement(java.lang.String elemName, java.lang.String nsPrefix)
          This method encodes an XML end element tag.
 void encodeHexStrValue(byte[] data)
          This method encodes XML hexadecimal string data
 void encodeNamedValue(java.lang.String valueName, java.lang.String elemName, java.lang.String nsPrefix)
          This method encodes an XML named value (with start and end tags)
 void encodeNamedValueElement(java.lang.String valueName)
          This method encodes an XML named value element tag.
 void encodeStartDocument()
          This method encodes standard header information at the beginning of the XML document.
 void encodeStartElement(java.lang.String elemName, java.lang.String nsPrefix, boolean terminate)
          This method encodes an XML start element tag with attribute.
 void encodeXSIAttrs()
          This method encodes XSI attributes.
 Asn1XmlEncodeHelper getHelper()
          This method returns a reference to the internal helper object.
 void incrLevel()
          This method increments the element nesting level counter.
 void indent()
          This methods indents by adding a new-line followed by whitespace corresponding to the current nesting level to the output stream.
 void setIndent(int value)
          This method sets the number of spaces per indentation.
 void setMixedContent(boolean value)
          This method sets the mixed content flag which indicates that this buffer will be used to encode mixed content.
 void setTermStart(boolean value)
          This method sets the start element termination required flag.
 void setXSIAttrs(Asn1XmlXSIAttrs value)
          This method sets the XSI attributes object to the given value.
 void write(java.lang.String value)
          This method copies a character string to the output stream.
 
Methods inherited from class com.objsys.asn1j.runtime.Asn1OutputStream
close, flush, getContext, write, write, write, write2Bytes, write4Bytes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.objsys.asn1j.runtime.Asn1XmlXerEncoder
getContext
 

Constructor Detail

Asn1XmlOutputStream

public Asn1XmlOutputStream(java.io.OutputStream os)
This constructor creates a buffered XML output stream object with default size of buffer. Whenever the buffer becomes full, the buffer will be flushed to the stream.

Parameters:
os - The underlying OutputStream object.

Asn1XmlOutputStream

public Asn1XmlOutputStream(java.io.OutputStream os,
                           int bufSize)
This constructor creates a buffered XML output stream object. Whenever the buffer becomes full, the buffer will be flushed to the stream.

Parameters:
os - The underlying OutputStream object.
bufSize - The buffer size. If it is 0 then the output stream is used as unbuffered.
Method Detail

copy

public void copy(byte value)
          throws java.io.IOException
This method is used to copy a single byte to the output stream. It first converts the byte to a hex character representation and then copies it to the output buffer.

Specified by:
copy in interface Asn1XmlXerEncoder
Parameters:
value - The byte value to copy
Throws:
java.io.IOException - Any exception thrown by the underlying OutputStream.

copy

public void copy(byte[] value)
          throws java.io.IOException,
                 Asn1Exception
This method copies multiple bytes to the output stream. It is assumed the byte are already formatted into a valid XML encoding type (for example, UTF-8).

Specified by:
copy in interface Asn1XmlXerEncoder
Parameters:
value - Array of bytes to copy to the output stream
Throws:
java.io.IOException - Any exception thrown by the underlying OutputStream.
Asn1Exception - Thrown, if operation is failed.

copy

public void copy(byte[] value,
                 int off,
                 int len)
          throws java.io.IOException,
                 Asn1Exception
This method copies multiple bytes to the output stream. It is assumed the byte are already formatted into a valid XML encoding type (for example, UTF-8).

Specified by:
copy in interface Asn1XmlXerEncoder
Parameters:
value - Array of bytes to copy to the output stream
off - Starting offset in array
len - The length to be encoded
Throws:
java.io.IOException - Any exception thrown by the underlying OutputStream.
Asn1Exception - Thrown, if operation is failed.

copy

public void copy(java.lang.String value)
          throws java.io.IOException,
                 Asn1Exception
This method copies a character string to the output stream.

Specified by:
copy in interface Asn1XmlXerEncoder
Parameters:
value - The string value to copy
Throws:
java.io.IOException - Any exception thrown by the underlying OutputStream.
Asn1Exception - Thrown, if operation is failed.

write

public void write(java.lang.String value)
           throws java.io.IOException,
                  Asn1Exception
This method copies a character string to the output stream.

Parameters:
value - The string value to copy
Throws:
java.io.IOException - Any exception thrown by the underlying OutputStream.
Asn1Exception - Thrown, if operation is failed.

decrLevel

public void decrLevel()
This method decrements the element nesting level counter.

Specified by:
decrLevel in interface Asn1XmlXerEncoder

encodeData

public void encodeData(java.lang.String value)
                throws java.io.IOException,
                       Asn1Exception
This method encodes XML string data

Specified by:
encodeData in interface Asn1XmlXerEncoder
Parameters:
value - String value to encode
Throws:
java.io.IOException - Any exception thrown by the underlying OutputStream.
Asn1Exception - Thrown, if operation is failed.

encodeAttr

public void encodeAttr(java.lang.String qname,
                       java.lang.String value)
                throws java.io.IOException,
                       Asn1Exception
This method encodes an XML attribute value.

Specified by:
encodeAttr in interface Asn1XmlEncoder
Parameters:
qname - Attribute qualified name.
value - Attribute value in string form.
Throws:
java.io.IOException
Asn1Exception

encodeBinStrValue

public void encodeBinStrValue(byte[] bits,
                              int nbits)
                       throws java.io.IOException,
                              Asn1Exception
This method encodes XML binary string data

Specified by:
encodeBinStrValue in interface Asn1XmlXerEncoder
Parameters:
bits - Bit string to encode
Throws:
java.io.IOException - Any exception thrown by the underlying OutputStream.
Asn1Exception - Thrown, if operation is failed.

encodeHexStrValue

public void encodeHexStrValue(byte[] data)
                       throws java.io.IOException,
                              Asn1Exception
This method encodes XML hexadecimal string data

Specified by:
encodeHexStrValue in interface Asn1XmlXerEncoder
Parameters:
data - Data to encode
Throws:
java.io.IOException - Any exception thrown by the underlying OutputStream.
Asn1Exception - Thrown, if operation is failed.

encodeEndDocument

public void encodeEndDocument()
                       throws java.io.IOException,
                              Asn1Exception
This method encodes standard trailor information at the end of the XML document.

Specified by:
encodeEndDocument in interface Asn1XmlXerEncoder
Throws:
java.io.IOException - Any exception thrown by the underlying OutputStream.
Asn1Exception - Thrown, if operation is failed.

encodeEndElement

public void encodeEndElement(java.lang.String elemName,
                             java.lang.String nsPrefix)
                      throws java.io.IOException,
                             Asn1Exception
This method encodes an XML end element tag.

Specified by:
encodeEndElement in interface Asn1XmlEncoder
Parameters:
elemName - The name of element.
Throws:
java.io.IOException - If I/O error occurs.
Asn1Exception - Thrown, if operation is failed.

encodeStartDocument

public void encodeStartDocument()
                         throws java.io.IOException,
                                Asn1Exception
This method encodes standard header information at the beginning of the XML document.

Specified by:
encodeStartDocument in interface Asn1XmlXerEncoder
Throws:
java.io.IOException - If I/O error occurs.
Asn1Exception - Thrown, if operation is failed.

encodeStartElement

public void encodeStartElement(java.lang.String elemName,
                               java.lang.String nsPrefix,
                               boolean terminate)
                        throws Asn1Exception,
                               java.io.IOException
This method encodes an XML start element tag with attribute.

Specified by:
encodeStartElement in interface Asn1XmlEncoder
Parameters:
elemName - The name of element.
nsPrefix - The namespace prefix of element.
Throws:
java.io.IOException - If I/O error occurs.
Asn1Exception - Thrown, if operation is failed.

encodeEmptyElement

public void encodeEmptyElement(java.lang.String elemName,
                               java.lang.String nsPrefix)
                        throws Asn1Exception,
                               java.io.IOException
This method encodes an XML empty element tag

Specified by:
encodeEmptyElement in interface Asn1XmlEncoder
Parameters:
elemName - The name of element.
nsPrefix - The namespace prefix of element.
Throws:
java.io.IOException - If I/O error occurs.
Asn1Exception - Thrown, if operation is failed.

encodeNamedValueElement

public void encodeNamedValueElement(java.lang.String valueName)
                             throws Asn1Exception,
                                    java.io.IOException
This method encodes an XML named value element tag.

Specified by:
encodeNamedValueElement in interface Asn1XmlXerEncoder
Parameters:
valueName - The name of the element.
Throws:
java.io.IOException - If I/O error occurs.
Asn1Exception - Thrown, if operation is failed.

encodeNamedValue

public void encodeNamedValue(java.lang.String valueName,
                             java.lang.String elemName,
                             java.lang.String nsPrefix)
                      throws Asn1Exception,
                             java.io.IOException
This method encodes an XML named value (with start and end tags)

Specified by:
encodeNamedValue in interface Asn1XmlEncoder
Parameters:
valueName - The name of value.
elemName - The name of element.
nsPrefix - Element namespace prefix value
Throws:
java.io.IOException - If I/O error occurs.
Asn1Exception - Thrown, if operation is failed.

encodeDoubleValue

public void encodeDoubleValue(double value,
                              java.lang.String elemName,
                              java.lang.String nsPrefix)
                       throws java.io.IOException,
                              Asn1Exception
This method encodes an XML REAL (double) value (with start and end tags).

Specified by:
encodeDoubleValue in interface Asn1XmlEncoder
Parameters:
value - The value to be encoded.
elemName - The name of element. If null, then start and end tags won't be encoded.
nsPrefix - Element namespace prefix value
Throws:
java.io.IOException - If I/O error occurs.
Asn1Exception - Thrown, if operation is failed.

encodeXSIAttrs

public void encodeXSIAttrs()
                    throws Asn1Exception,
                           java.io.IOException
This method encodes XSI attributes.

Specified by:
encodeXSIAttrs in interface Asn1XmlEncoder
Throws:
Asn1Exception
java.io.IOException

getHelper

public Asn1XmlEncodeHelper getHelper()
This method returns a reference to the internal helper object.

Specified by:
getHelper in interface Asn1XmlEncoder
Returns:
Reference to mHelper object.

incrLevel

public void incrLevel()
This method increments the element nesting level counter.

Specified by:
incrLevel in interface Asn1XmlXerEncoder

indent

public void indent()
            throws java.io.IOException,
                   Asn1Exception
This methods indents by adding a new-line followed by whitespace corresponding to the current nesting level to the output stream.

Specified by:
indent in interface Asn1XmlXerEncoder
Throws:
java.io.IOException - Any exception thrown by the underlying OutputStream.
Asn1Exception - Thrown, if operation is failed.

setIndent

public void setIndent(int value)
This method sets the number of spaces per indentation. If the value is set to zero, no indentation of the XML data is done.

Specified by:
setIndent in interface Asn1XmlEncoder
Parameters:
value - Number of spaces per indentation level.

setMixedContent

public void setMixedContent(boolean value)
This method sets the mixed content flag which indicates that this buffer will be used to encode mixed content.

Parameters:
value - Boolean value

setTermStart

public void setTermStart(boolean value)
This method sets the start element termination required flag.

Parameters:
value - Boolean value

setXSIAttrs

public void setXSIAttrs(Asn1XmlXSIAttrs value)
This method sets the XSI attributes object to the given value.

Specified by:
setXSIAttrs in interface Asn1XmlEncoder
Parameters:
value - XSI attributes object