Package dk.netarkivet.testutils
Class TestFileUtils
- java.lang.Object
-
- dk.netarkivet.testutils.TestFileUtils
-
public class TestFileUtils extends Object
File utilities specific to the test classes.
-
-
Field Summary
Fields Modifier and Type Field Description static FileFilter
DIRS_ONLY_FILTER
static FilenameFilter
NON_CVS_DIRS_FILTER
-
Constructor Summary
Constructors Constructor Description TestFileUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
compareDirsText(File fstDir, File sndDir)
Compares the content of two directories and report all differences in the returned text string.static void
copyDirectoryNonCVS(File from, File to)
Copy an entire directory from one location to another, skipping CVS directories.static File
createTempDir(String prefix, String suffix)
Make a temporary directory using File.createTempFile.static File
createTempDir(String prefix, String suffix, File directory)
Make a temporary directory using File.createTempFile.static List<File>
findFiles(File start, FileFilter filter)
Find files recursively that match the given filter.static String
getDifferences(String s1, String s2)
Return textual description of the differences between two strings.
-
-
-
Field Detail
-
NON_CVS_DIRS_FILTER
public static final FilenameFilter NON_CVS_DIRS_FILTER
-
DIRS_ONLY_FILTER
public static final FileFilter DIRS_ONLY_FILTER
-
-
Method Detail
-
copyDirectoryNonCVS
public static final void copyDirectoryNonCVS(File from, File to) throws IOFailure
Copy an entire directory from one location to another, skipping CVS directories. Note that this will silently overwrite old files, just like copyFile().- Parameters:
from
- Original directory (or file, for that matter) to copy.to
- Destination directory, i.e. the 'new name' of the copy of the from directory.- Throws:
IOFailure
-
compareDirsText
public static String compareDirsText(File fstDir, File sndDir) throws IOFailure
Compares the content of two directories and report all differences in the returned text string. If no difference are located, an empty string ("") is returned. All files located in the directories are treated as text files, and a text comparison is done on a line by line basis. This function will not work if the dirs contain binary files. No attempt is made to recover from errors.- Parameters:
fstDir
- The directory to compare with sndDirsndDir
- The directory to compare with fstDir- Returns:
- A text string describing the differences between the two dirs. Empty if no differences are found.
- Throws:
IOFailure
- if there are problems reading the content of the dirs.
-
getDifferences
public static String getDifferences(String s1, String s2)
Return textual description of the differences between two strings.- Parameters:
s1
- strings to compares2
- strings to compare- Returns:
- first line of text that differs
-
createTempDir
public static File createTempDir(String prefix, String suffix) throws IOException
Make a temporary directory using File.createTempFile.- Parameters:
prefix
-suffix
-- Returns:
- a temporary directory using File.createTempFile
- Throws:
IOException
-
createTempDir
public static File createTempDir(String prefix, String suffix, File directory) throws IOException
Make a temporary directory using File.createTempFile.- Parameters:
prefix
-suffix
-directory
-- Returns:
- a temporary directory using File.createTempFile
- Throws:
IOException
-
findFiles
public static List<File> findFiles(File start, FileFilter filter)
Find files recursively that match the given filter.- Parameters:
start
- The directory (or file) to start at.filter
- Filter of files to include. All files (including directories) are passed to this filter and are included if filter.accept() returns true. Subdirectories are scanned whether or not filter.accept() returns true for them.- Returns:
- List of files (in no particular order) that match the filter. and reside under start.
-
-