Class FileUtil

java.lang.Object
org.red5.server.util.FileUtil

public class FileUtil extends Object
Generic file utility containing useful file or directory manipulation functions.
Author:
Paul Gregoire (mondain@gmail.com), Dominick Accattato (daccattato@gmail.com)
  • Field Details

    • log

      private static org.slf4j.Logger log
  • Constructor Details

    • FileUtil

      public FileUtil()
  • Method Details

    • copyFile

      public static void copyFile(File source, File dest) throws IOException
      Throws:
      IOException
    • copyFile

      public static void copyFile(String source, String dest) throws IOException
      Throws:
      IOException
    • moveFile

      public static void moveFile(String source, String dest) throws IOException
      Throws:
      IOException
    • deleteDirectory

      public static boolean deleteDirectory(String directory) 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 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 delete
      useOSNativeDelete - 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

      public static void rename(String from, String to)
      Rename a file natively; using REN on Windows and mv on *nix.
      Parameters:
      from - old name
      to - new name
    • stdOut

      private static final Thread stdOut(Process p)
      Special method for capture of StdOut.
      Returns:
      stdOut thread
    • makeDirectory

      public static boolean makeDirectory(String directory) throws IOException
      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

      public static boolean makeDirectory(String directory, boolean createParents) throws IOException
      Create a directory. The parent directories will be created if createParents is passed as true.
      Parameters:
      directory - directory
      createParents - whether to create all parents
      Returns:
      true if directory was created; false if it already existed
      Throws:
      IOException - if we cannot create directory
    • unzip

      public static void unzip(String compressedFileName, String destinationDir)
      Unzips a war file to an application located under the webapps directory
      Parameters:
      compressedFileName - The String name of the war file
      destinationDir - The destination directory, ie: webapps
    • copy

      public static void copy(InputStream in, OutputStream out) throws IOException
      Throws:
      IOException
    • formatPath

      public static String formatPath(String absWebappsPath, String contextDirName)
      Quick-n-dirty directory formatting to support launching in windows, specifically from ant.
      Parameters:
      absWebappsPath - abs webapps path
      contextDirName - conext directory name
      Returns:
      full path
    • generateCustomName

      public static String 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

      public static byte[] readAsByteArray(File localSwfFile)
      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