Class FileUtils


  • public class FileUtils
    extends java.lang.Object
    Some file helper methods.
    Author:
    Holger Eichelberger
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private FileUtils()
      Prevents external instantiations (utility class).
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) static java.util.List<IFileSystemArtifact> copy​(IFileSystemArtifact source, IFileSystemArtifact target)
      Copies source to target.
      private static void copyOrMove​(java.io.File source, java.io.File target, ArtifactModel sourceModel, ArtifactModel targetModel, java.util.List<IFileSystemArtifact> artifacts)
      Copy or move from source to target considering each as directories or files.
      private static java.util.List<IFileSystemArtifact> copyOrMove​(IFileSystemArtifact source, IFileSystemArtifact target, boolean move)
      Copy or move from source to target considering each as directories or files.
      (package private) static Set<IFileSystemArtifact> copyOrMove​(Path source, IFileSystemArtifact target, boolean move)
      Copy or move from the source path to the target artifact.
      (package private) static void delete​(java.io.File file)
      Deletes the given file and handles the exceptions / return values in the sense of VIL.
      private static java.io.File determineDestination​(Path sourcePath, FileArtifact sourceArtefakt, java.io.File targetFile)
      Determines the destination of an artefact, which shall be copied/moved from a given source path (e.g.
      static java.io.File getTempDirectory()
      Returns a File representing the system temporary directory.
      static boolean isDirectory​(java.io.File file)
      Returns whether file is a directory regardless whether it exists or not.
      static boolean isFile​(java.io.File file)
      Returns whether file is a file regardless whether it exists or not.
      static boolean isFile​(java.lang.String path)
      A heuristic whether the given path is a file.
      (package private) static java.util.List<IFileSystemArtifact> move​(IFileSystemArtifact source, IFileSystemArtifact target)
      Moves source to target.
      (package private) static void rename​(java.io.File file, java.io.File newFile)
      Renames the given file and handles the exceptions / return values in the sense of VIL.
      (package private) static void rename​(java.io.File file, java.lang.String name)
      Renames the given file and handles the exceptions / return values in the sense of VIL.
      static <T extends IArtifact>
      void
      scan​(java.io.File location, ArtifactModel model, long timestamp, FileUtils.ScanResult<T> result, java.lang.Class<T> type)
      Scans the file system for new files.
      • Methods inherited from class java.lang.Object

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

      • FileUtils

        private FileUtils()
        Prevents external instantiations (utility class).
    • Method Detail

      • delete

        static void delete​(java.io.File file)
                    throws VilException
        Deletes the given file and handles the exceptions / return values in the sense of VIL.
        Parameters:
        file - the file to be deleted
        Throws:
        VilException - in case that anything goes seriously wrong
      • rename

        static void rename​(java.io.File file,
                           java.io.File newFile)
                    throws VilException
        Renames the given file and handles the exceptions / return values in the sense of VIL.
        Parameters:
        file - the file to be renamed
        newFile - the new file name
        Throws:
        VilException - in case that anything goes seriously wrong
      • rename

        static void rename​(java.io.File file,
                           java.lang.String name)
                    throws VilException
        Renames the given file and handles the exceptions / return values in the sense of VIL.
        Parameters:
        file - the file to be renamed
        name - the new name
        Throws:
        VilException - in case that anything goes seriously wrong
      • copyOrMove

        static Set<IFileSystemArtifact> copyOrMove​(Path source,
                                                   IFileSystemArtifact target,
                                                   boolean move)
                                            throws VilException
        Copy or move from the source path to the target artifact.
        Parameters:
        source - the source path
        target - the target artifact
        move - move or copy
        Returns:
        the created or touched artifacts
        Throws:
        VilException - in case that file system operations or artifact model operations fail
      • copyOrMove

        private static java.util.List<IFileSystemArtifact> copyOrMove​(IFileSystemArtifact source,
                                                                      IFileSystemArtifact target,
                                                                      boolean move)
                                                               throws VilException
        Copy or move from source to target considering each as directories or files. This method informs the involved artifact models appropriately.
        Parameters:
        source - the source to copy from
        target - the target to copy to
        move - move or copy
        Returns:
        the created or touched artifacts
        Throws:
        VilException - in case that file system operations or artifact model operations fail
      • copyOrMove

        private static void copyOrMove​(java.io.File source,
                                       java.io.File target,
                                       ArtifactModel sourceModel,
                                       ArtifactModel targetModel,
                                       java.util.List<IFileSystemArtifact> artifacts)
                                throws VilException
        Copy or move from source to target considering each as directories or files. This method informs the involved artifact models appropriately.
        Parameters:
        source - the source to copy from
        target - the target to copy to
        sourceModel - the source artifact model (may be null for copy, non-null for move operation)
        targetModel - the target artifact model
        artifacts - the created or touched artifacts (may be null then resulting artifacts will not be collected)
        Throws:
        VilException - in case that file system operations or artifact model operations fail
      • isFile

        public static boolean isFile​(java.lang.String path)
        A heuristic whether the given path is a file.
        Parameters:
        path - the path to be considered
        Returns:
        true if path is considered to be a file, false else
      • isFile

        public static boolean isFile​(java.io.File file)
        Returns whether file is a file regardless whether it exists or not.
        Parameters:
        file - the file to be considered
        Returns:
        true if file is considered to be a file, false else
      • isDirectory

        public static boolean isDirectory​(java.io.File file)
        Returns whether file is a directory regardless whether it exists or not.
        Parameters:
        file - the file to be considered
        Returns:
        true if file is considered to be a directory, false else
      • scan

        public static <T extends IArtifact> void scan​(java.io.File location,
                                                      ArtifactModel model,
                                                      long timestamp,
                                                      FileUtils.ScanResult<T> result,
                                                      java.lang.Class<T> type)
        Scans the file system for new files.
        Type Parameters:
        T - the actual type of artifacts to be produced
        Parameters:
        location - the location to scan
        model - the artifact model to generate new artifacts into if needed
        timestamp - the timestamp all returned artifacts must be newer (use PathUtils.normalizedTime())
        result - the resulting artifacts and errors (to be modified as a side effect, may be null)
        type - the artifact type to be produced (may be null for any restriction)
      • getTempDirectory

        public static java.io.File getTempDirectory()
        Returns a File representing the system temporary directory.
        Returns:
        the system temporary directory.
      • determineDestination

        private static java.io.File determineDestination​(Path sourcePath,
                                                         FileArtifact sourceArtefakt,
                                                         java.io.File targetFile)
        Determines the destination of an artefact, which shall be copied/moved from a given source path (e.g. a pattern) to a given target (folder). Considers sub folder structures, will not consider constant parts at the beginning of a pattern. For instance:
        Elements of "src/foo/**//bar/*.java" will be copied to "targetFile/**//bar/*.java"
        Part of the copyOrMove(Path, IFileSystemArtifact, boolean) method.
        Parameters:
        sourcePath - The sourcepath, containing the sourceArtefact (may be a pattern). Must not be null.
        sourceArtefakt - An artefact inside the given sourcePath. Must not be null
        targetFile - The destination, should be a folder. Must not be null
        Returns:
        The destination of the the file to be copied/moved.