Package fr.gouv.vitam.common
Class FileUtil
- java.lang.Object
-
- fr.gouv.vitam.common.FileUtil
-
public final class FileUtil extends java.lang.ObjectFile Utility class
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.io.FileconvertInputStreamToFile(java.io.InputStream rulesStream, java.lang.String filename)static java.io.FileconvertInputStreamToFile(java.io.InputStream stream, java.lang.String filename, java.lang.String extension)static java.io.FilecreateFileInTempDirectoryWithPathCheck(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 filestatic booleandeleteRecursive(java.io.File file)CARE: delete all files and directories from this file or directory, this one includedstatic voidfsyncFile(java.nio.file.Path path)static java.lang.StringgetFileCanonicalPath(java.lang.String pathname)retrieve the canonical path for a given file pathnamestatic java.lang.StringreadFile(java.io.File file)static java.lang.StringreadFile(java.lang.String filename)static java.lang.StringreadInputStream(java.io.InputStream input)static java.lang.StringreadPartialFile(java.io.File file, int limit)
-
-
-
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.XMLStreamExceptionjava.io.IOException
-
createFileInTempDirectoryWithPathCheck
public static java.io.File createFileInTempDirectoryWithPathCheck(java.lang.String filename, java.lang.String fileExtension) throws java.io.IOException, IllegalPathExceptionCreates 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:
java.io.IOException- If a file could not be createdIllegalPathException
-
getFileCanonicalPath
public static java.lang.String getFileCanonicalPath(java.lang.String pathname) throws java.io.IOExceptionretrieve 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.IOExceptionIllegalPathException
-
convertInputStreamToFile
public static java.io.File convertInputStreamToFile(java.io.InputStream rulesStream, java.lang.String filename) throws java.io.IOException, IllegalPathException- Throws:
java.io.IOExceptionIllegalPathException
-
-