Class FileHelper


  • public class FileHelper
    extends java.lang.Object
    Helper methods for file handling.
    Author:
    harald
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.io.InputStream createInputStream​(java.lang.Class<?> caller, java.lang.String name)
      Creates an input stream from a resource.
      static java.util.Properties loadProperties​(java.lang.String name)
      Loads properties.
      Tries to load from filesystem first, then from classpath.
      static java.util.Properties loadProperties​(java.lang.String name, boolean asResource)
      Loads properties from a resource.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • createInputStream

        public static java.io.InputStream createInputStream​(java.lang.Class<?> caller,
                                                            java.lang.String name)
                                                     throws java.io.IOException
        Creates an input stream from a resource.
        Parameters:
        caller - the caller class, null to determine via Stackwalker
        name - the resource name
        Returns:
        the input stream
        Throws:
        java.io.IOException - if reading the resources failed
        java.io.FileNotFoundException - if no such resources found
      • loadProperties

        public static java.util.Properties loadProperties​(java.lang.String name,
                                                          boolean asResource)
                                                   throws java.io.IOException
        Loads properties from a resource.
        Parameters:
        name - the properties name, null if return empty properties
        asResource - true if load from the classpath, false if from filesystem
        Returns:
        the properties, empty if filename is null
        Throws:
        java.io.IOException - if reading the property file failed
        java.io.FileNotFoundException - if no properties found
      • loadProperties

        public static java.util.Properties loadProperties​(java.lang.String name)
                                                   throws java.io.IOException
        Loads properties.
        Tries to load from filesystem first, then from classpath.
        Parameters:
        name - the properties name, null if return empty properties
        Returns:
        the properties, empty if filename is null
        Throws:
        java.io.IOException - if reading the property file failed
        java.io.FileNotFoundException - if no properties found