Package org.red5.server.util
Class FileUtil
java.lang.Object
org.red5.server.util.FileUtil
Generic file utility containing useful file or directory manipulation functions.
- Author:
- Paul Gregoire (mondain@gmail.com), Dominick Accattato (daccattato@gmail.com)
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
copy
(InputStream in, OutputStream out) static void
static void
static boolean
deleteDirectory
(String directory) Deletes a directory and its contents.static boolean
deleteDirectory
(String directory, boolean useOSNativeDelete) Deletes a directory and its contents.static String
formatPath
(String absWebappsPath, String contextDirName) Quick-n-dirty directory formatting to support launching in windows, specifically from ant.static String
Generates a custom name containing numbers and an underscore ex.static boolean
makeDirectory
(String directory) Create a directory.static boolean
makeDirectory
(String directory, boolean createParents) Create a directory.static void
static byte[]
readAsByteArray
(File localSwfFile) Reads all the bytes of a given file into an array.static void
Rename a file natively; using REN on Windows and mv on *nix.private static final Thread
Special method for capture of StdOut.static void
Unzips a war file to an application located under the webapps directory
-
Field Details
-
log
private static org.slf4j.Logger log
-
-
Constructor Details
-
FileUtil
public FileUtil()
-
-
Method Details
-
copyFile
- Throws:
IOException
-
copyFile
- Throws:
IOException
-
moveFile
- Throws:
IOException
-
deleteDirectory
Deletes a directory and its contents. This will fail if there are any file locks or if the directory cannot be emptied.- Parameters:
directory
- directory to delete- Returns:
- true if directory was successfully deleted; false if directory did not exist
- Throws:
IOException
- if directory cannot be deleted
-
deleteDirectory
public static boolean deleteDirectory(String directory, boolean useOSNativeDelete) throws IOException Deletes a directory and its contents. This will fail if there are any file locks or if the directory cannot be emptied.- Parameters:
directory
- directory to deleteuseOSNativeDelete
- flag to signify use of operating system delete function- Returns:
- true if directory was successfully deleted; false if directory did not exist
- Throws:
IOException
- if directory cannot be deleted
-
rename
Rename a file natively; using REN on Windows and mv on *nix.- Parameters:
from
- old nameto
- new name
-
stdOut
Special method for capture of StdOut.- Returns:
- stdOut thread
-
makeDirectory
Create a directory.- Parameters:
directory
- directory to make- Returns:
- whether a new directory was made
- Throws:
IOException
- if directory does not already exist or cannot be made
-
makeDirectory
Create a directory. The parent directories will be created if createParents is passed as true.- Parameters:
directory
- directorycreateParents
- whether to create all parents- Returns:
- true if directory was created; false if it already existed
- Throws:
IOException
- if we cannot create directory
-
unzip
Unzips a war file to an application located under the webapps directory- Parameters:
compressedFileName
- The String name of the war filedestinationDir
- The destination directory, ie: webapps
-
copy
- Throws:
IOException
-
formatPath
Quick-n-dirty directory formatting to support launching in windows, specifically from ant.- Parameters:
absWebappsPath
- abs webapps pathcontextDirName
- conext directory name- Returns:
- full path
-
generateCustomName
Generates a custom name containing numbers and an underscore ex. 282818_00023. The name contains current seconds and a random number component.- Returns:
- custom name
-
readAsByteArray
Reads all the bytes of a given file into an array. If the file size exceeds Integer.MAX_VALUE, it will be truncated.- Parameters:
localSwfFile
- swf file- Returns:
- file bytes
-