Reuse of Java Decoding Objects

The sample above showed the MDER decoding of a single message. In a typical application, a loop would be involved to decode a series of messages.

A single decode buffer can be used to process a stream of messages. If the decode buffer is created using an input stream that contains a series of messages (for example, a file containing multiple records, or a communications device), you can repeatedly invoke the MDER decode method on the given message type.

Note that you can also use the same instance of your message type for repeated decoding, rather than creating a new object and leaving the old one to be garbage collected. Nothing special needs to be done to do this. The generated decode method will automatically call the internal init() method before decoding to make sure all items are reset to their starting state.

In the example above, all that would need to be done to decode a series of personnel records is the inclusion of a loop after the PersonnelRecord object was created in step 2:

   for (;;) {
      personnelRecord.decode (decodeBuffer);

      if (trace) {
         System.out.println ("Decode was successful");
         personnelRecord.print (System.out, "personnelRecord", 0);
      }
   }