Class PropertiesUtils

java.lang.Object
fr.gouv.vitam.common.PropertiesUtils

public final class PropertiesUtils extends Object
Property Utility class NOTE for developers: Do not add LOGGER there
  • Method Details

    • getConfigAsStream

      public static InputStream getConfigAsStream(String resourcesFile) throws 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:
      FileNotFoundException - if the resource file not found
    • getConfigFile

      public static File getConfigFile(String resourcesFile) throws 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:
      FileNotFoundException - if the resource file not found
    • getResourceAsStream

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

      public static File getResourceFile(String resourcesFile) throws 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:
      FileNotFoundException - if the resource file not found
    • getResourcePath

      public static Path getResourcePath(String resourcesFile) throws 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:
      FileNotFoundException - if resource file not found
    • getResourceListing

      public static Stream<String> getResourceListing(Class clazz, String path) throws URISyntaxException, IOException
      Throws:
      URISyntaxException
      IOException
    • findFile

      public static File findFile(String filename) throws 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:
      FileNotFoundException - if not fount
    • fileFromConfigFolder

      public static File fileFromConfigFolder(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 File fileFromDataFolder(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 File fileFromTmpFolder(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 Properties readProperties(File propertiesFile) throws IOException
      Read a properties file and returns the associated Properties
      Parameters:
      propertiesFile - properties file
      Returns:
      the associated Properties
      Throws:
      IOException - if cannot load file
    • readYaml

      public static <C> C readYaml(File yamlFile, Class<C> clasz) throws 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:
      IOException - if read yaml input stream to class template exception occurred
    • readYaml

      public static <C> C readYaml(File yamlFile, com.fasterxml.jackson.core.type.TypeReference<C> typeReference) throws 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:
      IOException - if read yaml input stream to class template exception occurred
    • readYaml

      public static <C> C readYaml(InputStream yamlInputStream, Class<C> clasz) throws 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:
      IOException - if read yaml input stream to class template exception occurred
    • readYaml

      public static <C> C readYaml(Path yamlPath, Class<C> clasz) throws 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:
      IOException - if file not found exception
    • writeYaml

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

      public static String getResourceAsString(String resourcesFile) throws 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:
      FileNotFoundException - if the resource file not found