2 * Copyright 2011-2012 BitMeister Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package jp.bitmeister.asn1.sample;
18 import java.io.ByteArrayInputStream;
19 import java.io.ByteArrayOutputStream;
21 import jp.bitmeister.asn1.codec.ber.BerDecoder;
22 import jp.bitmeister.asn1.codec.ber.BerEncoder;
23 import jp.bitmeister.asn1.codec.ber.DerEncoder;
24 import jp.bitmeister.asn1.codec.xer.XerDecoder;
25 import jp.bitmeister.asn1.codec.xer.XerEncoder;
26 import jp.bitmeister.asn1.exception.ASN1DecodingException;
27 import jp.bitmeister.asn1.exception.ASN1EncodingException;
28 import jp.bitmeister.asn1.sample.FrightStatusTypes.Airport;
29 import jp.bitmeister.asn1.sample.FrightStatusTypes.AllFrights;
30 import jp.bitmeister.asn1.sample.FrightStatusTypes.FrightNumber;
31 import jp.bitmeister.asn1.sample.FrightStatusTypes.Information;
32 import jp.bitmeister.asn1.sample.FrightStatusTypes.Status;
33 import jp.bitmeister.asn1.type.ASN1Type;
34 import jp.bitmeister.asn1.type.builtin.INTEGER;
35 import jp.bitmeister.asn1.type.useful.UTCTime;
36 import jp.bitmeister.asn1.value.HexString;
38 public class FrightStatusMain {
40 public static void main(String[] args) {
41 AllFrights frights = new AllFrights(
43 new FrightNumber("JP041"),
45 new Airport(Airport.tokyo),
46 new UTCTime("110627073000"),
47 new UTCTime("110627073000")
50 new Airport(Airport.osaka),
51 new UTCTime("110627090000"),
56 new FrightNumber("NI022"),
58 new Airport(Airport.fukuoka),
59 new UTCTime("110627080000"),
60 new UTCTime("110627081000")
63 new Airport(Airport.nagoya),
64 new UTCTime("110627093000"),
67 new Status(new INTEGER(10))
71 System.out.println("Source data:");
72 System.out.println(frights);
73 derEncAndDec(frights);
74 xerEncAndDec(frights);
77 static void derEncAndDec(ASN1Type data) {
78 System.out.println("BER encoding:");
79 ByteArrayOutputStream bo = new ByteArrayOutputStream();
80 BerEncoder enc = new DerEncoder(bo);
83 } catch (ASN1EncodingException e) {
87 System.out.println(new HexString(bo.toByteArray()));
89 ByteArrayInputStream bi = new ByteArrayInputStream(bo.toByteArray());
90 BerDecoder dec = new BerDecoder(FrightStatusTypes.class, bi);
92 ASN1Type result = dec.decode();
93 System.out.println("BER decoding:");
94 System.out.println(result);
95 } catch (ASN1DecodingException e) {
101 static void xerEncAndDec(ASN1Type data) {
103 System.out.println("XER encoding:");
104 ByteArrayOutputStream bo = new ByteArrayOutputStream();
105 XerEncoder enc = new XerEncoder(bo);
108 } catch (ASN1EncodingException e) {
111 System.out.println(new String(bo.toByteArray()));
113 ByteArrayInputStream bi = new ByteArrayInputStream(bo.toByteArray());
114 XerDecoder dec = new XerDecoder(FrightStatusTypes.class, bi);
116 ASN1Type result = dec.decode();
117 System.out.println("XER decoding:");
118 System.out.println(result);
119 } catch (ASN1DecodingException e) {