KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.lowagie.bc.asn1;
2
3 import java.io.ByteArrayInputStream;
4 import java.io.ByteArrayOutputStream;
5 import java.io.IOException;
6
7 /**
8  * Base class for an application specific object
9  */

10 public class DERApplicationSpecific
11     extends DERObject
12 {
13     private int tag;
14     private byte[] octets;
15     
16     public DERApplicationSpecific(
17         int tag,
18         byte[] octets)
19     {
20         this.tag = tag;
21         this.octets = octets;
22     }
23     
24     public DERApplicationSpecific(
25         int tag,
26         DEREncodable object)
27         throws IOException
28     {
29         this.tag = tag | DERTags.CONSTRUCTED;
30         
31         ByteArrayOutputStream baos = new ByteArrayOutputStream();
32         DEROutputStream dos = new DEROutputStream(baos);
33         
34         dos.writeObject(object);
35         
36         this.octets = baos.toByteArray();
37     }
38     
39     public boolean isConstructed()
40     {
41         return (tag & DERTags.CONSTRUCTED) != 0;
42     }
43     
44     public byte[] getContents()
45     {
46         return octets;
47     }
48     
49     public int getApplicationTag()
50     {
51         return tag & 0x1F;
52     }
53     
54     public DERObject getObject()
55         throws IOException
56     {
57         return new ASN1InputStream(new ByteArrayInputStream(getContents())).readObject();
58     }
59     
60     /* (non-Javadoc)
61      * @see org.bouncycastle.asn1.DERObject#encode(org.bouncycastle.asn1.DEROutputStream)
62      */

63     void encode(DEROutputStream out) throws IOException
64     {
65         out.writeEncoded(DERTags.APPLICATION | tag, octets);
66     }
67 }
68
Popular Tags