Package org.citrusframework.util
Class FileUtils
java.lang.Object
org.citrusframework.util.FileUtils
Class to provide general file utilities, such as listing all XML files in a directory,
or finding certain tests in a directory.
- Since:
- 2007
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic StringconstructContentType(String contentType, Charset charset) Construct content type information with given charset parameter.static byte[]copyToByteArray(File file) static byte[]copyToByteArray(InputStream inputStream) static byte[]copyToByteArray(Resource resource) Method to retrieve all files with given file name pattern in given directory.static StringgetBaseName(String fileName) Remove file extension from file name.static StringgetBasePath(String filePath) Gets the base path of given file path removing any file name if present.static CharsetgetCharset(String path) Extract charset information from file path.static CharsetGets the default charset.static StringgetFileExtension(String path) Extract file extension from given path.static StringgetFileName(String path) Gets the file name from given file path.static ResourcegetFileResource(String filePath) Reads file resource from path with variable replacement support.static ResourcegetFileResource(String filePath, TestContext context) Reads file resource from path with variable replacement support.static TestSourcegetTestSource(String sourceFile) Read String representation and construct proper test source instance.static PropertiesloadAsProperties(Resource resource) Load properties from file.static StringreadToString(File file) Read file content to string value with default charset settings.static StringreadToString(InputStream inputStream) Read file input stream to string value with default charset settings.static StringreadToString(InputStream inputStream, Charset charset) Read file input stream to string value.static StringreadToString(Resource resource) Read file resource to string value with default charset settings.static StringreadToString(Resource resource, Charset charset) Read file resource to string value.static voidsetSimulationMode(boolean mode) Sets the simulation mode.static voidwriteToFile(InputStream inputStream, File file) Writes inputStream content to file.static voidwriteToFile(String content, File file) Writes String content to file.static voidwriteToFile(String content, File file, Charset charset) Writes String content to file with given charset encoding.
-
Field Details
-
FILE_EXTENSION_JAVA
- See Also:
-
FILE_EXTENSION_XML
- See Also:
-
FILE_EXTENSION_GROOVY
- See Also:
-
FILE_EXTENSION_YAML
- See Also:
-
FILE_PATH_CHARSET_PARAMETER
-
-
Method Details
-
setSimulationMode
public static void setSimulationMode(boolean mode) Sets the simulation mode. -
readToString
Read file resource to string value with default charset settings.- Parameters:
resource-- Returns:
- Throws:
IOException
-
readToString
Read file input stream to string value with default charset settings.- Parameters:
inputStream-- Returns:
- Throws:
IOException
-
readToString
Read file content to string value with default charset settings.- Parameters:
file-- Returns:
- Throws:
IOException
-
readToString
Read file resource to string value.- Parameters:
resource-charset-- Returns:
- Throws:
IOException
-
readToString
Read file input stream to string value.- Parameters:
inputStream-charset-- Returns:
- Throws:
IOException
-
writeToFile
Writes inputStream content to file. Uses default charset encoding.- Parameters:
inputStream-file-
-
writeToFile
Writes String content to file. Uses default charset encoding.- Parameters:
content-file-
-
writeToFile
Writes String content to file with given charset encoding. Automatically closes file output streams when done.- Parameters:
content-file-
-
findFiles
Method to retrieve all files with given file name pattern in given directory. Hierarchy of folders is supported.- Parameters:
startDir- the directory to hold the filesfileNamePatterns- the file names to include- Returns:
- list of test files as filename paths
-
getFileResource
Reads file resource from path with variable replacement support.- Parameters:
filePath-context-- Returns:
-
getFileResource
Reads file resource from path with variable replacement support.- Parameters:
filePath-- Returns:
-
getDefaultCharset
Gets the default charset. If set by Citrus system property (citrus.file.encoding) use this one otherwise use system default.- Returns:
-
getCharset
Extract charset information from file path. If not set return default charset. Charset is read as path parameter at the end of the file path- Parameters:
path-- Returns:
-
getFileExtension
Extract file extension from given path.- Parameters:
path-- Returns:
-
loadAsProperties
Load properties from file. Supports XML and key-value format.- Parameters:
resource-- Returns:
-
getFileName
Gets the file name from given file path.- Parameters:
path-- Returns:
-
getBaseName
Remove file extension from file name.- Parameters:
fileName-- Returns:
-
getBasePath
Gets the base path of given file path removing any file name if present.- Parameters:
filePath-- Returns:
-
copyToByteArray
-
copyToByteArray
-
copyToByteArray
-
constructContentType
Construct content type information with given charset parameter.- Parameters:
contentType-charset-- Returns:
-
getTestSource
Read String representation and construct proper test source instance. Extract source type from give file extension and try to set proper test source name from given file name.- Parameters:
sourceFile-- Returns:
-