com.objsys.asn1j.runtime
Class Asn1EncodeBuffer

java.lang.Object
  extended by com.objsys.asn1j.runtime.Asn1MessageBufferBase
      extended by com.objsys.asn1j.runtime.Asn1MessageBuffer
          extended by com.objsys.asn1j.runtime.Asn1EncodeBuffer
Direct Known Subclasses:
Asn1BerEncodeBuffer, Asn1PerEncodeBuffer, Asn1XerEncodeBuffer, Asn1XmlEncodeBuffer

public abstract class Asn1EncodeBuffer
extends Asn1MessageBuffer

This is the base class to specific encode buffer classes for the different types of encoding rules (BER, DER and PER).


Field Summary
static int INITIAL_SIZE
          This constant specifies the default initial size of the encode buffer.
protected  int mByteIndex
           
protected  byte[] mData
           
 
Fields inherited from class com.objsys.asn1j.runtime.Asn1MessageBufferBase
context, mTypeCode
 
Method Summary
abstract  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 binDump(java.lang.String varName)
          This method invokes an overloaded version of binDump to dump the encoded message to standard output.
protected  void checkSize(int bytesRequired)
          This method determines if the encode buffer can hold the requested number of bytes.
abstract  void copy(byte value)
          This abstract method is used to copy a single byte to the encode buffer.
abstract  void copy(byte[] value)
          This method copies multiple bytes to the encode buffer
abstract  byte[] getMsgCopy()
          This method returns the encoded message in a byte array.
abstract  int getMsgLength()
          This method returns the length (in bytes) of the encoded message component.
 void hexDump()
          This method dumps the encoded message in hex/ascii format to the standard output stream.
 void hexDump(java.io.PrintStream out)
          This method dumps the encoded message in hex/ascii format to the given print output stream.
protected  void initBuffer(int size)
           
abstract  void reset()
          This method resets the buffer to allow a new record to be encoded into it.
 int trimBitString(Asn1BitString bitstr)
          This method will trim a BIT STRING for relevant encodings by removing all zero trailing bits.
abstract  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.Asn1MessageBuffer
addNamedEventHandler, getEventHandlerListCount, getInputStream, 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
 

Field Detail

mByteIndex

protected int mByteIndex

mData

protected byte[] mData

INITIAL_SIZE

public static final int INITIAL_SIZE
This constant specifies the default initial size of the encode buffer. It is currently set to 1024 bytes.

See Also:
Constant Field Values
Method Detail

binDump

public void binDump(java.lang.String varName)
This method invokes an overloaded version of binDump to dump the encoded message to standard output.


binDump

public abstract 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.


checkSize

protected void checkSize(int bytesRequired)
This method determines if the encode buffer can hold the requested number of bytes. If not, the buffer is expanded. This implementation is shared by the Xml and Xer subclasses. It assumes that the location at mByteIndex is not used, and that the array is filling from 0..n. Ber and Per override this method with slightly different behavior.

Parameters:
bytesRequired - Number of required bytes.

trimBitString

public int trimBitString(Asn1BitString bitstr)
This method will trim a BIT STRING for relevant encodings by removing all zero trailing bits. This is necessary for DER and PER when a BIT STRING contains named bits.

Parameters:
bitstr - An ASN.1 BIT STRING object.
Returns:
Adjusted bit count.

copy

public abstract void copy(byte value)
This abstract method is used to copy a single byte to the encode buffer.

Parameters:
value - The byte value to copy

copy

public abstract void copy(byte[] value)
                   throws Asn1Exception
This method copies multiple bytes to the encode buffer

Parameters:
value - Array of bytes to copy to the encode buffer
Throws:
Asn1Exception

getMsgCopy

public abstract byte[] getMsgCopy()
This method returns the encoded message in a byte array. This is less efficient than the getInputStream method because the message contents must be copied to a newly created byte array.

Returns:
byte array containing encoded message

getMsgLength

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

Returns:
length of encoded message component

hexDump

public void hexDump()
This method dumps the encoded message in hex/ascii format to the standard output stream.


hexDump

public void hexDump(java.io.PrintStream out)
This method dumps the encoded message in hex/ascii format to the given print output stream.

Parameters:
out - Output stream object reference

initBuffer

protected void initBuffer(int size)

reset

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


write

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

Parameters:
out - Output stream to which record is to be written
Throws:
java.io.IOException