Class Files


  • public class Files
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      Files()  
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static boolean cleanFolder​(java.io.File parentFolder, java.io.FileFilter filter, boolean continueOnError, boolean deleteParentFolder)
      Clean the content of the given folder.
      static void copyFiles​(java.lang.String sourceDir, java.lang.String targetDir, java.util.List<java.lang.String> files)
      Copies a list of files from a source to a target directory.
      static java.lang.String readFileIntoString​(java.lang.String filename)
      Deprecated.
      Use com.google.common.io.Files.toString(File, Charset) instead
      static byte[] readStreamIntoByteArray​(java.io.InputStream inputStream)
      Deprecated.
      Use com.google.common.io.ByteStreams.toByteArray(InputStream) instead
      static java.lang.String readStreamIntoString​(java.io.InputStream inputStream)  
      static boolean sweepFolder​(java.io.File folder)
      This will completely sweep the given folder.
      static void writeStringIntoFile​(java.lang.String filename, java.lang.String content)  
      • Methods inherited from class java.lang.Object

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

      • Files

        public Files()
    • Method Detail

      • copyFiles

        public static void copyFiles​(java.lang.String sourceDir,
                                     java.lang.String targetDir,
                                     java.util.List<java.lang.String> files)
        Copies a list of files from a source to a target directory. Existing files are not overwritten. If the target directory does not exist it will be created.
        Parameters:
        sourceDir - source directory
        targetDir - target directory. Not mandatory to exist before.
        files - File paths relative to the source directory to copy
      • cleanFolder

        public static boolean cleanFolder​(java.io.File parentFolder,
                                          java.io.FileFilter filter,
                                          boolean continueOnError,
                                          boolean deleteParentFolder)
                                   throws java.io.FileNotFoundException
        Clean the content of the given folder.
        Parameters:
        parentFolder - the folder to be cleaned. It must not be null.
        filter - a filter for selecting the files to be removed. If it is null, all the files are removed.
        continueOnError - indicates if the cleaning should continue after an error occurs.
        deleteParentFolder - indicates if parentFolder should be also deleted if it becomes empty.
        Returns:
        true if the cleaning process goes through all the folders and files. false if the process has been stopped before its termination. The value false could be replied only if the value of continueOnError is false.
        Throws:
        java.io.FileNotFoundException - if the given parentFolder does not exists.
      • sweepFolder

        public static boolean sweepFolder​(java.io.File folder)
                                   throws java.io.FileNotFoundException
        This will completely sweep the given folder. Consider using cleanFolder(File, FileFilter, boolean, boolean) if you want to preserve CVS or SVN information.
        Parameters:
        folder - to delete
        Returns:
        true if all content was successfully deleted
        Throws:
        java.io.FileNotFoundException - if folder does not exists
      • readFileIntoString

        @Deprecated
        public static java.lang.String readFileIntoString​(java.lang.String filename)
        Deprecated.
        Use com.google.common.io.Files.toString(File, Charset) instead
      • readStreamIntoByteArray

        @Deprecated
        public static byte[] readStreamIntoByteArray​(java.io.InputStream inputStream)
        Deprecated.
        Use com.google.common.io.ByteStreams.toByteArray(InputStream) instead
        Since:
        2.3
      • readStreamIntoString

        public static java.lang.String readStreamIntoString​(java.io.InputStream inputStream)
      • writeStringIntoFile

        public static void writeStringIntoFile​(java.lang.String filename,
                                               java.lang.String content)