public XML loadXML(String filename, String options) { try { return new XML(createInput(filename), options); } catch (Exception e) { e.printStackTrace(); return null; } }
static public String[] loadStrings(File file) { InputStream is = createInput(file); if (is != null) return loadStrings(is); return null; }
public byte[] loadBytes(String filename) { InputStream is = createInput(filename); if (is != null) return loadBytes(is); System.err.println("The file \"" + filename + "\" " + "is missing or inaccessible, make sure " + "the URL is valid or that the file has been " + "added to your sketch and is readable."); return null; }
static public byte[] loadBytes(File file) { InputStream is = createInput(file); return loadBytes(is); }
/** * @nowebref */ static public String[] loadStrings(File file) { if (!file.exists()) { System.err.println(file + " does not exist, loadStrings() will return null"); return null; } InputStream is = createInput(file); if (is != null) { String[] outgoing = loadStrings(is); try { is.close(); } catch (IOException e) { e.printStackTrace(); } return outgoing; } return null; }
/** * I want to read lines from a file. I have RSI from typing these * eight lines of code so many times. */ public BufferedReader createReader(String filename) { try { InputStream is = createInput(filename); if (is == null) { System.err.println(filename + " does not exist or could not be read"); return null; } return createReader(is); } catch (Exception e) { if (filename == null) { System.err.println("Filename passed to reader() was null"); } else { System.err.println("Couldn't create a reader for " + filename); } } return null; }
/** * Load data from a file and shove it into a String array. * <p/> * Exceptions are handled internally, when an error, occurs, an * exception is printed to the console and 'null' is returned, * but the program continues running. This is a tradeoff between * 1) showing the user that there was a problem but 2) not requiring * that all i/o code is contained in try/catch blocks, for the sake * of new users (or people who are just trying to get things done * in a "scripting" fashion. If you want to handle exceptions, * use Java methods for I/O. */ public String[] loadStrings(String filename) { InputStream is = createInput(filename); if (is != null) return loadStrings(is); System.err.println("The file \"" + filename + "\" " + "is missing or inaccessible, make sure " + "the URL is valid or that the file has been " + "added to your sketch and is readable."); return null; }
public PImage loadImage(String filename) { // return loadImage(filename, null); InputStream stream = createInput(filename); if (stream == null) { System.err.println("Could not find the image " + filename + "."); return null; } // long t = System.currentTimeMillis(); Bitmap bitmap = null; try { bitmap = BitmapFactory.decodeStream(stream); } finally { try { stream.close(); stream = null; } catch (IOException e) { } } // int much = (int) (System.currentTimeMillis() - t); // println("loadImage(" + filename + ") was " + nfc(much)); PImage image = new PImage(bitmap); image.parent = this; // if (params != null) { // image.setParams(g, params); // } return image; }
/** * ( begin auto-generated from createReader.xml ) * * Creates a <b>BufferedReader</b> object that can be used to read files * line-by-line as individual <b>String</b> objects. This is the complement * to the <b>createWriter()</b> function. * <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 input:files * @param filename name of the file to be opened * @see BufferedReader * @see PApplet#createWriter(String) * @see PrintWriter */ public BufferedReader createReader(String filename) { InputStream is = createInput(filename); if (is == null) { System.err.println("The file \"" + filename + "\" " + "is missing or inaccessible, make sure " + "the URL is valid or that the file has been " + "added to your sketch and is readable."); return null; } return createReader(is); }
public Interface(PApplet app, String cssfile) { this.app = app; root = new Widget(this); selected = null; drawnWidgets = new ArrayList<Widget>(); state = INIT; viewport = currentClip = new ClipRect(0, 0, app.width, app.height); clipStack = new Stack<ClipRect>(); imageCache = new HashMap<String, PImage>(); fontCache = new HashMap<String, PFont>(); shapeCache = new HashMap<String, PShape>(); if (cssfile != null && !cssfile.equals("")) { style = new Style(app.createInput(cssfile)); } bckColor = 0xFFFFFFFF; enabled = true; }
public Table loadTable(String filename, String options) { try { String ext = checkExtension(filename); if (ext != null) { if (ext.equals("csv") || ext.equals("tsv")) { if (options == null) { options = ext; } else { options = ext + "," + options; } } } return new Table(createInput(filename), options); } catch (IOException e) { e.printStackTrace(); return null; } }
public PFont loadFont(String filename) { try { InputStream input = createInput(filename); return new PFont(input); } catch (Exception e) { die("Could not load font " + filename + ". " + "Make sure that the font has been copied " + "to the data folder of your sketch.", e); } return null; }
protected PFont createFont(String name, float size, boolean smooth, char[] charset) { String lowerName = name.toLowerCase(); Font baseFont = null; try { InputStream stream = null; if (lowerName.endsWith(".otf") || lowerName.endsWith(".ttf")) { stream = parent.createInput(name); if (stream == null) { System.err.println("The font \"" + name + "\" " + "is missing or inaccessible, make sure " + "the URL is valid or that the file has been " + "added to your sketch and is readable."); return null; } baseFont = Font.createFont(Font.TRUETYPE_FONT, parent.createInput(name)); } else { baseFont = PFont.findFont(name); } return new PFont(baseFont.deriveFont(size * parent.pixelDensity), smooth, charset, stream != null, parent.pixelDensity); } catch (Exception e) { System.err.println("Problem with createFont(\"" + name + "\")"); e.printStackTrace(); return null; } }
/** * version that uses a File object; future releases (or data types) * may include additional optimizations here * * @nowebref */ public Table(File file, String options) throws IOException { // uses createInput() to handle .gz (and eventually .bz2) files init(); parse(PApplet.createInput(file), extensionOptions(true, file.getName(), options)); }
/** * version that uses a File object; future releases (or data types) * may include additional optimizations here * * @nowebref */ public Table(File file, String options) throws IOException { // uses createInput() to handle .gz (and eventually .bz2) files init(); parse(PApplet.createInput(file), extensionOptions(true, file.getName(), options)); }
InputStream stream = createInput(filename); if (stream == null) { System.err.println("The image " + filename + " could not be found.");
InputStream input = createInput(filename); return new PFont(input);
@Override public PShape loadShape(String filename) { String extension = PApplet.getExtension(filename); PShapeSVG svg = null; if (extension.equals("svg")) { svg = new PShapeSVG(parent.loadXML(filename)); } else if (extension.equals("svgz")) { try { InputStream input = new GZIPInputStream(parent.createInput(filename)); XML xml = new XML(input); svg = new PShapeSVG(xml); } catch (Exception e) { e.printStackTrace(); } } else { PGraphics.showWarning("Unsupported format"); } return svg; }
if (opt.startsWith("dictionary=")) { dictionary = loadTable(opt.substring(opt.indexOf('=') + 1), "tsv"); return dictionary.typedParse(createInput(filename), optionStr); InputStream input = createInput(filename); if (input == null) { System.err.println(filename + " does not exist or could not be read");
font = Font.loadFont(parent.createInput(filename), size);