X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2FIOUtils.java;h=4a185c6386ba31b84a474540f82d78aa25d691dc;hb=7ee9568bee3caddfb837007dda09460acc145177;hp=92e312874599c6652454551bdd096cbc7b531226;hpb=b607df60a14942d9aa6383144470a237934eecfc;p=nikiroo-utils.git diff --git a/src/be/nikiroo/utils/IOUtils.java b/src/be/nikiroo/utils/IOUtils.java index 92e3128..4a185c6 100644 --- a/src/be/nikiroo/utils/IOUtils.java +++ b/src/be/nikiroo/utils/IOUtils.java @@ -202,20 +202,15 @@ public class IOUtils { * the target to delete */ public static void deltree(File target) { - for (File file : target.listFiles()) { - if (file.isDirectory()) { + File[] files = target.listFiles(); + if (files != null) { + for (File file : files) { deltree(file); - } else { - if (!file.delete()) { - System.err.println("Cannot delete file: " - + file.getAbsolutePath()); - } } } if (!target.delete()) { - System.err.println("Cannot delete file: " - + target.getAbsolutePath()); + System.err.println("Cannot delete: " + target.getAbsolutePath()); } } @@ -232,7 +227,7 @@ public class IOUtils { * @throws IOException * in case of IO error */ - static public BufferedImage toImage(InputStream in) throws IOException { + public static BufferedImage toImage(InputStream in) throws IOException { MarkableFileInputStream tmpIn = null; File tmp = null; try { @@ -329,6 +324,23 @@ public class IOUtils { return image; } + /** + * Open the given /-separated resource (from the binary root). + * + * @param name + * the resource name + * + * @return the opened resource if found, NLL if not + */ + public static InputStream openResource(String name) { + ClassLoader loader = IOUtils.class.getClassLoader(); + if (loader == null) { + loader = ClassLoader.getSystemClassLoader(); + } + + return loader.getResourceAsStream(name); + } + /** * Return the EXIF transformation flag of this image if any. * @@ -344,7 +356,7 @@ public class IOUtils { * @throws IOException * in case of IO error */ - static private int getExifTransorm(InputStream in) throws IOException { + private static int getExifTransorm(InputStream in) throws IOException { int[] exif_data = new int[100]; int set_flag = 0; int is_motorola = 0;