diff -r ed84c8bdd87b -r 7f84f4de2893 src/org/sonews/util/io/Resource.java --- a/src/org/sonews/util/io/Resource.java Sun Aug 29 17:28:58 2010 +0200 +++ b/src/org/sonews/util/io/Resource.java Mon Jun 06 20:12:21 2011 +0200 @@ -32,101 +32,89 @@ */ public final class Resource { - - /** - * Loads a resource and returns it as URL reference. - * The Resource's classloader is used to load the resource, not - * the System's ClassLoader so it may be safe to use this method - * in a sandboxed environment. - * @return - */ - public static URL getAsURL(final String name) - { - if(name == null) - { - return null; - } - return Resource.class.getClassLoader().getResource(name); - } - - /** - * Loads a resource and returns an InputStream to it. - * @param name - * @return - */ - public static InputStream getAsStream(String name) - { - try - { - URL url = getAsURL(name); - if(url == null) - { - return null; - } - else - { - return url.openStream(); - } - } - catch(IOException e) - { - e.printStackTrace(); - return null; - } - } + /** + * Loads a resource and returns it as URL reference. + * The Resource's classloader is used to load the resource, not + * the System's ClassLoader so it may be safe to use this method + * in a sandboxed environment. + * @return + */ + public static URL getAsURL(final String name) + { + if (name == null) { + return null; + } - /** - * Loads a plain text resource. - * @param withNewline If false all newlines are removed from the - * return String - */ - public static String getAsString(String name, boolean withNewline) - { - if(name == null) - return null; + return Resource.class.getClassLoader().getResource(name); + } - BufferedReader in = null; - try - { - InputStream ins = getAsStream(name); - if(ins == null) - return null; + /** + * Loads a resource and returns an InputStream to it. + * @param name + * @return + */ + public static InputStream getAsStream(String name) + { + try { + URL url = getAsURL(name); + if (url == null) { + return null; + } else { + return url.openStream(); + } + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } - in = new BufferedReader( - new InputStreamReader(ins, Charset.forName("UTF-8"))); - StringBuffer buf = new StringBuffer(); + /** + * Loads a plain text resource. + * @param withNewline If false all newlines are removed from the + * return String + */ + public static String getAsString(String name, boolean withNewline) + { + if (name == null) { + return null; + } - for(;;) - { - String line = in.readLine(); - if(line == null) - break; + BufferedReader in = null; + try { + InputStream ins = getAsStream(name); + if (ins == null) { + return null; + } - buf.append(line); - if(withNewline) - buf.append('\n'); - } + in = new BufferedReader( + new InputStreamReader(ins, Charset.forName("UTF-8"))); + StringBuffer buf = new StringBuffer(); - return buf.toString(); - } - catch(Exception e) - { - e.printStackTrace(); - return null; - } - finally - { - try - { - if(in != null) - in.close(); - } - catch(IOException ex) - { - ex.printStackTrace(); - } - } - } + for (;;) { + String line = in.readLine(); + if (line == null) { + break; + } + buf.append(line); + if (withNewline) { + buf.append('\n'); + } + } + + return buf.toString(); + } catch (Exception e) { + e.printStackTrace(); + return null; + } finally { + try { + if (in != null) { + in.close(); + } + } catch (IOException ex) { + ex.printStackTrace(); + } + } + } }