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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddAllowedRootDirectoryRead(String rootDirectoryName) static voidaddAllowedRootDirectoryReadWrite(String rootDirectoryName) You may pass directory names, that restrict the file access.static voidappendToFile(String fileName, byte[] data, boolean withError) static voidappendUTF8ToFile(String fileName, String text, boolean withError) static booleancheckIfFileExists(String fileName) static booleancheckIfFileExists(String fileName, boolean internalCall) static voidCounter part toopenFileOutputStream(String, boolean).static voidcopyDirectory(String fromDirectory, String toDirectory, String[] ignoreNames, boolean withError) static voidcopyDirectory(String fromDirectory, String toDirectory, String[] ignoreNames, boolean withError, IObserver observer) static voidstatic voidstatic booleancreateDirectory(String directory) static FilecreateFileInstance(String fileName) static voiddeleteDirectory(String dirName) Deletes a directory with all its contained sub-directories and files.static voiddeleteDirectoryContent(String dirName) Deletes the content of a directory - without removing the directory itself.static voiddeleteDirectoryContent(String dirName, boolean deleteSubDirectories) Deletes the content of a directory - without removing the directory itself.static voiddeleteFile(String fileName) static voidensureDirectoryExists(String dirName) Ensure that a certain directory exists.static voidensureDirectoryForFileExists(String fileName) Ensure that the directory for the file exists.static voidensureFileIsWriteable(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 FileReturns the operating system's temp directory.static booleanstatic FileOutputStreamopenFileOutputStream(String fileName, boolean withError) Opens output stream.static byte[]static InputStreamreadFileInputStream(String fileName, boolean withError) static byte[]readLastBytesOfFile(File file, int numberOfBytes, boolean withError) static StringreadTextFile(String fileName, String encoding, boolean withError) Encoding can be passes as null value - in this case the VMs default encoding is used.static StringreadUTF8File(String fileName, boolean withError) static voidreplaceInUTF8File(File file, List<String[]> fromTos, boolean withError) static voidupdateDirectory(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 voidstatic voidwriteTextFile(String fileName, String content, String encoding, boolean withError) Encoding can be passed as null - in this case the VMs default encoding is used.static voidwriteUTF8File(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
-