Class FileManager

java.lang.Object
org.eclnt.util.file.FileManager

public class FileManager extends Object
Helper class for all functions that have to do with File I/O withith the CaptainCasa runtime.
  • Constructor Details

    • FileManager

      public FileManager()
  • Method Details

    • addAllowedRootDirectoryReadWrite

      public static void addAllowedRootDirectoryReadWrite(String rootDirectoryName)
      You may pass directory names, that restrict the file access. The FileManager will only access files that are below the root directories.
    • addAllowedRootDirectoryRead

      public static void addAllowedRootDirectoryRead(String rootDirectoryName)
    • getFilesOfDirectoryByPattern

      public static List<String> getFilesOfDirectoryByPattern(String directoryName, String[] extensions)
      Parameters:
      extensions - Only these files are returned which exactly end with one of the extensions.
      Returns:
      List of absolute file names
    • getFilesOfDirectoryByPattern

      public static List<String> getFilesOfDirectoryByPattern(String directoryName, String extension)
      Parameters:
      extension - Only these files are returned which exactly end with the extension.
      Returns:
      List of absolute file names
    • getFilesOfDirectoryByPattern

      public static List<String> getFilesOfDirectoryByPattern(String directoryName, String pattern, String extension)
      Pattern search: in certain scenarios there are many files in one directory that follow one naming pattern:
      Example: system.xml, system.variant1.xml, system.variant2.xml
      By passing pattern "system" and extension ".xml" this method will return all "system.*.xml" files of the directory.
      Parameters:
      extension - Only these files are returned which exactly end with the extension.
      pattern - Only these files are returned which exactly start with this pattern followed by a ".".
      Returns:
      List of absolute file names
    • getFilesOfDirectory

      public static List<File> getFilesOfDirectory(String directoryName)
    • getDirectoriesOfDirectory

      public static List<File> getDirectoriesOfDirectory(String directoryName)
    • ensureDirectoryForFileExists

      public static void ensureDirectoryForFileExists(String fileName)
      Ensure that the directory for the file exists. If it does not exist then it will be created.
    • ensureDirectoryExists

      public static void ensureDirectoryExists(String dirName)
      Ensure that a certain directory exists. If not exists then it will be created.
    • checkIfFileExists

      public static boolean checkIfFileExists(String fileName)
    • checkIfFileExists

      public static boolean checkIfFileExists(String fileName, boolean internalCall)
    • deleteDirectory

      public static void deleteDirectory(String dirName)
      Deletes a directory with all its contained sub-directories and files.
    • deleteDirectoryContent

      public static void deleteDirectoryContent(String dirName)
      Deletes the content of a directory - without removing the directory itself.
    • deleteDirectoryContent

      public static void deleteDirectoryContent(String dirName, boolean deleteSubDirectories)
      Deletes the content of a directory - without removing the directory itself.
    • deleteFile

      public static void deleteFile(String fileName)
    • readUTF8File

      public static String readUTF8File(String fileName, boolean withError)
    • readTextFile

      public static String readTextFile(String fileName, String encoding, boolean withError)
      Encoding can be passes as null value - in this case the VMs default encoding is used.
    • readLastBytesOfFile

      public static byte[] readLastBytesOfFile(File file, int numberOfBytes, boolean withError)
    • readFile

      public static byte[] readFile(String fileName, boolean withError)
    • readFileInputStream

      public static InputStream readFileInputStream(String fileName, boolean withError)
    • ensureFileIsWriteable

      public static void ensureFileIsWriteable(String fileName, boolean withError)
    • writeUTF8File

      public static void writeUTF8File(String fileName, String content, boolean withError)
    • writeTextFile

      public static void writeTextFile(String fileName, String content, String encoding, boolean withError)
      Encoding can be passed as null - in this case the VMs default encoding is used.
    • writeFile

      public static void writeFile(String fileName, byte[] bytes, boolean withError)
    • mkdir

      public static boolean mkdir(String directory)
    • createDirectory

      public static boolean createDirectory(String directory)
    • createFileInstance

      public static File createFileInstance(String fileName)
    • copyFile

      public static void copyFile(String fromFile, String toFile, boolean withError)
    • copyFile

      public static void copyFile(String fromFile, String toFile, int bufferSize, boolean withError)
    • copyDirectory

      public static void copyDirectory(String fromDirectory, String toDirectory, String[] ignoreNames, boolean withError)
    • copyDirectory

      public static void copyDirectory(String fromDirectory, String toDirectory, String[] ignoreNames, boolean withError, IObserver observer)
    • updateDirectory

      public static void updateDirectory(String fromDirectory, String toDirectory, String[] ignoreNames, boolean withError, IObserver observer)
      Copies the files from the fromDirectory into the toDirectory - but only copies these files which are newer in the fromDirectory than in the toDirectory. So "newer" content in the toDirectory will not be changed.
    • appendUTF8ToFile

      public static void appendUTF8ToFile(String fileName, String text, boolean withError)
    • appendToFile

      public static void appendToFile(String fileName, byte[] data, boolean withError)
    • openFileOutputStream

      public static FileOutputStream openFileOutputStream(String fileName, boolean withError)
      Opens output stream. The closing needs to be explicitly done by the caller! Close the stream by calling method closeFileOutputStream(FileOutputStream).
    • closeFileOutputStream

      public static void closeFileOutputStream(FileOutputStream fos)
    • getTempFileDirectory

      public static File getTempFileDirectory()
      Returns the operating system's temp directory.
    • replaceInUTF8File

      public static void replaceInUTF8File(File file, List<String[]> fromTos, boolean withError)