KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lowagie > bc > asn1 > ASN1Encodable


1 package com.lowagie.bc.asn1;
2
3 import java.io.ByteArrayOutputStream;
4 import java.io.IOException;
5
6 /**
7  * Abstract Syntax Notation One (ASN.1) is a formal language for abstractly describing messages to be exchanged between distributed computer systems.
8  */

9 public abstract class ASN1Encodable
10     implements DEREncodable
11 {
12     /**
13      * Encodes the ASN1Encodable object.
14      * @return an encoded bytearray
15      * @throws IOException
16      */

17     public byte[] getEncoded()
18         throws IOException
19     {
20         ByteArrayOutputStream bOut = new ByteArrayOutputStream();
21         ASN1OutputStream aOut = new ASN1OutputStream(bOut);
22         
23         aOut.writeObject(this);
24         
25         return bOut.toByteArray();
26     }
27     
28     /**
29      * @see java.lang.Object#hashCode()
30      */

31     public int hashCode()
32     {
33         return this.getDERObject().hashCode();
34     }
35
36     /**
37      * @see java.lang.Object#equals(java.lang.Object)
38      */

39     public boolean equals(
40         Object o)
41     {
42         if ((o == null) || !(o instanceof DEREncodable))
43         {
44             return false;
45         }
46
47         DEREncodable other = (DEREncodable)o;
48
49         return this.getDERObject().equals(other.getDERObject());
50     }
51
52     /**
53      * @see com.lowagie.bc.asn1.DEREncodable#getDERObject()
54      */

55     public DERObject getDERObject()
56     {
57         return this.toASN1Object();
58     }
59
60     /**
61      * Abstract method that returns the object as an ASN1 object.
62      * @return an encodable object
63      */

64     public abstract DERObject toASN1Object();
65 }
66
Popular Tags