Package fr.gouv.vitam.common

# Class FileUtil

java.lang.Object
fr.gouv.vitam.common.FileUtil

public final class FileUtil extends Object
File Utility class

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static File`
  `convertInputStreamToFile(InputStream rulesStream, String filename)`
  `static File`
  `convertInputStreamToFile(InputStream stream, String filename, String extension)`
  `static File`
  `createFileInTempDirectoryWithPathCheck(String filename, 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 final boolean`
  `deleteRecursive(File file)`
  CARE: delete all files and directories from this file or directory, this one included
  `static void`
  `fsyncFile(Path path)`
  `static String`
  `getFileCanonicalPath(String pathname)`
  retrieve the canonical path for a given file pathname
  `static final String`
  `readFile(File file)`
  `static final String`
  `readFile(String filename)`
  `static final String`
  `readInputStream(InputStream input)`
  `static final String`
  `readPartialFile(File file, int limit)`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### readFile

    public static final String readFile(String filename) throws IOException
    Parameters:
      `filename` -
    Returns:
      the content of the file
    Throws:
      `IOException`

  - ### readFile

    public static final String readFile(File file) throws IOException
    Parameters:
      `file` -
    Returns:
      the content of the file
    Throws:
      `IOException`

  - ### readPartialFile

    public static final String readPartialFile(File file, int limit) throws IOException
    Parameters:
      `file` -
      `limit` - the limit in bytes to read
    Returns:
      the content of the file
    Throws:
      `IOException`

  - ### deleteRecursive

    public static final boolean deleteRecursive(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 String readInputStream(InputStream input) throws IOException
    Parameters:
      `input` - to read
    Returns:
      String
    Throws:
      `XMLStreamException`
      `IOException`

  - ### createFileInTempDirectoryWithPathCheck

    public static File createFileInTempDirectoryWithPathCheck(String filename, String fileExtension) throws 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:
      `IOException` - If a file could not be created
      `IllegalPathException`

  - ### getFileCanonicalPath

    public static String getFileCanonicalPath(String pathname) throws IOException
    retrieve the canonical path for a given file pathname
    Parameters:
      `pathname` -
    Returns:
      STring representing the canonical path for pathname file
    Throws:
      `IOException` - If an I/O errors occurs

  - ### fsyncFile

    public static void fsyncFile(Path path) throws IOException
    Throws:
      `IOException`

  - ### convertInputStreamToFile

    public static File convertInputStreamToFile(InputStream stream, String filename, String extension) throws IOException, IllegalPathException
    Throws:
      `IOException`
      `IllegalPathException`

  - ### convertInputStreamToFile

    public static File convertInputStreamToFile(InputStream rulesStream, String filename) throws IOException, IllegalPathException
    Throws:
      `IOException`
      `IllegalPathException`