java.lang.Object
de.cuioss.tools.io.FileLoaderUtility
Utility class for dealing with generic / classpath related file access.
- Author:
- Oliver Wolff
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic PathcopyFileToTemp(FileLoader source, boolean markDeleteOnExit) Helper class that copies the content of aFileLoaderto the temp-folder and references itstatic FileLoadergetLoaderForPath(String pathName) Returns an implementation ofFileLoadermatching to the given path.static StringtoString(FileLoader fileLoader) Convenience method for reading the content from a givenFileLoaderinto a String read as UTF-8 Stringstatic StringtoString(FileLoader fileLoader, Charset charset) Convenience method for reading the content from a givenFileLoaderinto a Stringstatic StringtoStringUnchecked(FileLoader fileLoader) Convenience method for reading the content from a givenFileLoaderinto a String read as UTF-8 String
-
Constructor Details
-
FileLoaderUtility
public FileLoaderUtility()
-
-
Method Details
-
getLoaderForPath
Returns an implementation ofFileLoadermatching to the given path.- Parameters:
pathName- must not be null or empty.- Returns:
- a configured implementation of
FileLoader. In case the pathName is prefixed withFileTypePrefix.CLASSPATHit returns aClassPathLoader. If prefixed withFileTypePrefix.URLit returns aUrlLoader. Otherwise, it returns aFileSystemLoader.
-
copyFileToTemp
Helper class that copies the content of aFileLoaderto the temp-folder and references itCaution: Security-Impact
Creating a temp-file might introduce a security issue. Never ever use this location for sensitive information that might be of interest for an attacker- Parameters:
source- must not be null and represent an accessible file, sayingFileLoader.isReadable()markDeleteOnExit- iftruethe file will be marked to delete on Exit.- Returns:
- a reference on a file copied in the temp folder
- Throws:
IOException
-
toString
Convenience method for reading the content from a givenFileLoaderinto a String- Parameters:
fileLoader- must not be nullcharset- must not be null- Returns:
- The String content of the File represented by the given
FileLoader - Throws:
IOException
-
toString
Convenience method for reading the content from a givenFileLoaderinto a String read as UTF-8 String- Parameters:
fileLoader- must not be null- Returns:
- The String content of the File represented by the given
FileLoader - Throws:
IOException
-
toStringUnchecked
Convenience method for reading the content from a givenFileLoaderinto a String read as UTF-8 String- Parameters:
fileLoader- must not be null- Returns:
- The String content of the File represented by the given
FileLoader - Throws:
IllegalArgumentException- masking the actualIOExceptionNullPointerException- iffileLoaderis null
-