Package org.opends.quicksetup.util
Class FileManager
- java.lang.Object
-
- org.opends.quicksetup.util.FileManager
-
public class FileManager extends Object
Utility class for use by applications containing methods for managing file system files. This class handles application notifications for interesting events.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFileManager.DeletionPolicyDescribes the approach taken to deleting a file or directory.
-
Constructor Summary
Constructors Constructor Description FileManager()Creates a new file manager.FileManager(Application app)Creates a new file manager.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Filecopy(File objectFile, File destDir)Copies everything below the specified file.Filecopy(File objectFile, File destDir, boolean overwrite)Copies everything below the specified file.voidcopyRecursively(File objectFile, File destDir)Copies everything below the specified file.voidcopyRecursively(File objectFile, File destDir, FileFilter filter)Copies everything below the specified file.voidcopyRecursively(File objectFile, File destDir, FileFilter filter, boolean overwrite)Copies everything below the specified file.voiddelete(File object)Deletes a single file or directory.voiddelete(File object, FileFilter filter)Deletes a single file or directory.voiddeleteChildren(File parentDir)Deletes the children of a directory.voiddeleteRecursively(File file)Deletes everything below the specified file.voiddeleteRecursively(File file, FileFilter filter, FileManager.DeletionPolicy deletePolicy)Deletes everything below the specified file.booleanfilesDiffer(File f1, File f2)Determines whether two files differ in content.voidmove(File object, File newParent)Move a file.voidmove(File object, File newParent, FileFilter filter)Move a file.voidrename(File fileToRename, File target)Renames the source file to the target file.voidsynchronize(File source, File target)Recursively copies any files or directories appearing insourceor a subdirectory ofsourceto the corresponding directory undertarget.
-
-
-
Constructor Detail
-
FileManager
public FileManager()
Creates a new file manager.
-
FileManager
public FileManager(Application app)
Creates a new file manager.- Parameters:
app- Application managing files to which progress notifications will be sent
-
-
Method Detail
-
synchronize
public void synchronize(File source, File target) throws ApplicationException
Recursively copies any files or directories appearing insourceor a subdirectory ofsourceto the corresponding directory undertarget. Files in undersourceare not copied totargetif a file by the same name already exists intarget.- Parameters:
source- source directorytarget- target directory- Throws:
ApplicationException- if there is a problem copying files
-
rename
public void rename(File fileToRename, File target) throws ApplicationException
Renames the source file to the target file. If the target file exists it is first deleted. The rename and delete operation return values are checked for success and if unsuccessful, this method throws an exception.- Parameters:
fileToRename- The file to rename.target- The file to whichfileToRenamewill be moved.- Throws:
ApplicationException- If a problem occurs while attempting to rename the file. On the Windows platform, this typically indicates that the file is in use by this or another application.
-
move
public void move(File object, File newParent) throws ApplicationException
Move a file.- Parameters:
object- File to movenewParent- File representing new parent directory- Throws:
ApplicationException- if something goes wrong
-
move
public void move(File object, File newParent, FileFilter filter) throws ApplicationException
Move a file.- Parameters:
object- File to movenewParent- File representing new parent directoryfilter- that will be asked whether the operation should be performed- Throws:
ApplicationException- if something goes wrong
-
delete
public void delete(File object) throws ApplicationException
Deletes a single file or directory.- Parameters:
object- File to delete- Throws:
ApplicationException- if something goes wrong
-
delete
public void delete(File object, FileFilter filter) throws ApplicationException
Deletes a single file or directory.- Parameters:
object- File to deletefilter- that will be asked whether the operation should be performed- Throws:
ApplicationException- if something goes wrong
-
deleteChildren
public void deleteChildren(File parentDir) throws ApplicationException
Deletes the children of a directory.- Parameters:
parentDir- the directory whose children is deleted- Throws:
ApplicationException- if there is a problem deleting children
-
deleteRecursively
public void deleteRecursively(File file) throws ApplicationException
Deletes everything below the specified file.- Parameters:
file- the path to be deleted.- Throws:
ApplicationException- if something goes wrong.
-
deleteRecursively
public void deleteRecursively(File file, FileFilter filter, FileManager.DeletionPolicy deletePolicy) throws ApplicationException
Deletes everything below the specified file.- Parameters:
file- the path to be deleted.filter- the filter of the files to know if the file can be deleted directly or not.deletePolicy- describes how deletions are to be made JVM exits rather than deleting the files immediately.- Throws:
ApplicationException- if something goes wrong.
-
copy
public File copy(File objectFile, File destDir) throws ApplicationException
Copies everything below the specified file.- Parameters:
objectFile- the file to be copied.destDir- the directory to copy the file to- Returns:
- File representing the destination
- Throws:
ApplicationException- if something goes wrong.
-
copy
public File copy(File objectFile, File destDir, boolean overwrite) throws ApplicationException
Copies everything below the specified file.- Parameters:
objectFile- the file to be copied.destDir- the directory to copy the file tooverwrite- overwrite destination files.- Returns:
- File representing the destination
- Throws:
ApplicationException- if something goes wrong.
-
copyRecursively
public void copyRecursively(File objectFile, File destDir) throws ApplicationException
Copies everything below the specified file.- Parameters:
objectFile- the file to be copied.destDir- the directory to copy the file to- Throws:
ApplicationException- if something goes wrong.
-
copyRecursively
public void copyRecursively(File objectFile, File destDir, FileFilter filter) throws ApplicationException
Copies everything below the specified file.- Parameters:
objectFile- the file to be copied.destDir- the directory to copy the file tofilter- the filter of the files to know if the file can be copied directly or not.- Throws:
ApplicationException- if something goes wrong.
-
copyRecursively
public void copyRecursively(File objectFile, File destDir, FileFilter filter, boolean overwrite) throws ApplicationException
Copies everything below the specified file.- Parameters:
objectFile- the file to be copied.destDir- the directory to copy the file tofilter- the filter of the files to know if the file can be copied directly or not.overwrite- overwrite destination files.- Throws:
ApplicationException- if something goes wrong.
-
filesDiffer
public boolean filesDiffer(File f1, File f2) throws IOException
Determines whether two files differ in content.- Parameters:
f1- file to comparef2- file to compare- Returns:
- boolean where true indicates that two files differ
- Throws:
IOException- if there is a problem reading the files' contents
-
-