static boolean loadBufferedImage_useImageCache = true; static BufferedImage loadBufferedImage(String snippetIDOrURLOrFile) ctex { ping(); if (snippetIDOrURLOrFile == null) ret null; if (isURL(snippetIDOrURLOrFile)) ret imageIO_readURL(snippetIDOrURLOrFile); if (isSnippetID(snippetIDOrURLOrFile)) { S snippetID = "" + parseSnippetID(snippetIDOrURLOrFile); ifndef NoResourceLoader IResourceLoader rl = vm_getResourceLoader(); if (rl != null) ret loadBufferedImage(rl.loadLibrary(snippetID)); endifndef File dir = imageSnippetsCacheDir(); if (loadBufferedImage_useImageCache) { dir.mkdirs(); File file = new File(dir, snippetID + ".png"); if (file.exists() && file.length() != 0) try { return ImageIO.read(file); } catch (Throwable e) { e.printStackTrace(); // fall back to loading from sourceforge } } String imageURL = snippetImageURL_http(snippetID); print("Loading image: " + imageURL); BufferedImage image = imageIO_readURL(imageURL); if (loadBufferedImage_useImageCache) { File tempFile = new File(dir, snippetID + ".tmp." + System.currentTimeMillis()); ImageIO.write(image, "png", tempFile); tempFile.renameTo(new File(dir, snippetID + ".png")); //Log.info("Cached image."); } //Log.info("Loaded image."); return image; } else ret loadBufferedImage(new File(snippetIDOrURLOrFile)); } static BufferedImage loadBufferedImage(File file) { ret loadBufferedImageFile(file); }