com.objsys.asn1j.runtime
Class Asn1BerEncodeBuffer

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.Asn1BerEncodeBuffer
Direct Known Subclasses:
Asn1DerEncodeBuffer

public class Asn1BerEncodeBuffer
extends Asn1EncodeBuffer

This class handles the encoding of ASN.1 messages as specified in the Basic Encoding Rules (BER) as specified in the ITU-T X.690 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.Asn1EncodeBuffer
INITIAL_SIZE, mByteIndex, mData
 
Fields inherited from class com.objsys.asn1j.runtime.Asn1MessageBufferBase
context, mTypeCode
 
Constructor Summary
Asn1BerEncodeBuffer()
          This constructor creates a BER encode buffer object with the default initial size.
Asn1BerEncodeBuffer(int size)
          This constructor creates a BER encode buffer object with the given initial size.
 
Method Summary
 void binDump()
           
 void binDump(java.io.PrintStream out, java.lang.String varName)
          This method dumps the encoded message in a human-readable format showing tags and contents to the given print output stream.
protected  void checkSize(int bytesRequired)
          This method determines if the encode buffer can hold the requested number of bytes.
 void copy(byte value)
          This method copies 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 startOffset, int length)
          This method copies multiple bytes to the encode buffer
 void copy(java.lang.String value)
          This method copies a character string into the encode buffer
 int encodeIdentifier(int ident)
          This method encodes an ASN.1 identifier value such as the ones used in a tags or object identifiers.
 int encodeIntValue(long ivalue)
          This method encodes an ASN.1 integer value's contents according to the ASN.1 Basic Encoding Rules (BER)..
 int encodeLength(int len)
          This method encodes a length value.
 int encodeTag(Asn1Tag tag)
          This method encodes a tag value.
 int encodeTag(short tagClass, short tagForm, int tagIdent)
          This method encodes a tag value.
 int encodeTagAndLength(Asn1Tag tag, int len)
          This method encodes both a tag and length value.
 int encodeTagAndLength(short tagClass, short tagForm, int tagIDCode, int len)
          This overloaded version of encodeTagAndLength allows tag value components to be specified instead of an Asn1Tag object
 java.io.ByteArrayInputStream getByteArrayInputStream()
          This method returns a reference to a byte array input stream representing the encoded message.
 java.io.InputStream getInputStream()
          This method returns an input stream representing the encoded message.
 byte[] getMsgCopy()
          This method returns the encoded message in a byte array.
 int getMsgLength()
          This method returns the length of the encoded message component.
 boolean isBER()
          This method is used for testing encode rules type.
 void reset()
          This method resets the buffer to allow a new record to be encoded into it.
 java.lang.String toString()
          This method will return a string representation of the data in the encode 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, 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, wait, wait, wait
 

Constructor Detail

Asn1BerEncodeBuffer

public Asn1BerEncodeBuffer()
This constructor creates a BER encode buffer object with the default initial size. Whenever the buffer becomes full, it will be expanded.


Asn1BerEncodeBuffer

public Asn1BerEncodeBuffer(int size)
This constructor creates a BER encode buffer object with the given initial size. Whenever the buffer becomes full, it will be expanded. For best performance, this size should be large enough to prevent resizing in normal operation.

Parameters:
size - The initial size in bytes of an encode buffer.
Method Detail

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 treats mByteIndex as unused and reflects the fact that BER writes into the buffer from right to left.

Overrides:
checkSize in class Asn1EncodeBuffer
Parameters:
bytesRequired - Number of required bytes.

copy

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

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

Specified by:
copy in class Asn1EncodeBuffer
Parameters:
value - Array of bytes to copy to the encode buffer
Throws:
Asn1Exception

copy

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

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

copy

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

Parameters:
value - String to copy to the encode buffer

encodeIdentifier

public int encodeIdentifier(int ident)
This method encodes an ASN.1 identifier value such as the ones used in a tags or object identifiers.

Parameters:
ident - The identifier to be encoded.
Returns:
Length of the encoded component in octets.

encodeIntValue

public int encodeIntValue(long ivalue)
This method encodes an ASN.1 integer value's contents according to the ASN.1 Basic Encoding Rules (BER)..

Parameters:
ivalue - Integer value to encode
Returns:
Length of encoded component

encodeLength

public int encodeLength(int len)
This method encodes a length value.

Parameters:
len - The length to be encoded.
Returns:
Length of encoded component

encodeTag

public int encodeTag(Asn1Tag tag)
This method encodes a tag value.

Parameters:
tag - The tag to be encoded.
Returns:
Length of component or negative status value

encodeTag

public int encodeTag(short tagClass,
                     short tagForm,
                     int tagIdent)
This method encodes a tag value.

Parameters:
tagClass - Tag class value (UNIV, APPL, CTXT, or PRIV)
tagForm - Tag form value (PRIM or CONS)
tagIdent - Tag identifer code
Returns:
Length of component or negative status value

encodeTagAndLength

public int encodeTagAndLength(Asn1Tag tag,
                              int len)
This method encodes both a tag and length value.

Parameters:
tag - The tag to be encoded.
len - The length to be encoded.
Returns:
Length of encoded component

encodeTagAndLength

public int encodeTagAndLength(short tagClass,
                              short tagForm,
                              int tagIDCode,
                              int len)
This overloaded version of encodeTagAndLength allows tag value components to be specified instead of an Asn1Tag object

Parameters:
tagClass - The class of the tag to be encoded.
tagForm - The form of the tag to be encoded.
tagIDCode - The ID code of the tag to be encoded.
len - The length to be encoded.
Returns:
status value (see Asn1Status.java)

getByteArrayInputStream

public java.io.ByteArrayInputStream getByteArrayInputStream()
This method returns a reference to a byte array input stream representing the encoded message. This is the preferred way to access the contents of the encoded message as it is the most efficient.

Returns:
byte array input stream containing encoded message

getInputStream

public java.io.InputStream getInputStream()
This method returns an input stream representing the encoded message. This is a method defined as abstract in the base class that must be implemented by all derived classes. In this case, a byte array input stream is returned.

Specified by:
getInputStream in class Asn1MessageBuffer
Returns:
Input stream containing encoded message

getMsgCopy

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

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

getMsgLength

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

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

binDump

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

Specified by:
binDump in class Asn1EncodeBuffer

binDump

public void binDump()

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

toString

public java.lang.String toString()
This method will return a string representation of the data in the encode buffer. The format is hex characters.

Overrides:
toString in class java.lang.Object
Returns:
Stringified representation of the value

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

isBER

public boolean isBER()
This method is used for testing encode rules type.