Package edu.odu.cs.zeil.codegrader
Class FileUtils
- java.lang.Object
-
- edu.odu.cs.zeil.codegrader.FileUtils
-
public final class FileUtils extends java.lang.Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
copyDirectory(java.nio.file.Path source, java.nio.file.Path target, java.util.List<java.lang.String> inclusions, java.util.List<java.lang.String> exclusions, java.nio.file.CopyOption... options)
Directory copy utility.static void
deleteDirectory(java.nio.file.Path dir)
Directory delete utility.static java.util.List<java.io.File>
findAllDeepFiles(java.nio.file.Path dir, java.lang.String extension)
Find all files with the given extension in a directory tree.static java.util.List<java.io.File>
findAllFiles(java.nio.file.Path dir, java.lang.String extension)
Find all files with the given extension in a directory.static java.util.List<java.io.File>
findDirectoriesContaining(java.nio.file.Path dir, java.lang.String extension)
Find all directories containing files with the given extension in a directory tree.static java.util.Optional<java.io.File>
findFile(java.nio.file.Path dir, java.lang.String extension)
Find a file with the given extension in a directory.static java.util.Map<java.lang.String,java.lang.Object>
loadYaml(java.io.File yamlFile)
Load a file of YAML content into a map structure.static java.lang.String
readTextFile(java.io.File file)
Read an entire test file into a string.static void
writeTextFile(java.nio.file.Path destination, java.lang.String outputString)
WWrite a string into a file.
-
-
-
Method Detail
-
copyDirectory
public static void copyDirectory(java.nio.file.Path source, java.nio.file.Path target, java.util.List<java.lang.String> inclusions, java.util.List<java.lang.String> exclusions, java.nio.file.CopyOption... options) throws java.io.IOException
Directory copy utility.- Parameters:
source
- directory to copytarget
- destination for copyinclusions
- list of patterns to include. If null or empty, copy all files.exclusions
- list of patterns to include. If null or empty, exclude no files. Exclusions are applied after inclusions.options
- copy options, e.g., StandardCopyOption.REPLACE_EXISTING- Throws:
java.io.IOException
- if files cannot be accessed/copied
-
deleteDirectory
public static void deleteDirectory(java.nio.file.Path dir) throws java.io.IOException
Directory delete utility.- Parameters:
dir
- directory to delete- Throws:
java.io.IOException
- if files cannot be accessed/deleted
-
readTextFile
public static java.lang.String readTextFile(java.io.File file)
Read an entire test file into a string.- Parameters:
file
- file to be read- Returns:
- contents of that file (empty if any IO error occurs)
-
loadYaml
public static java.util.Map<java.lang.String,java.lang.Object> loadYaml(java.io.File yamlFile)
Load a file of YAML content into a map structure.- Parameters:
yamlFile
- the file to read- Returns:
- the YAML content as a map from field names onto objects.
-
findFile
public static java.util.Optional<java.io.File> findFile(java.nio.file.Path dir, java.lang.String extension)
Find a file with the given extension in a directory.- Parameters:
dir
- a path to a directoryextension
- the desired file extension- Returns:
- a file with the desired extension, if one exists.
-
findAllFiles
public static java.util.List<java.io.File> findAllFiles(java.nio.file.Path dir, java.lang.String extension)
Find all files with the given extension in a directory.- Parameters:
dir
- a path to a directoryextension
- the desired file extension- Returns:
- a list of files with the desired extension.
-
findAllDeepFiles
public static java.util.List<java.io.File> findAllDeepFiles(java.nio.file.Path dir, java.lang.String extension)
Find all files with the given extension in a directory tree.- Parameters:
dir
- a path to a directoryextension
- the desired file extension- Returns:
- a list of files with the desired extension.
-
findDirectoriesContaining
public static java.util.List<java.io.File> findDirectoriesContaining(java.nio.file.Path dir, java.lang.String extension)
Find all directories containing files with the given extension in a directory tree.- Parameters:
dir
- a path to a directoryextension
- the desired file extension- Returns:
- a list of directories
-
writeTextFile
public static void writeTextFile(java.nio.file.Path destination, java.lang.String outputString) throws TestConfigurationError
WWrite a string into a file.- Parameters:
destination
- path at which to writeoutputString
- string to write- Throws:
TestConfigurationError
- if file cannot be written.
-
-