Package fr.gouv.vitam.common
Class FileUtil
java.lang.Object
fr.gouv.vitam.common.FileUtil
File Utility class
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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 filestatic final boolean
deleteRecursive
(File file) CARE: delete all files and directories from this file or directory, this one includedstatic void
static String
getFileCanonicalPath
(String pathname) retrieve the canonical path for a given file pathnamestatic final String
static final String
static final String
readInputStream
(InputStream input) static final String
readPartialFile
(File file, int limit)
-
Method Details
-
readFile
- Parameters:
filename
-- Returns:
- the content of the file
- Throws:
IOException
-
readFile
- Parameters:
file
-- Returns:
- the content of the file
- Throws:
IOException
-
readPartialFile
- Parameters:
file
-limit
- the limit in bytes to read- Returns:
- the content of the file
- Throws:
IOException
-
deleteRecursive
CARE: delete all files and directories from this file or directory, this one included- Parameters:
file
-- Returns:
- True if all files were deleted
-
readInputStream
- 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 longfileExtension
- The suffix string to be used in generating the file's name; may benull
, 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 createdIllegalPathException
-
getFileCanonicalPath
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
- 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
-