/** * Serialises the current state of the JSON configuration to the specified * writer. By default this doesn't use a pretty printer. * * @param writer a writer * @throws IOException if there was an error writing the configuration */ public void store(Writer writer) throws IOException { store(writer, false); }
/** * Serialises the current state of the JSON configuration to the specified * writer. The output can be set to be pretty printed if required. * * @param writer a writer * @param pretty use pretty printer * @throws IOException if there was an error writing the configuration */ public void store(Writer writer, boolean pretty) throws IOException { userConfig.store(writer, pretty); FileWriter sysWriter = new FileWriter(getSystemFile()); systemConfig.store(sysWriter, pretty); sysWriter.close(); }
/** * Convert Json to String * * @param pretty state to format the layout of the Json configuration file * @return Json configuration in String */ public String toString(boolean pretty) { String json = "{}"; ByteArrayOutputStream out = new ByteArrayOutputStream(); try { store(new OutputStreamWriter(out, "UTF-8"), pretty); json = out.toString("UTF-8"); } catch (IOException e) { } return json; } }