Class FileUtil


  • public final class FileUtil
    extends java.lang.Object
    File Utility class
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.io.File convertInputStreamToFile​(java.io.InputStream rulesStream, java.lang.String filename)  
      static java.io.File convertInputStreamToFile​(java.io.InputStream stream, java.lang.String filename, java.lang.String extension)  
      static java.io.File createFileInTempDirectoryWithPathCheck​(java.lang.String filename, java.lang.String fileExtension)
      Creates a new empty file in the vitam temporary directory retrieved from VitamConfiguration, using the given filename and fileExtension strings to generate its name.
      Do a Path traversal attack check before creating file
      static boolean deleteRecursive​(java.io.File file)
      CARE: delete all files and directories from this file or directory, this one included
      static void fsyncFile​(java.nio.file.Path path)  
      static java.lang.String getFileCanonicalPath​(java.lang.String pathname)
      retrieve the canonical path for a given file pathname
      static java.lang.String readFile​(java.io.File file)  
      static java.lang.String readFile​(java.lang.String filename)  
      static java.lang.String readInputStream​(java.io.InputStream input)  
      static java.lang.String readPartialFile​(java.io.File file, int limit)  
      • Methods inherited from class java.lang.Object

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

      • readFile

        public static final java.lang.String readFile​(java.lang.String filename)
                                               throws java.io.IOException
        Parameters:
        filename -
        Returns:
        the content of the file
        Throws:
        java.io.IOException
      • readFile

        public static final java.lang.String readFile​(java.io.File file)
                                               throws java.io.IOException
        Parameters:
        file -
        Returns:
        the content of the file
        Throws:
        java.io.IOException
      • readPartialFile

        public static final java.lang.String readPartialFile​(java.io.File file,
                                                             int limit)
                                                      throws java.io.IOException
        Parameters:
        file -
        limit - the limit in bytes to read
        Returns:
        the content of the file
        Throws:
        java.io.IOException
      • deleteRecursive

        public static final boolean deleteRecursive​(java.io.File file)
        CARE: delete all files and directories from this file or directory, this one included
        Parameters:
        file -
        Returns:
        True if all files were deleted
      • readInputStream

        public static final java.lang.String readInputStream​(java.io.InputStream input)
                                                      throws java.io.IOException
        Parameters:
        input - to read
        Returns:
        String
        Throws:
        javax.xml.stream.XMLStreamException
        java.io.IOException
      • createFileInTempDirectoryWithPathCheck

        public static java.io.File createFileInTempDirectoryWithPathCheck​(java.lang.String filename,
                                                                          java.lang.String fileExtension)
                                                                   throws java.io.IOException,
                                                                          IllegalPathException
        Creates a new empty file in the vitam temporary directory retrieved from VitamConfiguration, using the given filename and fileExtension strings to generate its name.
        Do a Path traversal attack check before creating file
        Parameters:
        filename - The prefix string to be used in generating the file's name; must be at least three characters long
        fileExtension - The suffix string to be used in generating the file's name; may be null, in which case the suffix ".tmp" will be used
        Returns:
        An abstract file representation for a newly-created empty file
        Throws:
        java.io.IOException - If a file could not be created
        IllegalPathException
      • getFileCanonicalPath

        public static java.lang.String getFileCanonicalPath​(java.lang.String pathname)
                                                     throws java.io.IOException
        retrieve the canonical path for a given file pathname
        Parameters:
        pathname -
        Returns:
        STring representing the canonical path for pathname file
        Throws:
        java.io.IOException - If an I/O errors occurs
      • fsyncFile

        public static void fsyncFile​(java.nio.file.Path path)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • convertInputStreamToFile

        public static java.io.File convertInputStreamToFile​(java.io.InputStream stream,
                                                            java.lang.String filename,
                                                            java.lang.String extension)
                                                     throws java.io.IOException,
                                                            IllegalPathException
        Throws:
        java.io.IOException
        IllegalPathException
      • convertInputStreamToFile

        public static java.io.File convertInputStreamToFile​(java.io.InputStream rulesStream,
                                                            java.lang.String filename)
                                                     throws java.io.IOException,
                                                            IllegalPathException
        Throws:
        java.io.IOException
        IllegalPathException