com.objsys.asn1j.runtime
Class Asn1CerOutputStream

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

public class Asn1CerOutputStream
extends Asn1BerOutputStream

This class implements the output stream to encode ASN.1 messages as specified in the Canonical Encoding Rules (CER) 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.Asn1OutputStream
os
 
Constructor Summary
Asn1CerOutputStream(java.io.OutputStream os)
          This constructor creates a CER output stream object with default size of buffer.
Asn1CerOutputStream(java.io.OutputStream os, int bufSize)
          This constructor creates a buffered CER output stream object.
 
Method Summary
 void encode(Asn1Type object, boolean explicit)
          This method encodes and writes to the stream ASN.1 types.
 void encodeBitString(byte[] value, int numbits, boolean explicit, Asn1Tag tag)
          This method writes the given array of bytes as bit string value.
 void encodeBMPString(java.lang.String value, boolean explicit, Asn1Tag tag)
          This method writes the given string as BMP string value.
 void encodeCharString(java.lang.String value, boolean explicit, Asn1Tag tag)
          This method encodes and writes to the stream an ASN.1 8-bit character string types including IA5String, PrintableString, NumericString, etc.
 void encodeOctetString(byte[] value, boolean explicit, Asn1Tag tag)
          This method writes the given array of bytes as octet string value.
 void encodeStringTag(int nbytes, Asn1Tag tag)
          This method encodes and writes both a tag and length value to the stream.
 void encodeStringTag(int nbytes, short tagClass, short tagForm, int tagIDCode)
          This method encodes and writes both a tag and length value to the stream.
 void encodeUnivString(int[] value, boolean explicit, Asn1Tag tag)
          This method writes the given array of integers as UniversalString value.
 boolean isBER()
          This method is used for testing encode rules type.
 
Methods inherited from class com.objsys.asn1j.runtime.Asn1BerOutputStream
encodeEOC, encodeIdentifier, encodeIntValue, encodeLength, encodeTag, encodeTag, encodeTagAndIndefLen, encodeTagAndIndefLen, encodeTagAndLength
 
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
 

Constructor Detail

Asn1CerOutputStream

public Asn1CerOutputStream(java.io.OutputStream os)
This constructor creates a CER output stream object with default size of buffer. Whenever the buffer becomes full, the buffer will be flushed to the stream. Note: in Java ME environment, the stream is not buffered.

Parameters:
os - The underlying OutputStream object.

Asn1CerOutputStream

public Asn1CerOutputStream(java.io.OutputStream os,
                           int bufSize)
This constructor creates a buffered CER output stream object. Whenever the buffer becomes full, the buffer will be flushed to the stream. Note: in Java ME environment, the stream is not buffered.

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

encodeBMPString

public void encodeBMPString(java.lang.String value,
                            boolean explicit,
                            Asn1Tag tag)
                     throws Asn1Exception,
                            java.io.IOException
This method writes the given string as BMP string value.

Overrides:
encodeBMPString in class Asn1BerOutputStream
Parameters:
value - String containing data to encode.
explicit - Flag indicating explicit tagging should be done
tag - Universal tag to apply
Throws:
java.io.IOException - Any exception thrown by the underlying OutputStream.
Asn1Exception - Thrown, if operation is failed.

encodeBitString

public void encodeBitString(byte[] value,
                            int numbits,
                            boolean explicit,
                            Asn1Tag tag)
                     throws Asn1Exception,
                            java.io.IOException
This method writes the given array of bytes as bit string value.

Overrides:
encodeBitString in class Asn1BerOutputStream
Parameters:
value - Byte array containing data to encode.
numbits - Number of bits to encode
explicit - Flag indicating explicit tagging should be done
tag - Universal tag to apply
Throws:
java.io.IOException - Any exception thrown by the underlying OutputStream.
Asn1Exception - Thrown, if operation is failed.

encodeCharString

public void encodeCharString(java.lang.String value,
                             boolean explicit,
                             Asn1Tag tag)
                      throws Asn1Exception,
                             java.io.IOException
This method encodes and writes to the stream an ASN.1 8-bit character string types including IA5String, PrintableString, NumericString, etc. The UNIVERSAL tag value and length is also encoded if explicit tagging is specified (the universal identifier must be provided by the caller).

Overrides:
encodeCharString in class Asn1BerOutputStream
Parameters:
value - The string object to be written
explicit - Flag indicating explicit tagging should be done
tag - Universal tag to apply
Throws:
java.io.IOException - Any exception thrown by the underlying OutputStream.
Asn1Exception - Thrown, if operation is failed.

encodeOctetString

public void encodeOctetString(byte[] value,
                              boolean explicit,
                              Asn1Tag tag)
                       throws Asn1Exception,
                              java.io.IOException
This method writes the given array of bytes as octet string value.

Overrides:
encodeOctetString in class Asn1BerOutputStream
Parameters:
value - Byte array containing data to encode.
explicit - Flag indicating explicit tagging should be done
tag - Universal tag to apply
Throws:
java.io.IOException - Any exception thrown by the underlying OutputStream.
Asn1Exception - Thrown, if operation is failed.

encodeStringTag

public void encodeStringTag(int nbytes,
                            Asn1Tag tag)
                     throws java.io.IOException
This method encodes and writes both a tag and length value to the stream.

Parameters:
nbytes - The number of bytes in string to be encoded.
tag - The tag to be encoded.
Throws:
java.io.IOException - Any exception thrown by the underlying OutputStream.

encodeStringTag

public void encodeStringTag(int nbytes,
                            short tagClass,
                            short tagForm,
                            int tagIDCode)
                     throws java.io.IOException
This method encodes and writes both a tag and length value to the stream.

Parameters:
nbytes - The number of bytes in string to be encoded.
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.
Throws:
java.io.IOException - Any exception thrown by the underlying OutputStream.

encodeUnivString

public void encodeUnivString(int[] value,
                             boolean explicit,
                             Asn1Tag tag)
                      throws Asn1Exception,
                             java.io.IOException
This method writes the given array of integers as UniversalString value.

Overrides:
encodeUnivString in class Asn1BerOutputStream
Parameters:
value - Array containing data to encode.
explicit - Flag indicating explicit tagging should be done
tag - Universal tag to apply
Throws:
java.io.IOException - Any exception thrown by the underlying OutputStream.
Asn1Exception - Thrown, if operation is failed.

encode

public void encode(Asn1Type object,
                   boolean explicit)
            throws java.io.IOException,
                   Asn1Exception
This method encodes and writes to the stream ASN.1 types. The UNIVERSAL tag value and length is also encoded if explicit tagging is specified (the universal identifier must be provided by the caller).

Overrides:
encode in class Asn1BerOutputStream
Parameters:
object - The object to be written
explicit - Flag indicating explicit tagging should be done
Throws:
java.io.IOException - Any exception thrown by the underlying OutputStream.
Asn1Exception

isBER

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

Overrides:
isBER in class Asn1BerOutputStream