Home | History | Annotate | Download | only in asn1
      1 package org.bouncycastle.asn1;
      2 
      3 import java.io.IOException;
      4 import java.io.OutputStream;
      5 
      6 /**
      7  * A class which writes indefinite and definite length objects,
      8  */
      9 public class BEROutputStream
     10     extends DEROutputStream
     11 {
     12     /**
     13      * Base constructor.
     14      *
     15      * @param os target output stream.
     16      */
     17     public BEROutputStream(
     18         OutputStream    os)
     19     {
     20         super(os);
     21     }
     22 
     23     /**
     24      * Write out an ASN.1 object.
     25      *
     26      * @param obj the object to be encoded.
     27      * @throws IOException if there is an issue on encoding or output of the object.
     28      */
     29     public void writeObject(
     30         Object    obj)
     31         throws IOException
     32     {
     33         if (obj == null)
     34         {
     35             writeNull();
     36         }
     37         else if (obj instanceof ASN1Primitive)
     38         {
     39             ((ASN1Primitive)obj).encode(this);
     40         }
     41         else if (obj instanceof ASN1Encodable)
     42         {
     43             ((ASN1Encodable)obj).toASN1Primitive().encode(this);
     44         }
     45         else
     46         {
     47             throw new IOException("object not BEREncodable");
     48         }
     49     }
     50 }
     51