Next on my "cool things to do with JiBX" is making the output compressed. XML files are text files, which can make them very large. This also makes them compress well. In our application we can send the XML datafiles and be assured that only our application will read the results. Well, most of the time.

A test datafile we use is 538K, which compresses to 26K. Fortunately this is very easy to do both from a code standpoint and from a user interaction standpoint. The key is to use the java.util.zip.GZIPInputStream and GZIPOutputStream classes as a middle layer to compress and expand the datafile.

public void read()
{
try {
IBindingFactory bfact = BindingDirectory.getFactory(Astrogation.class);
IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
if (useCompressedFile){
data = (Astrogation) uctx.unmarshalDocument(new GZIPInputStream (new FileInputStream(inputFile)), null);
} else {
data = (Astrogation) uctx.unmarshalDocument (new FileInputStream(inputFile), null);
}
}
catch (Exception ex) {ex.printStackTrace(); }
}


public void write ()
{
try {
IBindingFactory bfact = BindingDirectory.getFactory(Astrogation.class);
IMarshallingContext mctx = bfact.createMarshallingContext();
mctx.setIndent(4);
if (useCompressedFile) {
mctx.marshalDocument(data, "UTF-8", null, new GZIPOutputStream(new FileOutputStream(outputFile)));
} else {
mctx.marshalDocument(data, "UTF-8", null, new FileOutputStream(outputFile));
}
}
catch (Exception ex) { ex.printStackTrace(); }
}


--
        Thomas Jones-Low            Softstart Services Inc.
        [EMAIL PROTECTED]      JobScheduler for Oracle
        Ph: 802-398-1012            http://www.softstart.com



-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl
_______________________________________________
jibx-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to