Class IOHelper

java.lang.Object
org.apache.activemq.util.IOHelper

public final class IOHelper extends Object
Collection of File and Folder utility methods.
  • Field Details

    • MAX_DIR_NAME_LENGTH

      protected static final int MAX_DIR_NAME_LENGTH
    • MAX_FILE_NAME_LENGTH

      protected static final int MAX_FILE_NAME_LENGTH
  • Method Details

    • scheduleAsyncDelete

      public static void scheduleAsyncDelete(File file)
      Schedule a file for async deletion. Used when immediate deletion fails on Windows. The file will be deleted in the background when it becomes unlocked.
    • deleteFileNonBlocking

      public static boolean deleteFileNonBlocking(File file)
      Non-blocking file deletion. Tries to delete once, and if it fails, schedules async cleanup instead of blocking with retries. This is safe to call from synchronized blocks as it never sleeps or retries.
      Parameters:
      file - the file to delete
      Returns:
      true if deleted immediately, false if scheduled for async cleanup
    • isWindows

      public static boolean isWindows()
      Check if we're running on Windows.
    • getDefaultDataDirectory

      public static String getDefaultDataDirectory()
    • getDefaultStoreDirectory

      public static String getDefaultStoreDirectory()
    • getDefaultDirectoryPrefix

      public static String getDefaultDirectoryPrefix()
      Allows a system property to be used to overload the default data directory which can be useful for forcing the test cases to use a target/ prefix
    • toFileSystemDirectorySafeName

      public static String toFileSystemDirectorySafeName(String name)
      Converts any string into a string that is safe to use as a file name. The result will only include ascii characters and numbers, and the "-","_", and "." characters.
      Parameters:
      name -
      Returns:
      safe name of the directory
    • toFileSystemSafeName

      public static String toFileSystemSafeName(String name)
    • toFileSystemSafeName

      public static String toFileSystemSafeName(String name, boolean dirSeparators, int maxFileLength)
      Converts any string into a string that is safe to use as a file name. The result will only include ascii characters and numbers, and the "-","_", and "." characters.
      Parameters:
      name -
      dirSeparators -
      maxFileLength -
      Returns:
      file system safe name
    • delete

      public static boolean delete(File top)
    • deleteFile

      public static boolean deleteFile(File fileToDelete)
    • deleteChildren

      public static boolean deleteChildren(File parent)
    • renameFile

      public static void renameFile(File src, File dest) throws IOException
      Rename a file to a new name/path. Non-blocking on failure. Strategy: rename -> NIO move -> copy + async delete of source.
      Parameters:
      src - the source file
      dest - the destination file (full path with new name)
      Throws:
      IOException
    • moveFile

      public static void moveFile(File src, File targetDirectory) throws IOException
      Move a file to a target directory. Non-blocking - uses async cleanup for source on Windows. Strategy: rename -> NIO move -> copy + async delete of source.
      Parameters:
      src - the source file to move
      targetDirectory - the target directory (must be a directory)
      Throws:
      IOException
    • moveFiles

      public static void moveFiles(File srcDirectory, File targetDirectory, FilenameFilter filter) throws IOException
      Throws:
      IOException
    • copyFile

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

      public static void copyFile(File src, File dest, FilenameFilter filter) throws IOException
      Throws:
      IOException
    • copySingleFile

      public static void copySingleFile(File src, File dest) throws IOException
      Throws:
      IOException
    • copyInputStream

      public static void copyInputStream(InputStream in, OutputStream out) throws IOException
      Throws:
      IOException
    • getMaxDirNameLength

      public static int getMaxDirNameLength()
    • getMaxFileNameLength

      public static int getMaxFileNameLength()
    • mkdirs

      public static void mkdirs(File dir) throws IOException
      Throws:
      IOException