Class TestFileUtils


  • public class TestFileUtils
    extends java.lang.Object
    File utilities specific to the test classes.
    • Constructor Summary

      Constructors 
      Constructor Description
      TestFileUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String compareDirsText​(java.io.File fstDir, java.io.File sndDir)
      Compares the content of two directories and report all differences in the returned text string.
      static void copyDirectoryNonCVS​(java.io.File from, java.io.File to)
      Copy an entire directory from one location to another, skipping CVS directories.
      static java.io.File createTempDir​(java.lang.String prefix, java.lang.String suffix)
      Make a temporary directory using File.createTempFile.
      static java.io.File createTempDir​(java.lang.String prefix, java.lang.String suffix, java.io.File directory)
      Make a temporary directory using File.createTempFile.
      static java.util.List<java.io.File> findFiles​(java.io.File start, java.io.FileFilter filter)
      Find files recursively that match the given filter.
      static java.lang.String getDifferences​(java.lang.String s1, java.lang.String s2)
      Return textual description of the differences between two strings.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • copyDirectoryNonCVS

        public static final void copyDirectoryNonCVS​(java.io.File from,
                                                     java.io.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 java.lang.String compareDirsText​(java.io.File fstDir,
                                                       java.io.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 sndDir
        sndDir - 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 java.lang.String getDifferences​(java.lang.String s1,
                                                      java.lang.String s2)
        Return textual description of the differences between two strings.
        Parameters:
        s1 - strings to compare
        s2 - strings to compare
        Returns:
        first line of text that differs
      • createTempDir

        public static java.io.File createTempDir​(java.lang.String prefix,
                                                 java.lang.String suffix)
                                          throws java.io.IOException
        Make a temporary directory using File.createTempFile.
        Parameters:
        prefix -
        suffix -
        Returns:
        a temporary directory using File.createTempFile
        Throws:
        java.io.IOException
      • createTempDir

        public static java.io.File createTempDir​(java.lang.String prefix,
                                                 java.lang.String suffix,
                                                 java.io.File directory)
                                          throws java.io.IOException
        Make a temporary directory using File.createTempFile.
        Parameters:
        prefix -
        suffix -
        directory -
        Returns:
        a temporary directory using File.createTempFile
        Throws:
        java.io.IOException
      • findFiles

        public static java.util.List<java.io.File> findFiles​(java.io.File start,
                                                             java.io.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.