Package ru.vyarus.yaml.updater.util
Class FileUtils
- java.lang.Object
-
- ru.vyarus.yaml.updater.util.FileUtils
-
public final class FileUtils extends java.lang.Object- Since:
- 06.10.2021
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.io.FilecopyToTempFile(java.lang.String path)Creates temporary file by copying content of the specified file.static java.io.InputStreamfindExistingFile(java.lang.String path)Same asfindFile(String), but fails if target file not found.static java.io.InputStreamfindFile(java.lang.String path)Searches file in multiple locations.static voidloadProperties(java.io.InputStream in, java.util.Map<java.lang.String,java.lang.String> out)Loads properties file from stream.static java.util.Map<java.lang.String,java.lang.String>loadProperties(java.lang.String path)Loads properties file from fs, classpath or url (seefindFile(String)) as map of values.static booleanloadProperties(java.lang.String path, java.util.Map<java.lang.String,java.lang.String> out)Loads properties file from fs, classpath or url (seefindFile(String)) and appends everything to provided map.static java.lang.Stringread(java.io.InputStream in)Reads file content from stream.
-
-
-
Method Detail
-
findFile
public static java.io.InputStream findFile(java.lang.String path)
Searches file in multiple locations.- First checks if provided path is fs file path (relative or absolute)
- If path contains ':' then tries to load it as URL
- Otherwise, tries to load file from classpath
- Parameters:
path- fs file path, classpath or file url- Returns:
- file's input stream or null if not found
- See Also:
findExistingFile(String)
-
findExistingFile
public static java.io.InputStream findExistingFile(java.lang.String path)
Same asfindFile(String), but fails if target file not found.- Parameters:
path- fs file path, classpath or file url- Returns:
- file's input stream
-
read
public static java.lang.String read(java.io.InputStream in)
Reads file content from stream. Closes stream after read.- Parameters:
in- file stream- Returns:
- file content string
-
copyToTempFile
public static java.io.File copyToTempFile(java.lang.String path)
Creates temporary file by copying content of the specified file. This is required when file is loaded from classpath or url in tests because updater accepts only exact file as updatable configuration.- Parameters:
path- fs file path, classpath or file url- Returns:
- created tmp file with content from file in specified path
- Throws:
java.lang.IllegalArgumentException- if target file not found
-
loadProperties
public static java.util.Map<java.lang.String,java.lang.String> loadProperties(java.lang.String path)
Loads properties file from fs, classpath or url (seefindFile(String)) as map of values.- Parameters:
path- fs file path, classpath or file url- Returns:
- loader properties map or empty map if file not found
-
loadProperties
public static boolean loadProperties(java.lang.String path, java.util.Map<java.lang.String,java.lang.String> out)Loads properties file from fs, classpath or url (seefindFile(String)) and appends everything to provided map.- Parameters:
path- fs file path, classpath or file urlout- output map- Returns:
- true if file was found, false otherwise
-
loadProperties
public static void loadProperties(java.io.InputStream in, java.util.Map<java.lang.String,java.lang.String> out) throws java.lang.ExceptionLoads properties file from stream.- Parameters:
in- input streamout- map to put properties into- Throws:
java.lang.Exception- on read errors
-
-