Class PropertiesUtils


  • public final class PropertiesUtils
    extends java.lang.Object
    Property Utility class NOTE for developers: Do not add LOGGER there
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.io.File fileFromConfigFolder​(java.lang.String subpath)
      Return a full file path using Config folder as root and subpath as sub paths.
      static java.io.File fileFromDataFolder​(java.lang.String subpath)
      Return a full file path using Data folder as root and subpath as sub paths.
      static java.io.File fileFromTmpFolder​(java.lang.String subpath)
      Return a full file path using Tmp folder as root and subpath as sub paths.
      static java.io.File findFile​(java.lang.String filename)
      Get the File associated with this filename, trying in this order: as fullpath, as in Vitam Config Folder, as Resources file
      static java.io.InputStream getConfigAsStream​(java.lang.String resourcesFile)
      Get the InputStream representation from the local path to the Resources directory
      static java.io.InputStream getResourceAsStream​(java.lang.String resourcesFile)
      Get the InputStream representation from the Resources directory
      static java.lang.String getResourceAsString​(java.lang.String resourcesFile)
      Get the String content from the Resources directory
      static java.io.File getResourceFile​(java.lang.String resourcesFile)
      Get the File representation from the local path to the Resources directory
      static java.util.stream.Stream<java.lang.String> getResourceListing​(java.lang.Class clazz, java.lang.String path)  
      static java.nio.file.Path getResourcePath​(java.lang.String resourcesFile)
      Get the Path representation from the local path to the Resources directory
      static java.util.Properties readProperties​(java.io.File propertiesFile)
      Read a properties file and returns the associated Properties
      static <C> C readYaml​(java.io.File yamlFile, com.fasterxml.jackson.core.type.TypeReference<C> typeReference)
      Read the Yaml file and return the object read
      static <C> C readYaml​(java.io.File yamlFile, java.lang.Class<C> clasz)
      Read the Yaml file and return the object read
      static <C> C readYaml​(java.io.InputStream yamlInputStream, java.lang.Class<C> clasz)
      Read the Yaml InputStream and return the object read
      static <C> C readYaml​(java.nio.file.Path yamlPath, java.lang.Class<C> clasz)
      Read the Yaml file and return the object read
      static void writeYaml​(java.io.File destination, java.lang.Object config)
      Write the Yaml file
      • Methods inherited from class java.lang.Object

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

      • getConfigAsStream

        public static java.io.InputStream getConfigAsStream​(java.lang.String resourcesFile)
                                                     throws java.io.FileNotFoundException
        Get the InputStream representation from the local path to the Resources directory
        Parameters:
        resourcesFile - properties file from resources directory
        Returns:
        the associated File
        Throws:
        java.io.FileNotFoundException - if the resource file not found
      • getResourceAsStream

        public static java.io.InputStream getResourceAsStream​(java.lang.String resourcesFile)
                                                       throws java.io.FileNotFoundException
        Get the InputStream representation from the Resources directory
        Parameters:
        resourcesFile - properties file from resources directory
        Returns:
        the associated File
        Throws:
        java.io.FileNotFoundException - if the resource file not found
      • getResourceFile

        public static java.io.File getResourceFile​(java.lang.String resourcesFile)
                                            throws java.io.FileNotFoundException
        Get the File representation from the local path to the Resources directory
        Parameters:
        resourcesFile - properties file from resources directory
        Returns:
        the associated File
        Throws:
        java.io.FileNotFoundException - if the resource file not found
      • getResourcePath

        public static java.nio.file.Path getResourcePath​(java.lang.String resourcesFile)
                                                  throws java.io.FileNotFoundException
        Get the Path representation from the local path to the Resources directory
        Parameters:
        resourcesFile - properties file from resources directory
        Returns:
        the associated Path
        Throws:
        java.io.FileNotFoundException - if resource file not found
      • getResourceListing

        public static java.util.stream.Stream<java.lang.String> getResourceListing​(java.lang.Class clazz,
                                                                                   java.lang.String path)
                                                                            throws java.net.URISyntaxException,
                                                                                   java.io.IOException
        Throws:
        java.net.URISyntaxException
        java.io.IOException
      • findFile

        public static java.io.File findFile​(java.lang.String filename)
                                     throws java.io.FileNotFoundException
        Get the File associated with this filename, trying in this order: as fullpath, as in Vitam Config Folder, as Resources file
        Parameters:
        filename - the file name
        Returns:
        the File if found
        Throws:
        java.io.FileNotFoundException - if not fount
      • fileFromConfigFolder

        public static java.io.File fileFromConfigFolder​(java.lang.String subpath)
        Return a full file path using Config folder as root and subpath as sub paths.
        Parameters:
        subpath - the subpath under Config folder
        Returns:
        the full file path (no check on existing is done)
      • fileFromDataFolder

        public static java.io.File fileFromDataFolder​(java.lang.String subpath)
        Return a full file path using Data folder as root and subpath as sub paths.
        Parameters:
        subpath - the subpath under Data folder
        Returns:
        the full file path (no check on existing is done)
      • fileFromTmpFolder

        public static java.io.File fileFromTmpFolder​(java.lang.String subpath)
        Return a full file path using Tmp folder as root and subpath as sub paths.
        Parameters:
        subpath - the subpath under Tmp folder
        Returns:
        the full file path (no check on existing is done)
      • readProperties

        public static java.util.Properties readProperties​(java.io.File propertiesFile)
                                                   throws java.io.IOException
        Read a properties file and returns the associated Properties
        Parameters:
        propertiesFile - properties file
        Returns:
        the associated Properties
        Throws:
        java.io.IOException - if cannot load file
      • readYaml

        public static <C> C readYaml​(java.io.File yamlFile,
                                     java.lang.Class<C> clasz)
                              throws java.io.IOException
        Read the Yaml file and return the object read
        Parameters:
        yamlFile - the yaml file to read
        clasz - the class representing the target object
        Returns:
        the object read
        Throws:
        java.io.IOException - if read yaml input stream to class template exception occurred
      • readYaml

        public static <C> C readYaml​(java.io.File yamlFile,
                                     com.fasterxml.jackson.core.type.TypeReference<C> typeReference)
                              throws java.io.IOException
        Read the Yaml file and return the object read
        Parameters:
        yamlFile - the yaml file
        typeReference - the type reference representing the target interface object
        Returns:
        the object read
        Throws:
        java.io.IOException - if read yaml input stream to class template exception occurred
      • readYaml

        public static <C> C readYaml​(java.io.InputStream yamlInputStream,
                                     java.lang.Class<C> clasz)
                              throws java.io.IOException
        Read the Yaml InputStream and return the object read
        Parameters:
        yamlInputStream - the yaml input stream to read
        clasz - the class representing the target object
        Returns:
        the object read
        Throws:
        java.io.IOException - if read yaml input stream to class template exception occurred
      • readYaml

        public static <C> C readYaml​(java.nio.file.Path yamlPath,
                                     java.lang.Class<C> clasz)
                              throws java.io.IOException
        Read the Yaml file and return the object read
        Parameters:
        yamlPath - yaml file path
        clasz - the class representing the target object
        Returns:
        the object read
        Throws:
        java.io.IOException - if file not found exception
      • writeYaml

        public static void writeYaml​(java.io.File destination,
                                     java.lang.Object config)
                              throws java.io.IOException
        Write the Yaml file
        Parameters:
        destination - the destination file
        config - the configuration object to write using Yaml format
        Throws:
        java.io.IOException - if write object config exception occurred
      • getResourceAsString

        public static java.lang.String getResourceAsString​(java.lang.String resourcesFile)
                                                    throws java.io.FileNotFoundException
        Get the String content from the Resources directory
        Parameters:
        resourcesFile - properties file from resources directory
        Returns:
        the associated File content as a String
        Throws:
        java.io.FileNotFoundException - if the resource file not found