Package be.gaudry.model.file
Class FileUtils
java.lang.Object
be.gaudry.model.file.FileUtils
- All Implemented Interfaces:
PropertyChangeListener
,EventListener
Allows to manage files and paths. \n
Interacts also with the operating system to provide some features like the
name and the icon of a root file if it's a hard disk or a CDRom, etc.
\n
Provided by the broldev.core.model project.
- Since:
- 1.0 Sep 10, 2008, broldev.core.model 0.0.1-SNAPSHOT dependency
- Version:
- 1.3 Dec 5 2011
- Author:
- Steph GAUDRY
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
Deprecated.static boolean
copyAndReplace(File source, File target)
Copy a file from a source to a target.static boolean
deleteDirectory(File file)
Deprecated.static void
deleteDirectory(Path directoryPath)
protected void
finalize()
static String
static String
getApplicationPath(Class<?> startingClass, boolean cached)
System.getProperty("user.dir")
does not return class directory each time.static File
Returns the user's desktop folder.static String
Returns the user's desktop folder localized name.static long
getDirectoryLength(AbstractBrolWorker bgw, File root, boolean includeSubFolders)
Parses the sub directories to get the total size of a given directory.protected static JFileChooser
static String
getFileExtension(File file)
Returns a "Windows like" String with the file extension without the dot.static String
getFileExtension(String fileName)
Returns a "Windows like" String with the file extension without the dot.static Date
getFileModificationDate(File file)
Returns the time that the file was last modified.static String
Returns a localized string (never null) with the time that the file was last modified or a short localized message on error.static int
getFilesCount(AbstractBrolWorker bgw, File root, int counter)
Parses the sub directories to get the total size of a given directory.static String
getFileSizeString(File file)
Returns a localized string (never null) with the size of the file or a localized error message (file not found, etc).(package private) static FileSystemView
static Icon
Returns a system dependent icon for the generic filesstatic Icon
Returns a system dependent icon for the generic folders The system dependent icons for customized folders are available by calling thegetSystemIcon(File)
methodstatic File
getIncrementedFile(File file)
static String
getLocaleStr(String key, String defaultStr)
Loads the localized string matching the key if exists.static Icon
Returns the platform version of an icon for the Use a cache to store systemicons
icon.static String
Returns a localized version of the "Windows like" string of "My computer".static String
Provides a way to get the absolute path of the user's documents directory, becauseSystem.getProperty("user.home")
gives the user directory and not the user documents directory.static String
getSystemDisplayName(File file)
Returns a string (never null) with the platform dependent name of the file or a localized error message (file not found, etc).static String
getSystemDisplayName(File file, boolean rootFile)
Returns a string (never null) with the platform dependent name of the file or a localized error message (file not found, etc).static Icon
getSystemIcon(File file)
Returns the system dependent icon for a given file.static String
getSystemTypeDescription(File file)
Returns a string (never null) with a platform dependent description of the file or a localized error message (file not found, etc).static boolean
Launches the default application to open the file.void
Localize this instance when the observedLanguageHelper
is changed.protected void
Localize some strings using theLanguageHelper
features.
-
Field Details
-
LANGUAGE_PATH
Key to access to the language resource bundle- See Also:
- Constant Field Values
-
iconCache
Icon cache to speed the rendering.
-
-
Method Details
-
finalize
-
propertyChange
Localize this instance when the observedLanguageHelper
is changed.- Specified by:
propertyChange
in interfacePropertyChangeListener
- Since:
- 1.2 (Mar 30, 2009)
-
setLanguage
protected void setLanguage()Localize some strings using theLanguageHelper
features. See thelogging information
to know how the logging is implemented. -
getLocaleStr
Loads the localized string matching the key if exists. If any problem occurs, return the defaultStr value.- Parameters:
key
- to access to the localized stringdefaultStr
- default value if a problem occurs- Returns:
- localized string
-
getFileExtension
Returns a "Windows like" String with the file extension without the dot.- Parameters:
fileName
- name of the file from wich we need the extension- Returns:
- the extension, or an empty string on error
-
getFileExtension
Returns a "Windows like" String with the file extension without the dot.- Parameters:
file
- from wich we need the extension- Returns:
- the extension, or an empty string on error
-
getDirectoryLength
public static long getDirectoryLength(AbstractBrolWorker bgw, File root, boolean includeSubFolders)Parses the sub directories to get the total size of a given directory.- Parameters:
bgw
- SearchFilesWorker to cancel operation and report progressroot
- directory from wich we need the lengthincludeSubFolders
- add all sub directories informations (recursive method)- Returns:
- length of the directory in bytes
-
getFilesCount
Parses the sub directories to get the total size of a given directory. \n TODO: internationalize the reported message- Parameters:
bgw
- SearchFilesWorker to cancel operation and report progressroot
- directory from wich we need the lengthcounter
-- Returns:
- count of files
-
open
Launches the default application to open the file.If the specified file is a directory, the file manager of the current platform is launched to open it. On some platforms this feature may not be supported; in this case, the return value is false and the method call does nothing. See the
logging information
to know how the logging is implemented.- Parameters:
file
- the file to be opened with the associated application- Returns:
- true if the operation is supported by the platform
- Throws:
NullPointerException
- iffile
isnull
IllegalArgumentException
- if the specified file dosen't existUnsupportedOperationException
- if the current platform does not support the open actionSecurityException
- if a security manager exists and itsSecurityManager.checkRead(java.lang.String)
method denies read access to the file, or it denies theAWTPermission("showWindowWithoutWarningBanner")
permission, or the calling thread is not allowed to create a subprocess
-
getMyDocumentsPath
Provides a way to get the absolute path of the user's documents directory, becauseSystem.getProperty("user.home")
gives the user directory and not the user documents directory. See thelogging information
to know how the logging is implemented.- Returns:
- a
File
object representing the default starting folder
-
getApplicationPath
- Returns:
- path of this file
- Since:
- 1.2 (Feb 12 2009)
- See Also:
getApplicationPath(Class, boolean)
-
getApplicationPath
System.getProperty("user.dir")
does not return class directory each time. If we start a java application from a command prompt by giving the path (not usingcd
command to set the active directory), user.dir contains the active directory and not the application directory. See thelogging information
to know how the logging is implemented.- Parameters:
startingClass
- class wich we need to know directorycached
-true
to avoid doing the parsing each time. The result is stored as cache after the first call.false
to ignore cached result (this does not affect the cached result).
- Returns:
- path of the class arg
- Since:
- 1.2 (Feb 12 2009)
-
deleteDirectory
-
deleteDirectory
Deprecated.Removes a directory from the files system.- Parameters:
file
- file to delete- Returns:
- true if the file has been deleted
-
getFileChooser
-
getFileSystemView
-
getFileModificationDateString
Returns a localized string (never null) with the time that the file was last modified or a short localized message on error. See the debuglog
for more information about the error. \n Be careful than some differences may be found depending on the platform.- Parameters:
file
- the file that we want the last modification date- Returns:
- last modification date of the file, or a localized error message
-
getFileModificationDate
Returns the time that the file was last modified. \n BeSee thelogging information
to know how the logging is implemented.latform. See thelogging
See thelogging information
to know how the logging is implemented.fication date- Parameters:
file
- the file that we want the last modification date- Returns:
- the last modification date of a file, or null on error
-
getSystemTypeDescription
Returns a string (never null) with a platform dependent description of the file or a localized error message (file not found, etc).- Parameters:
file
- wich we want the description- Returns:
- the file description or the error message
-
getSystemDisplayName
Returns a string (never null) with the platform dependent name of the file or a localized error message (file not found, etc). This is mostly useful for special system files like an IO device or user's documents directory, etc.- Parameters:
file
- wich we want the system name- Returns:
- the system name of the file or the error message
- See Also:
getSystemDisplayName(File, boolean)
-
getSystemDisplayName
Returns a string (never null) with the platform dependent name of the file or a localized error message (file not found, etc). This is mostly useful for special system files like an IO device or user's documents directory, etc. Does not output into thelog
on error to improve performances on iterated call of this method (parsing the system files).- Parameters:
file
- wich we want the system namerootFile
-- Returns:
- the system name of the file or the error message
-
getFileSizeString
Returns a localized string (never null) with the size of the file or a localized error message (file not found, etc). Does not output into thelog
on error to improve performances on iterated call of this method (parsing the system files).- Parameters:
file
- wich we want the size- Returns:
- the string of the size or a localized message
- See Also:
UnitUtils.getLengthString(long)
-
getDesktopFolder
Returns the user's desktop folder.- Returns:
- the desktop folder
-
getDesktopName
Returns the user's desktop folder localized name.- Returns:
- the desktop name
-
getMyComputerName
Returns a localized version of the "Windows like" string of "My computer". "My Computer" is not a real file, but a kind of root of the storage devices.- Returns:
- the localized string
-
getMyComputerIcon
Returns the platform version of an icon for the Use a cache to store systemicons
icon.- Returns:
- System
Icon
of my computer - See Also:
getMyComputerName()
-
getSystemIcon
Returns the system dependent icon for a given file. Never returns null :- if the file is null or not exists, return a new
MissingIcon
. - returns a system dependent default file or folder icon on error
icons
by file extension. Exe files and folders are not cached. \n TODO: check linux default icons (can't use gnome themes?) \n TODO: don't use cache for images files, use thumbnails???- Parameters:
file
- wich we want the icon- Returns:
- System
Icon
of a given file
- if the file is null or not exists, return a new
-
getGenericFileIcon
Returns a system dependent icon for the generic files- Returns:
- the generic file icon
-
getGenericFolderIcon
Returns a system dependent icon for the generic folders The system dependent icons for customized folders are available by calling thegetSystemIcon(File)
method- Returns:
- the generic folder icon
-
copyAndReplace
Copy a file from a source to a target. \n If the parent folder of the target doesn't exist, the target structure is created. The target file is replaced if already exists.- Parameters:
source
- file to copytarget
- copied file- Returns:
- true if the file is copied (a warning is also sent to the logger in case of failure)
- Since:
- 1.3 (Dec 5, 2011)
-
copy
Deprecated.1.3 (Dec 5, 2011) seecopyAndReplace(File, File)
Copy a file from a source to a target. \n If the parent folder of the target doesn't exist, the target structure is created. The target file is replaced if already exists.- Parameters:
source
- file to copytarget
- copied file- Returns:
- true if the file is copied (a warning is also sent to the logger in case of failure)
-
getIncrementedFile
-
copyAndReplace(File, File)