Procedure for Calling Java BER Stream-Oriented Encode Methods
Once an object's member variables have been populated, the object's encode method can be invoked to encode the value. The general procedure to do this involves the following three steps:
The first step is the creation of an output stream object. There are two forms of the constructor: a constructor with one parameter (OutputStream reference) and one that allows specification of an internal buffer size. A larger internal buffer size generally provides better performance at the expense of increased memory consumption. The first constructor sets the value to a reasonable mid-range value.
The second step is the invocation of the encode method. The calling arguments were described earlier. As per the Java standard, this method must be invoked from within a try/catch block to catch the possible Asn1Exception and java.io.IOException, which may be thrown. Alternatively, the method from which the encode method is called can declare that it throws Asn1Exception and java.io.IOException leaving it to be dealt with at a higher level.
If you compare this example with the BER encoding example in Figure 2, you will see the encoding procedure is almost identical. This makes it very easy to switch encoding methods should the need arise. All you need to do is change Asn1BerEncodeBuffer to Asn1BerOutputStream and remove the explicit code that writes the messages into the stream. Also closing of the stream should be added.
Objective Systems, Inc.102 Pickering Way, Suite #506Exton, Pennsylvania 19341 http://www.obj-sys.com Phone: (484) 875-9841 Toll-free: (877) 307-6855 (US only) Fax: (484) 875-9830 info@obj-sys.com |