Procedure for Calling Java MDER Decode Methods

The general procedure to decode an ASN.1 MDER message involves the following three steps:

  1. Create a decode buffer on the message to be decoded

  2. Invoke the decode method

  3. Process the decoded data values

The first step is the creation of a decode buffer. Asn1MderDecodeBuffer has a constructor that accepts messages stored in a byte array. It also has a constructor that accepts a java.io.InputStream so that messages may be streamed from various sources, such as from a file.

The second step is to invoke the generated decode method. The calling arguments were described earlier.

The final step is to apply your application-specific processing to the data. All data is contained within public member variables so access is quite easy.

A complete example showing how to invoke a decode method is as follows:

   try {
      // Step 1: create a decode buffer for the message to be decoded. 
      // This example will use a file input stream to decode a message
      // in a binary file.

      // Create an input file stream object
      FileInputStream ins = new FileInputStream (filename);

      // Create a decode buffer object
      Asn1MderDecodeBuffer decodeBuffer = new Asn1MderDecodeBuffer (ins);

      // Step 2: create an object of the generated type and invoke the
      // decode method..
      PersonnelRecord personnelRecord = new PersonnelRecord ();
      personnelRecord.decode (decodeBuffer);

      // Step 3: process the data
      if (trace) {
         System.out.println ("Decode was successful");
         personnelRecord.print (System.out, "personnelRecord", 0);
      }
   }
   catch (Exception e) {
      System.out.println (e.getMessage());
      e.printStackTrace();
      return;
   }