/** * @param options "compact" and "indent=N", replace N with the number of spaces */ public boolean saveJSONObject(JSONObject json, String filename, String options) { return json.save(saveFile(filename), options); }
/** * @nowebref */ public boolean saveStream(String target, InputStream source) { return saveStream(saveFile(target), source); }
/** * Save the contents of a stream to a file in the sketch folder. * This is basically saveBytes(blah, loadBytes()), but done * more efficiently (and with less confusing syntax). */ public boolean saveStream(String targetFilename, String sourceLocation) { return saveStream(saveFile(targetFilename), sourceLocation); }
/** * @param options "compact" and "indent=N", replace N with the number of spaces */ public boolean saveJSONArray(JSONArray json, String filename, String options) { return json.save(saveFile(filename), options); }
/** * @nowebref */ public boolean saveJSONObject(JSONObject json, String filename, String options) { return json.save(saveFile(filename), options); }
public boolean saveTable(Table table, String filename, String options) { try { table.save(saveFile(filename), options); return true; } catch (IOException e) { e.printStackTrace(); } return false; }
/** * Saves bytes to a file to inside the sketch folder. * The filename can be a relative path, i.e. "poo/bytefun.txt" * would save to a file named "bytefun.txt" to a subfolder * called 'poo' inside the sketch folder. If the in-between * subfolders don't exist, they'll be created. */ public void saveBytes(String filename, byte buffer[]) { saveBytes(saveFile(filename), buffer); }
/** * @nowebref */ public boolean saveXML(XML xml, String filename, String options) { return xml.save(saveFile(filename), options); }
/** * I want to print lines to a file. Why can't I? */ public PrintWriter createWriter(String filename) { return createWriter(saveFile(filename)); }
public boolean saveJSONArray(JSONArray json, String filename, String options) { return json.save(saveFile(filename), options); }
public boolean saveXML(XML xml, String filename, String options) { return xml.save(saveFile(filename), options); }
public boolean saveStream(String targetFilename, InputStream sourceStream) { return saveStream(saveFile(targetFilename), sourceStream); }
public void saveStrings(String filename, String strings[]) { saveStrings(saveFile(filename), strings); }
/** * ( begin auto-generated from saveStream.xml ) * * Save the contents of a stream to a file in the sketch folder. This is * basically <b>saveBytes(blah, loadBytes())</b>, but done more efficiently * (and with less confusing syntax).<br /> * <br /> * When using the <b>targetFile</b> parameter, it writes to a <b>File</b> * object for greater control over the file location. (Note that unlike * some other functions, this will not automatically compress or uncompress * gzip files.) * * ( end auto-generated ) * * @webref output:files * @param target name of the file to write to * @param source location to read from (a filename, path, or URL) * @see PApplet#createOutput(String) */ public boolean saveStream(String target, String source) { return saveStream(saveFile(target), source); }
/** * ( begin auto-generated from createWriter.xml ) * * Creates a new file in the sketch folder, and a <b>PrintWriter</b> object * to write to it. For the file to be made correctly, it should be flushed * and must be closed with its <b>flush()</b> and <b>close()</b> methods * (see above example). * <br/> <br/> * Starting with Processing release 0134, all files loaded and saved by the * Processing API use UTF-8 encoding. In previous releases, the default * encoding for your platform was used, which causes problems when files * are moved to other platforms. * * ( end auto-generated ) * * @webref output:files * @param filename name of the file to be created * @see PrintWriter * @see PApplet#createReader * @see BufferedReader */ public PrintWriter createWriter(String filename) { return createWriter(saveFile(filename)); }
/** * ( begin auto-generated from saveBytes.xml ) * * Opposite of <b>loadBytes()</b>, will write an entire array of bytes to a * file. The data is saved in binary format. This file is saved to the * sketch's folder, which is opened by selecting "Show sketch folder" from * the "Sketch" menu.<br /> * <br /> * It is not possible to use saveXxxxx() functions inside a web browser * unless the sketch is <a * href="http://wiki.processing.org/w/Sign_an_Applet">signed applet</A>. To * save a file back to a server, see the <a * href="http://wiki.processing.org/w/Saving_files_to_a_web-server">save to * web</A> code snippet on the Processing Wiki. * * ( end auto-generated ) * * @webref output:files * @param filename name of the file to write to * @param data array of bytes to be written * @see PApplet#loadStrings(String) * @see PApplet#loadBytes(String) * @see PApplet#saveStrings(String, String[]) */ public void saveBytes(String filename, byte[] data) { saveBytes(saveFile(filename), data); }
/** * ( begin auto-generated from createOutput.xml ) * * Similar to <b>createInput()</b>, this creates a Java <b>OutputStream</b> * for a given filename or path. The file will be created in the sketch * folder, or in the same folder as an exported application. * <br /><br /> * If the path does not exist, intermediate folders will be created. If an * exception occurs, it will be printed to the console, and <b>null</b> * will be returned. * <br /><br /> * This function is a convenience over the Java approach that requires you * to 1) create a FileOutputStream object, 2) determine the exact file * location, and 3) handle exceptions. Exceptions are handled internally by * the function, which is more appropriate for "sketch" projects. * <br /><br /> * If the output filename ends with <b>.gz</b>, the output will be * automatically GZIP compressed as it is written. * * ( end auto-generated ) * @webref output:files * @param filename name of the file to open * @see PApplet#createInput(String) * @see PApplet#selectOutput(String,String) */ public OutputStream createOutput(String filename) { return createOutput(saveFile(filename)); }
/** * ( begin auto-generated from saveStrings.xml ) * * Writes an array of strings to a file, one line per string. This file is * saved to the sketch's folder, which is opened by selecting "Show sketch * folder" from the "Sketch" menu.<br /> * <br /> * It is not possible to use saveXxxxx() functions inside a web browser * unless the sketch is <a * href="http://wiki.processing.org/w/Sign_an_Applet">signed applet</A>. To * save a file back to a server, see the <a * href="http://wiki.processing.org/w/Saving_files_to_a_web-server">save to * web</A> code snippet on the Processing Wiki.<br/> * <br/ > * Starting with Processing 1.0, all files loaded and saved by the * Processing API use UTF-8 encoding. In previous releases, the default * encoding for your platform was used, which causes problems when files * are moved to other platforms. * * ( end auto-generated ) * @webref output:files * @param filename filename for output * @param data string array to be written * @see PApplet#loadStrings(String) * @see PApplet#loadBytes(String) * @see PApplet#saveBytes(String, byte[]) */ public void saveStrings(String filename, String data[]) { saveStrings(saveFile(filename), data); }
/** * @param options can be one of "tsv", "csv", "bin", or "html" */ public boolean saveTable(Table table, String filename, String options) { // String ext = checkExtension(filename); // if (ext != null) { // if (ext.equals("csv") || ext.equals("tsv") || ext.equals("bin") || ext.equals("html")) { // if (options == null) { // options = ext; // } else { // options = ext + "," + options; // } // } // } try { // Figure out location and make sure the target path exists File outputFile = saveFile(filename); // Open a stream and take care of .gz if necessary return table.save(outputFile, options); } catch (IOException e) { printStackTrace(e); return false; } }