Package org.eclnt.util.file
Class FileManager
java.lang.Object
org.eclnt.util.file.FileManager
Helper class for all functions that have to do with File I/O withith the CaptainCasa
runtime.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
addAllowedRootDirectoryRead
(String rootDirectoryName) static void
addAllowedRootDirectoryReadWrite
(String rootDirectoryName) You may pass directory names, that restrict the file access.static void
appendToFile
(String fileName, byte[] data, boolean withError) static void
appendUTF8ToFile
(String fileName, String text, boolean withError) static boolean
checkIfFileExists
(String fileName) static boolean
checkIfFileExists
(String fileName, boolean internalCall) static void
Counter part toopenFileOutputStream(String, boolean)
.static void
copyDirectory
(String fromDirectory, String toDirectory, String[] ignoreNames, boolean withError) static void
copyDirectory
(String fromDirectory, String toDirectory, String[] ignoreNames, boolean withError, IObserver observer) static void
static void
static boolean
createDirectory
(String directory) static File
createFileInstance
(String fileName) static void
deleteDirectory
(String dirName) Deletes a directory with all its contained sub-directories and files.static void
deleteDirectoryContent
(String dirName) Deletes the content of a directory - without removing the directory itself.static void
deleteDirectoryContent
(String dirName, boolean deleteSubDirectories) Deletes the content of a directory - without removing the directory itself.static void
deleteFile
(String fileName) static void
ensureDirectoryExists
(String dirName) Ensure that a certain directory exists.static void
ensureDirectoryForFileExists
(String fileName) Ensure that the directory for the file exists.static void
ensureFileIsWriteable
(String fileName, boolean withError) getDirectoriesOfDirectory
(String directoryName) getFilesOfDirectory
(String directoryName) getFilesOfDirectoryByPattern
(String directoryName, String extension) getFilesOfDirectoryByPattern
(String directoryName, String[] extensions) 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.static File
Returns the operating system's temp directory.static boolean
static FileOutputStream
openFileOutputStream
(String fileName, boolean withError) Opens output stream.static byte[]
static InputStream
readFileInputStream
(String fileName, boolean withError) static byte[]
readLastBytesOfFile
(File file, int numberOfBytes, boolean withError) 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.static String
readUTF8File
(String fileName, boolean withError) static void
replaceInUTF8File
(File file, List<String[]> fromTos, boolean withError) 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.static void
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.static void
writeUTF8File
(String fileName, String content, boolean withError)
-
Constructor Details
-
FileManager
public FileManager()
-
-
Method Details
-
addAllowedRootDirectoryReadWrite
You may pass directory names, that restrict the file access. The FileManager will only access files that are below the root directories. -
addAllowedRootDirectoryRead
-
getFilesOfDirectoryByPattern
- Parameters:
extensions
- Only these files are returned which exactly end with one of the extensions.- Returns:
- List of absolute file names
-
getFilesOfDirectoryByPattern
- 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
-
getDirectoriesOfDirectory
-
ensureDirectoryForFileExists
Ensure that the directory for the file exists. If it does not exist then it will be created. -
ensureDirectoryExists
Ensure that a certain directory exists. If not exists then it will be created. -
checkIfFileExists
-
checkIfFileExists
-
deleteDirectory
Deletes a directory with all its contained sub-directories and files. -
deleteDirectoryContent
Deletes the content of a directory - without removing the directory itself. -
deleteDirectoryContent
Deletes the content of a directory - without removing the directory itself. -
deleteFile
-
readUTF8File
-
readTextFile
Encoding can be passes as null value - in this case the VMs default encoding is used. -
readLastBytesOfFile
-
readFile
-
readFileInputStream
-
ensureFileIsWriteable
-
writeUTF8File
-
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
-
mkdir
-
createDirectory
-
createFileInstance
-
copyFile
-
copyFile
-
copyDirectory
-
copyDirectory
-
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
-
appendToFile
-
openFileOutputStream
Opens output stream. The closing needs to be explicitly done by the caller! Close the stream by calling methodcloseFileOutputStream(FileOutputStream)
. -
closeFileOutputStream
Counter part toopenFileOutputStream(String, boolean)
. -
getTempFileDirectory
Returns the operating system's temp directory. -
replaceInUTF8File
-