Class FileUtils
java.lang.Object
fr.paris.lutece.plugins.resource.util.FileUtils
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcleanDirectory(File directory) Clean a directory without deleting it.static voidcopy(InputStream input, OutputStream output) Copy bytes from anInputStreamto anOutputStream.static voidcopy(InputStream input, OutputStream output, int bufferSize) Copy bytes from anInputStreamto anOutputStream.static voidcopy(InputStream input, Writer output, String encoding, int bufferSize) Copy and convert bytes from anInputStreamto chars on aWriter, using the specified encoding.static voidCopy chars from aReaderto aWriter.static FilecreateTempFile(String prefix, String suffix, File parentDir) Create a temporary file in a given directory.static voiddeleteDirectory(File directory) Recursively delete a directory.static Stringstatic Stringstatic voidfileWrite(Path path, String encoding, String data, OpenOption... openOptions) static voidforceDelete(File file) Delete a file.static Stringstatic StringtoString(InputStream input, String encoding) static StringtoString(InputStream input, String encoding, int bufferSize)
-
Field Details
-
FAMILY_WINDOWS
- See Also:
-
OS_NAME
-
-
Constructor Details
-
FileUtils
public FileUtils()
-
-
Method Details
-
createTempFile
Create a temporary file in a given directory.
The file denoted by the returned abstract pathname did not exist before this method was invoked, any subsequent invocation of this method will yield a different file name.
The filename is prefixNNNNNsuffix where NNNN is a random number
This method is different to
File.createTempFile(String, String, File)of JDK 1.2 as it doesn't create the file itself. It uses the location pointed to by java.io.tmpdir when the parentDir attribute is null.To delete automatically the file created by this method, use the
File.deleteOnExit()method.- Parameters:
prefix- prefix before the random numbersuffix- file extension; include the '.'parentDir- Directory to create the temporary file in-java.io.tmpdirused if not specificed- Returns:
- a File reference to the new temporary file.
-
copy
public static void copy(InputStream input, Writer output, String encoding, int bufferSize) throws IOException Copy and convert bytes from anInputStreamto chars on aWriter, using the specified encoding.- Parameters:
input- to convertoutput- the resultencoding- The name of a supported character encoding. See the IANA Charset Registry for a list of valid encoding types.bufferSize- Size of internal buffer to use.- Throws:
IOException- io issue
-
copy
Copy chars from aReaderto aWriter.- Parameters:
input- to convertoutput- the resultbufferSize- Size of internal buffer to use.- Throws:
IOException- io issue
-
toString
- Parameters:
input- to convertencoding- The name of a supported character encoding. See the IANA Charset Registry for a list of valid encoding types.- Returns:
- Get the contents of an
InputStreamas a String. - Throws:
IOException- io issue
-
toString
public static String toString(InputStream input, String encoding, int bufferSize) throws IOException - Parameters:
input- to convertencoding- The name of a supported character encoding. See the IANA Charset Registry for a list of valid encoding types.bufferSize- Size of internal buffer to use.- Returns:
- Get the contents of an
InputStreamas a String. - Throws:
IOException- io issue
-
copy
Copy bytes from anInputStreamto anOutputStream.- Parameters:
input- to convertoutput- the resultbufferSize- Size of internal buffer to use.- Throws:
IOException- io issue
-
copy
Copy bytes from anInputStreamto anOutputStream.- Parameters:
input- to convertoutput- the result- Throws:
IOException- io issue
-
fileRead
- Parameters:
file- the file pathencoding- the wanted encoding- Returns:
- the file content using the specified encoding.
- Throws:
IOException- if any
-
fileRead
- Throws:
IOException
-
fileWrite
public static void fileWrite(Path path, String encoding, String data, OpenOption... openOptions) throws IOException - Throws:
IOException
-
forceDelete
Delete a file. If file is directory delete it and all sub-directories.- Parameters:
file- a file- Throws:
IOException- if any
-
deleteDirectory
Recursively delete a directory.- Parameters:
directory- a directory- Throws:
IOException- if any
-
cleanDirectory
Clean a directory without deleting it.- Parameters:
directory- a directory- Throws:
IOException- if any
-
getBasedir
-