Developing OTDs for Application Adapters

marshal() Method

The marshal() method serializes the OTD’s content as an array of bytes. The content is encoded with the OTD’s current encoding, which is the encoding specified when data was last unmarshaled (see setEncoding() and unmarshal() for additional details). If no data was unmarshaled prior to a marshal call, then the OTD defaults to EBCDIC CP037 encoding. If the OTD content is incompatible with the current encoding (this can happen when data was unmarshaled with a different encoding than the current one), a com.stc.otd.runtime.MarshalException occurs.

Table 1–2 marshal() Method

Syntax 

Throws 

Examples 

byte [] marshal() 

MarshalException, IOException, UnsupportedEncodingException 

// populate OTD and marshal entire content in EBCDIC 

OTD_1.setField1(... 

OTD_1.setField2(... 

... 

byte[] output = OTD_1.marshal(); 

// write ASCII data to OTD 

// edit some fields 

// marshal OTD data (still ASCII) 

byte[] content = ... 

OTD_1.unmarshal(content, "US-ASCII"); 

OTD_1.setField9(... 

OTD_1.setField10(... 

byte[] output = OTD_1.marshal(); 

// write ASCII data to OTD 

// edit some fields 

// marshal OTD data using different encoding (may fail depending on data) 

byte[] content = ... 

OTD_1.unmarshal(content, "US-ASCII"); 

OTD_1.setField9(... 

OTD_1.setField10(... 

OTD_1.useEncoding("CP277"); 

byte[] output = OTD_1.marshal();