com.objsys.asn1j.runtime
Class Asn1XerEncodeBuffer

java.lang.Object
  extended by com.objsys.asn1j.runtime.Asn1MessageBufferBase
      extended by com.objsys.asn1j.runtime.Asn1MessageBuffer
          extended by com.objsys.asn1j.runtime.Asn1EncodeBuffer
              extended by com.objsys.asn1j.runtime.Asn1XerEncodeBuffer
All Implemented Interfaces:
Asn1XerEncoder, Asn1XmlXerEncoder

public class Asn1XerEncodeBuffer
extends Asn1EncodeBuffer
implements Asn1XerEncoder

This class handles the encoding of ASN.1 messages as specified in the XML Encoding Rules (XER) as specified in the ITU-T X.693 standard.


Field Summary
 
Fields inherited from class com.objsys.asn1j.runtime.Asn1EncodeBuffer
INITIAL_SIZE, mByteIndex, mData
 
Fields inherited from class com.objsys.asn1j.runtime.Asn1MessageBufferBase
context, mTypeCode
 
Fields inherited from interface com.objsys.asn1j.runtime.Asn1XerEncoder
XERDATA, XEREND, XERINDENT, XERINIT, XERSTART
 
Constructor Summary
Asn1XerEncodeBuffer()
          The default constructor creates an XER encode buffer object with the default initial size and canonical set to false.
Asn1XerEncodeBuffer(boolean canonical)
          The parameterized constructor creates an XER encode buffer object with default initial size and canonical set to the given values.
Asn1XerEncodeBuffer(boolean canonical, int size)
          The parameterized constructor creates an XER encode buffer object with initial size increment and canonical set to the given values.
 
Method Summary
 void binDump(java.io.PrintStream out, java.lang.String varName)
          This method dumps the encoded message in a human-readable format showing a bit trace of all fields to the given print output stream.
 void copy(byte value)
          This method is used to copy a single byte to the encode buffer.
 void copy(byte[] value)
          This method copies multiple bytes to the encode buffer.
 void copy(byte[] value, int off, int len)
          This method copies multiple bytes to the encode buffer.
 void copy(java.lang.String value)
          This method copies a character string to the encode buffer.
 void decrLevel()
          This method decrements the element nesting level counter.
 void encodeBinStrValue(byte[] bits, int nbits)
          This method encodes XML binary string data
 void encodeByte(byte value)
          This method is used to encode a single byte to the encode buffer.
 void encodeData(java.lang.String value)
          This method encodes XML string data
 void encodeEmptyElement(java.lang.String elemName)
          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)
          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)
          This method encodes an XML named value (with start and end tags)
 void encodeNamedValueElement(java.lang.String elemName)
          This method encodes an XML named value element tag
 void encodeRealValue(double value, java.lang.String elemName)
          This method encodes an XML REAL (double) value (with start and end tags).
 void encodeStartDocument()
          This method encodes standard header information at the beginning of the XML document.
 void encodeStartElement(java.lang.String elemName)
          This method encodes an XML start element tag
 byte[] getBuffer()
          This method returns a reference to the byte buffer used to hold the encoded message.
 java.io.InputStream getInputStream()
          This method returns an input stream object reference to the message buffer contents (i.e. the encoded data).
 byte[] getMsgCopy()
          This method returns the encoded message in a byte array.
 int getMsgLength()
          This method returns the length (in bytes) of the encoded message component.
 int getState()
          This method gets the state of the buffer.
 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 encode buffer.
 void reset()
          This method resets the buffer to allow a new record to be encoded into it.
 void setCanonical(boolean value)
          This method sets the canonical encoding flag to the given value.
 void setState(int stat)
          This method sets the state of the buffer.
 void write(java.io.OutputStream out)
          This method writes the encoded record to the given output stream.
 
Methods inherited from class com.objsys.asn1j.runtime.Asn1EncodeBuffer
binDump, checkSize, hexDump, hexDump, initBuffer, trimBitString
 
Methods inherited from class com.objsys.asn1j.runtime.Asn1MessageBuffer
addNamedEventHandler, getEventHandlerListCount, hasEventHandlers, invokeCharacters, invokeEndElement, invokeStartElement, setEventHandlerList
 
Methods inherited from class com.objsys.asn1j.runtime.Asn1MessageBufferBase
getContext, hexDump, hexDump, setKey, setTypeCode
 
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

Asn1XerEncodeBuffer

public Asn1XerEncodeBuffer()
The default constructor creates an XER encode buffer object with the default initial size and canonical set to false.


Asn1XerEncodeBuffer

public Asn1XerEncodeBuffer(boolean canonical)
The parameterized constructor creates an XER encode buffer object with default initial size and canonical set to the given values.

Parameters:
canonical - Boolean indicating a canonical or non-canonical encoding should be produced as defined in the X.693 standard.

Asn1XerEncodeBuffer

public Asn1XerEncodeBuffer(boolean canonical,
                           int size)
The parameterized constructor creates an XER encode buffer object with initial size increment and canonical set to the given values.

Parameters:
canonical - Boolean indicating a canonical or non-canonical encoding should be produced as defined in the X.693 standard.
size - The initial size in bytes of an encode buffer. If this parameter is set to zero, the default size will be used.
Method Detail

binDump

public void binDump(java.io.PrintStream out,
                    java.lang.String varName)
This method dumps the encoded message in a human-readable format showing a bit trace of all fields to the given print output stream.

Specified by:
binDump in class Asn1EncodeBuffer

copy

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

Specified by:
copy in interface Asn1XmlXerEncoder
Specified by:
copy in class Asn1EncodeBuffer
Parameters:
value - The byte value to copy

copy

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

Specified by:
copy in interface Asn1XmlXerEncoder
Specified by:
copy in class Asn1EncodeBuffer
Parameters:
value - Array of bytes to copy to the encode buffer
Throws:
Asn1Exception - Thrown, if operation is failed.

copy

public void copy(byte[] value,
                 int off,
                 int len)
          throws Asn1Exception
This method copies multiple bytes to the encode buffer. 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 encode buffer
off - Starting offset in array
len - The length to be encoded
Throws:
Asn1Exception - Thrown, if operation is failed.

copy

public void copy(java.lang.String value)
          throws Asn1Exception
This method copies a character string to the encode buffer.

Specified by:
copy in interface Asn1XmlXerEncoder
Parameters:
value - The string value to copy
Throws:
Asn1Exception - Thrown, if operation is failed.

decrLevel

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

Specified by:
decrLevel in interface Asn1XmlXerEncoder

encodeByte

public void encodeByte(byte value)
This method is used to encode a single byte to the encode buffer. It first converts the byte to a hex character representation and then copies it to the output buffer.

Parameters:
value - The byte value to copy

encodeData

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

Specified by:
encodeData in interface Asn1XmlXerEncoder
Parameters:
value - String value to encode
Throws:
Asn1Exception - Thrown, if operation is failed.

encodeBinStrValue

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

Specified by:
encodeBinStrValue in interface Asn1XmlXerEncoder
Parameters:
bits - Bit string to encode
Throws:
Asn1Exception - Thrown, if operation is failed.

encodeHexStrValue

public void encodeHexStrValue(byte[] data)
                       throws Asn1Exception
This method encodes XML hexadecimal string data

Specified by:
encodeHexStrValue in interface Asn1XmlXerEncoder
Parameters:
data - Data to encode
Throws:
Asn1Exception - Thrown, if operation is failed.

encodeEndDocument

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

Specified by:
encodeEndDocument in interface Asn1XmlXerEncoder
Throws:
Asn1Exception - Thrown, if operation is failed.

encodeEndElement

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

Specified by:
encodeEndElement in interface Asn1XerEncoder
Parameters:
elemName - The name of element.
Throws:
Asn1Exception - Thrown, if operation is failed.

encodeStartDocument

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

Specified by:
encodeStartDocument in interface Asn1XmlXerEncoder
Throws:
Asn1Exception - Thrown, if operation is failed.

encodeStartElement

public void encodeStartElement(java.lang.String elemName)
                        throws Asn1Exception
This method encodes an XML start element tag

Specified by:
encodeStartElement in interface Asn1XerEncoder
Parameters:
elemName - The name of element.
Throws:
Asn1Exception - Thrown, if operation is failed.

encodeEmptyElement

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

Specified by:
encodeEmptyElement in interface Asn1XerEncoder
Parameters:
elemName - The name of element.
Throws:
Asn1Exception - Thrown, if operation is failed.

encodeNamedValueElement

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

Specified by:
encodeNamedValueElement in interface Asn1XmlXerEncoder
Parameters:
elemName - The name of element.
Throws:
Asn1Exception - Thrown, if operation is failed.

encodeRealValue

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

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

getBuffer

public byte[] getBuffer()
This method returns a reference to the byte buffer used to hold the encoded message.

Returns:
Byte buffer reference

getMsgCopy

public byte[] getMsgCopy()
This method returns the encoded message in a byte array.

Specified by:
getMsgCopy in class Asn1EncodeBuffer
Returns:
byte array containing encoded message

getMsgLength

public int getMsgLength()
This method returns the length (in bytes) of the encoded message component.

Specified by:
getMsgLength in class Asn1EncodeBuffer
Returns:
length of encoded message component

getInputStream

public java.io.InputStream getInputStream()
This method returns an input stream object reference to the message buffer contents (i.e. the encoded data). If an output stream was selected as the output method, this method returns null.

Specified by:
getInputStream in class Asn1MessageBuffer
Returns:
Input stream object reference

getState

public int getState()
This method gets the state of the buffer.

Specified by:
getState in interface Asn1XerEncoder
Returns:
Buffer Stat

incrLevel

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

Specified by:
incrLevel in interface Asn1XmlXerEncoder

indent

public void indent()
            throws Asn1Exception
This methods indents by adding a new-line followed by whitespace corresponding to the current nesting level to the encode buffer.

Specified by:
indent in interface Asn1XmlXerEncoder
Throws:
Asn1Exception - Thrown, if operation is failed.

reset

public void reset()
This method resets the buffer to allow a new record to be encoded into it. Any previously encoded data is lost.

Specified by:
reset in class Asn1EncodeBuffer

setCanonical

public void setCanonical(boolean value)
This method sets the canonical encoding flag to the given value.

Parameters:
value - Canonical encoding flag.

write

public void write(java.io.OutputStream out)
           throws java.io.IOException
This method writes the encoded record to the given output stream.

Specified by:
write in class Asn1EncodeBuffer
Parameters:
out - Output stream to which record is to be written
Throws:
java.io.IOException

setState

public void setState(int stat)
This method sets the state of the buffer.

Specified by:
setState in interface Asn1XerEncoder
Parameters:
stat - Buffer Stat

encodeNamedValue

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

Specified by:
encodeNamedValue in interface Asn1XerEncoder
Parameters:
valueName - The name of value.
elemName - The name of element.
Throws:
Asn1Exception - Thrown, if operation is failed.