In Niagara Ax, a bog file is nothing but a zipped xml. Whenever we need to serialize a BComponent as a file in the station files structure, we can use the below code to achieve the same.
/** Copy a BComponent to a bogFile @param comp : The source component @param bogFile : The bogfile to be persisted to. */ public static void copyComponentToBog(BComponent comp,BIFile bogFile) throws IOException { BogEncoder bogencoder = new BogEncoder(bogFile.getOutputStream()); bogencoder.setZipped(true); bogencoder.encodeDocument(comp); bogencoder.close(); }
Vice-verse, to decode or convert a bog file to a component you can use BodDecoder class as shown below.
/** * Decode a bog file and return its BComponent object. * @param sourceFile : The source bog file * @return BComponent * @throws Exception */ public static BComponent bogFileToComponent(BIFile sourceFile throws Exception { BogDecoder bogDec = null; try{ BogDecoder bogDec = new BogDecoder(file); BComponent component = ((BComponent)(bogDec.decodeDocument())); }finally{ if(null != bogDec){ bogDec.close(); } } return component; }
Disclaimer: Niagara Ax tips in this website are sourced from the Open Niagara Ax online community http://www.niagara-central.com/ . A forum where you can ask and resolve Niagara framework related queries.