<data.xml> <kColl id="personData"> <field id="name" /> <field id="age" /> </kColl> </data.xml>
<context.xml> <context id="sampleContext" type="op"> <refKColl refId="personData" /> </context> </context.xml>
<format.xml> <format id="PersonFormat"> <record> <fString dataName="name" encoding="cp937"/> <selfLength/> <fInteger dataName="age" byteOrdering="host"/> <selfLength/> </record> </format> </format.xml>
public static void main(String[] args) throws Exception { Context context = ContextFactory.createContext("sampleContext"); context.setValueAt("name", "George. Wilhelm. T"); context.setValueAt("age", 57); FormatElement format = FormatFactory.getFormatElement("PersonFormat"); ReadAdapter read = new ContextReadAdapter(context); Message msg = format.format(read); System.out.println("====Format Result===="); System.out.println(msg); }If you run this main method, you can get the following result in the console:
Read BTT configuration from : "jar:///btt.xml" Initialize BTT Component: traces Initialize BTT Component: traces [Success] Initialize BTT Component: dataElement Initialize BTT Component: dataElement [Success] Initialize BTT Component: context Initialize BTT Component: context [Success] Initialize BTT Component: format Initialize BTT Component: format [Success] 4 BTT Components initialized. ====Format Result==== 12C785969987854B40E68993888593944B40E30400000039
public static void main(String[] args) throws Exception { Context context = ContextFactory.createContext("sampleContext"); FormatElement format = FormatFactory.getFormatElement("PersonFormat"); WriteAdapter write = new ContextWriteAdapter(context); byte[] bytes = HexCodecUtil.decodeHex("06C785969987850400000012".toCharArray()); Message message = new Message(bytes); format.unformat(message, write); System.out.println("====Unformat Result===="); System.out.println(context.getKeyedCollection()); }
Read BTT configuration from : "jar:///btt.xml" Initialize BTT Component: traces Initialize BTT Component: traces [Success] Initialize BTT Component: dataElement Initialize BTT Component: dataElement [Success] Initialize BTT Component: context Initialize BTT Component: context [Success] Initialize BTT Component: format Initialize BTT Component: format [Success] 4 BTT Components initialized. ====Unformat Result==== <kColl id="personData" dynamic="false" compress="false"> <field id="name" value="George" description="" /> <field id="age" value="18" description="" /> </kColl>