/** * Main method. * * @param args should contain the options of a Saver. */ public static void main(String[] args) { runFileSaver(new JSONSaver(), args); } }
/** * Resets the Saver. */ @Override public void resetOptions() { super.resetOptions(); if (getCompressOutput()) { setFileExtension(JSONLoader.FILE_EXTENSION_COMPRESSED); } else { setFileExtension(JSONLoader.FILE_EXTENSION); } }
/** * Constructor. */ public JSONSaver() { resetOptions(); }
if (getInstances() == null) { throw new IOException("No instances to save"); if (getRetrieval() == INCREMENTAL) { throw new IOException("Batch and incremental saving cannot be mixed."); setRetrieval(BATCH); setWriteMode(WRITE); if ((retrieveFile() == null) && (getWriter() == null)) { outW = new PrintWriter(System.out); } else { outW = new PrintWriter(getWriter()); JSONNode json = JSONInstances.toJSON(getInstances()); StringBuffer buffer = new StringBuffer(); json.toString(buffer); outW.flush(); if (getWriter() != null) { outW.close(); setWriteMode(WAIT); outW = null; resetWriter(); setWriteMode(CANCEL);
/** * returns the saver used in the tests. * * @return the configured saver */ public AbstractSaver getSaver() { return new JSONSaver(); }
/** * returns the options of the current setup. * * @return the current options */ @Override public String[] getOptions() { Vector<String> result = new Vector<String>(); if (getClassIndex().length() != 0) { result.add("-C"); result.add(getClassIndex()); } if (getCompressOutput()) { result.add("-compress"); } Collections.addAll(result, super.getOptions()); return result.toArray(new String[result.size()]); }
/** * Sets the destination output stream. * * @param output the output stream. * @throws IOException throws an IOException if destination cannot be set */ @Override public void setDestination(OutputStream output) throws IOException { if (getCompressOutput()) { super.setDestination(new GZIPOutputStream(output)); } else { super.setDestination(output); } }
if (getInstances() == null) { throw new IOException("No instances to save"); if (getRetrieval() == INCREMENTAL) { throw new IOException("Batch and incremental saving cannot be mixed."); setRetrieval(BATCH); setWriteMode(WRITE); if ((retrieveFile() == null) && (getWriter() == null)) { outW = new PrintWriter(System.out); } else { outW = new PrintWriter(getWriter()); JSONNode json = JSONInstances.toJSON(getInstances()); StringBuffer buffer = new StringBuffer(); json.toString(buffer); outW.flush(); if (getWriter() != null) { outW.close(); setWriteMode(WAIT); outW = null; resetWriter(); setWriteMode(CANCEL);
/** * returns the saver used in the tests. * * @return the configured saver */ public AbstractSaver getSaver() { return new JSONSaver(); }
/** * returns the options of the current setup. * * @return the current options */ @Override public String[] getOptions() { Vector<String> result = new Vector<String>(); if (getClassIndex().length() != 0) { result.add("-C"); result.add(getClassIndex()); } if (getCompressOutput()) { result.add("-compress"); } Collections.addAll(result, super.getOptions()); return result.toArray(new String[result.size()]); }
/** * Sets the destination output stream. * * @param output the output stream. * @throws IOException throws an IOException if destination cannot be set */ @Override public void setDestination(OutputStream output) throws IOException { if (getCompressOutput()) { super.setDestination(new GZIPOutputStream(output)); } else { super.setDestination(output); } }
/** * Main method. * * @param args should contain the options of a Saver. */ public static void main(String[] args) { runFileSaver(new JSONSaver(), args); } }
/** * Resets the Saver. */ @Override public void resetOptions() { super.resetOptions(); if (getCompressOutput()) { setFileExtension(JSONLoader.FILE_EXTENSION_COMPRESSED); } else { setFileExtension(JSONLoader.FILE_EXTENSION); } }
/** * Constructor. */ public JSONSaver() { resetOptions(); }