KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > util > asn1 > DERConstructedSequence


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.util.asn1;
19
20 import java.io.ByteArrayOutputStream JavaDoc;
21 import java.io.IOException JavaDoc;
22 import java.util.Enumeration JavaDoc;
23
24 /**
25  * @deprecated use DERSequence.
26  */

27 public class DERConstructedSequence
28     extends ASN1Sequence
29 {
30     public void addObject(
31         DEREncodable obj)
32     {
33         super.addObject(obj);
34     }
35
36     public int getSize()
37     {
38         return size();
39     }
40
41     /*
42      * A note on the implementation:
43      * <p>
44      * As DER requires the constructed, definite-length model to
45      * be used for structured types, this varies slightly from the
46      * ASN.1 descriptions given. Rather than just outputing SEQUENCE,
47      * we also have to specify CONSTRUCTED, and the objects length.
48      */

49     void encode(
50         DEROutputStream out)
51         throws IOException JavaDoc
52     {
53         ByteArrayOutputStream JavaDoc bOut = new ByteArrayOutputStream JavaDoc();
54         DEROutputStream dOut = new DEROutputStream(bOut);
55         Enumeration JavaDoc e = this.getObjects();
56
57         while (e.hasMoreElements())
58         {
59             Object JavaDoc obj = e.nextElement();
60
61             dOut.writeObject(obj);
62         }
63
64         dOut.close();
65
66         byte[] bytes = bOut.toByteArray();
67
68         out.writeEncoded(SEQUENCE | CONSTRUCTED, bytes);
69     }
70 }
71
Popular Tags