com.alee.utils
Class FileUtils

java.lang.Object
  extended by com.alee.utils.FileUtils

public final class FileUtils
extends java.lang.Object

This class provides a set of utilities to work with files, file names and their extensions.

Note that methods which request information about files from the system has their own caches to improve performance. If you will need to clear that cache simply call the corresponding clearCache method, for example: For method "isHidden" you will need to call "clearIsHiddenCache" and all cached values will be resetted.

Author:
Mikle Garin

Field Summary
static long GB
          Number of bytes in 1 gigabyte.
static long KB
          Number of bytes in 1 kilobyte.
static long MB
          Number of bytes in 1 megabyte.
static long PB
          Number of bytes in 1 petabyte.
 
Constructor Summary
FileUtils()
           
 
Method Summary
static java.lang.String canonicalPath(java.io.File file)
          Returns file canonical path if its possible or absolute path otherwise.
static void clearDirectory(java.io.File dir)
          Deletes all child files and directories for specified directory.
static void clearDisplayFileCreationDateCache()
          Clears cache for "getDisplayFileCreationDate" method.
static void clearDisplayFileCreationDateCache(java.lang.String absolutePath)
          Clears cache for "getDisplayFileCreationDate" method for specified file path.
static void clearDisplayFileModificationDateCache()
          Clears cache for "getDisplayFileModificationDate" method.
static void clearDisplayFileModificationDateCache(java.lang.String absolutePath)
          Clears cache for "getDisplayFileModificationDate" method for specified file path.
static void clearDisplayFileNameCache()
          Clears cache for "getDisplayFileName" method.
static void clearDisplayFileNameCache(java.lang.String absolutePath)
          Clears cache for "getDisplayFileName" method for specified file path.
static void clearFileCaches(java.io.File file)
          Clears all caches for specified file.
static void clearFileCaches(java.lang.String path)
          Clears all caches for file under the specified path.
static void clearFileDescriptionCache()
          Clears cache for "getFileDescription" method.
static void clearFileDescriptionCache(java.lang.String absolutePath)
          Clears cache for "getFileDescription" method for specified file path.
static void clearFilesCaches(java.io.File... files)
          Clears all caches for specified files.
static void clearFileTypeDescriptionCache()
          Clears cache for "getFileTypeDescription" method.
static void clearFileTypeDescriptionCache(java.lang.String absolutePath)
          Clears cache for "getFileTypeDescription" method for specified file path.
static void clearIsCdDriveCache()
          Clears cache for "isCdDrive" method.
static void clearIsCdDriveCache(java.lang.String absolutePath)
          Clears cache for "isCdDrive" method for specified file path.
static void clearIsComputerCache()
          Clears cache for "isComputer" method.
static void clearIsComputerCache(java.lang.String absolutePath)
          Clears cache for "isComputer" method for specified file path.
static void clearIsDirectoryCache()
          Clears cache for "isDirectory" method.
static void clearIsDirectoryCache(java.lang.String absolutePath)
          Clears cache for "isDirectory" method for specified file path.
static void clearIsDriveCache()
          Clears cache for "isDrive" method.
static void clearIsDriveCache(java.lang.String absolutePath)
          Clears cache for "isDrive" method for specified file path.
static void clearIsFileCache()
          Clears cache for "isFile" method.
static void clearIsFileCache(java.lang.String absolutePath)
          Clears cache for "isFile" method for specified file path.
static void clearIsHiddenCache()
          Clears cache for "isHidden" method.
static void clearIsHiddenCache(java.lang.String absolutePath)
          Clears cache for "isHidden" method for specified file path.
static java.lang.String computeMD5(java.io.File file)
          Returns MD5 for specified file.
static java.lang.String computeMD5(java.io.File file, int bufferLength)
          Returns MD5 for specified file and using a buffer of specified length.
static java.lang.String computeMD5(java.io.InputStream is)
          Returns MD5 using the specified data stream.
static java.lang.String computeMD5(java.io.InputStream is, int bufferLength)
          Returns MD5 using the specified data stream and a buffer of specified length.
static boolean containtsFile(java.util.List files, java.io.File file)
          Returns whether list of files or file paths contains the specified file or not.
static boolean copyDirectory(java.io.File srcDir, java.io.File dstDir)
          Copies src directory content into dst directory and returns whether operation succeed or not.
static boolean copyDirectory(java.io.File srcDir, java.io.File dstDir, boolean stopOnFail)
          Copies src directory content into dst directory and returns whether operation succeed or not.
static boolean copyDirectory(java.lang.String src, java.lang.String dst)
          Copies src directory content into dst directory and returns whether operation succeed or not.
static boolean copyDirectory(java.lang.String src, java.lang.String dst, boolean stopOnFail)
          Copies src directory content into dst directory and returns whether operation succeed or not.
static boolean copyFile(java.nio.channels.FileChannel srcFC, java.nio.channels.FileChannel dstFC)
          Copies file data from source file channel into destination file channel.
static boolean copyFile(java.io.File srcFile, java.io.File dstFile)
          Copies source file content into destination file.
static boolean copyFile(java.lang.String src, java.lang.String dst)
          Copies source file content into destination file.
static FileDescription createFileDescription(java.io.File file, java.lang.String fileSize)
          Returns complete file description.
static void deleteFile(java.io.File file)
          Deletes file or directory completely.
static void deleteFiles(java.util.List files)
          Deletes all specified files.
static void deleteFiles(java.lang.Object... files)
          Deletes all specified files.
static void displayFileName(javax.swing.text.JTextComponent editor, java.io.File file)
          Sets file name as text and selects its name part in any text component.
static java.io.File downloadFile(java.lang.String url, java.io.File dstFile)
          Downloads file from the specified url to destination file and returns it if download succeed or null if not.
static java.io.File downloadFile(java.lang.String url, java.io.File dstFile, boolean encodeUrl, java.lang.String contentType, int timeout)
          Downloads file from the specified url to destination file and returns it if download succeed or null if not.
static java.io.File downloadFile(java.lang.String url, java.io.File dstFile, boolean encodeUrl, java.lang.String contentType, int timeout, FileDownloadListener listener)
          Downloads file from the specified url to destination file and returns it if download succeed or null if not.
static java.io.File downloadFile(java.lang.String url, java.io.File dstFile, FileDownloadListener listener)
          Downloads file from the specified url to destination file and returns it if download succeed or null if not.
static java.io.File downloadFile(java.lang.String url, java.lang.String dst, boolean encodeUrl, java.lang.String contentType, int timeout)
          Downloads file from the specified url to destination file and returns it if download succeed or null if not.
static java.io.File downloadFile(java.lang.String url, java.lang.String dst, boolean encodeUrl, java.lang.String contentType, int timeout, FileDownloadListener listener)
          Downloads file from the specified url to destination file and returns it if download succeed or null if not.
static boolean ensureDirectoryExists(java.io.File dir)
          Returns true if directory exists or was successfully created during this check, false otherwise.
static boolean ensureDirectoryExists(java.lang.String dir)
          Returns true if directory exists or was successfully created during this check, false otherwise.
static boolean equals(java.io.File file1, java.io.File file2)
          Returns whether both files represent the same path in file system or not.
static boolean equals(java.util.List<java.io.File> files1, java.util.List<java.io.File> files2)
          Returns whether both list of files have equal files in the same positions or not.
static java.util.List<java.io.File> filterFiles(java.util.Collection<java.io.File> files, AbstractFileFilter fileFilter)
          Returns filtered files list.
static java.util.List<java.io.File> findFilesRecursively(java.io.File dir, java.io.FileFilter filter)
          Returns list of files accepted by file filter found in the specified directory and its subdirectories.
static java.util.List<java.io.File> findFilesRecursively(java.io.File dir, java.io.FileFilter filter, java.util.List<java.io.File> found)
          Returns list of files accepted by file filter found in the specified directory and its subdirectories.
static java.util.List<java.io.File> findFilesRecursively(java.io.File dir, java.util.List<java.lang.String> extension)
          Returns list of files with specified extensions found in the specified directory and its subdirectories.
static java.util.List<java.io.File> findFilesRecursively(java.io.File dir, java.util.List<java.lang.String> extension, boolean withDot)
          Returns list of files with specified extensions found in the specified directory and its subdirectories.
static java.util.List<java.io.File> findFilesRecursively(java.io.File dir, java.util.List<java.lang.String> extension, boolean withDot, java.util.List<java.io.File> found)
          Returns list of files with specified extensions found in the specified directory and its subdirectories.
static java.util.List<java.io.File> findFilesRecursively(java.lang.String dir, java.io.FileFilter filter)
          Returns list of files accepted by file filter found in the specified directory and its subdirectories.
static java.util.List<java.io.File> findFilesRecursively(java.lang.String dir, java.io.FileFilter filter, java.util.List<java.io.File> found)
          Returns list of files accepted by file filter found in the specified directory and its subdirectories.
static java.util.List<java.io.File> findFilesRecursively(java.lang.String dir, java.util.List<java.lang.String> extension)
          Returns list of files with specified extensions found in the specified directory and its subdirectories.
static java.util.List<java.io.File> findFilesRecursively(java.lang.String dir, java.util.List<java.lang.String> extension, boolean withDot)
          Returns list of files with specified extensions found in the specified directory and its subdirectories.
static java.util.List<java.io.File> findFilesRecursively(java.lang.String dir, java.util.List<java.lang.String> extension, boolean withDot, java.util.List<java.io.File> found)
          Returns list of files with specified extensions found in the specified directory and its subdirectories.
static java.lang.String getAvailableName(java.io.File dir, java.lang.String name)
          Returns available file name in the specified directory and which is similar the specified name.
static java.lang.String getAvailableName(java.util.List<java.lang.String> exist, java.lang.String name)
          Returns available file name that is not contained in the existing names list.
static java.lang.String getAvailableName(java.lang.String dir, java.lang.String name)
          Returns available file name in the specified directory and which is similar the specified name.
static java.io.File[] getDiskRoots()
          Returns array of available system disks.
static java.lang.String getDisplayFileCreationDate(java.io.File file)
          Returns file modification date to display.
static java.lang.String getDisplayFileModificationDate(java.io.File file)
          Returns file modification date to display.
static java.lang.String getDisplayFileName(java.io.File file)
          Returns file name to display.
static java.lang.String getDisplayFileSize(java.io.File file)
          Returns file size to display.
static java.lang.String getDisplayFileSize(java.io.File file, int digits)
          Returns file size to display.
static FileDescription getFileDescription(java.io.File file, java.lang.String fileSize)
          Returns complete file description.
static java.lang.String getFileExtPart(java.lang.String file, boolean withDot)
          Returns file extension either with or without dot.
static javax.swing.ImageIcon getFileIcon(java.io.File file)
          Returns system file icon.
static javax.swing.ImageIcon getFileIcon(java.io.File file, boolean large)
          Returns either large or small system file icon.
static java.lang.String getFileNamePart(java.io.File file)
          Returns file name without extension.
static java.lang.String getFileNamePart(java.lang.String name)
          Returns file name without extension.
static java.util.List<java.io.File> getFilePath(java.io.File file)
          Returns list of files contained in path of the specified file.
static int getFileSize(java.lang.String url)
          Returns file size, located at the specified url.
static int getFileSize(java.net.URL url)
          Returns file size, located at the specified url.
static java.lang.String getFileSizeString(long size)
          Returns file size to display.
static java.lang.String getFileSizeString(long size, int digits)
          Returns file size to display.
static java.lang.String getFileTypeDescription(java.io.File file)
          Returns file type description.
static javax.swing.ImageIcon getIconResource(java.lang.Class nearClass, java.lang.String resource)
          Returns resource icon.
static javax.swing.ImageIcon getIconResource(java.lang.Class nearClass, java.lang.String resource, float transparency)
          Returns resource icon with the specified transparency.
static javax.swing.ImageIcon getMyComputerIcon()
          Returns default icon for "My computer" file.
static java.lang.String getProperFileName(java.lang.String name)
          Returns a valid for any file system file name based on specified name.
static java.lang.String getRelativePath(java.io.File file, java.io.File folder)
          Returns file path relative to specified folder or canonical path if file is not inside that folder.
static java.lang.String getShortFileName(java.lang.String name)
          Returns shortened file name.
static java.lang.String getShortFileName(java.lang.String name, int length)
          Returns shortened to the specified length file name.
static javax.swing.ImageIcon getStandartFileIcon(boolean large, java.lang.String extension, float transparency)
          Returns either large or small icon for the specified extension from a standard icons set.
static javax.swing.ImageIcon getStandartFileIcon(java.io.File file, boolean large)
          Returns either large or small file icon from a standard icons set.
static javax.swing.ImageIcon getStandartFileIcon(java.io.File file, boolean large, boolean enabled)
          Returns either large or small file icon from a standard icons set.
static java.util.List<java.lang.String> getSubpaths(java.io.File dir)
          Returns list of all file paths in this directory and all subdirectories.
static java.util.List<java.lang.String> getSubpaths(java.io.File dir, java.lang.String path)
          Returns list of all file paths in this directory and all subdirectories.
static java.util.List<java.lang.String> getSubpaths(java.io.File dir, java.lang.String path, java.util.List<java.lang.String> paths)
          Returns list of all file paths in this directory and all subdirectories.
static java.util.List<java.lang.String> getSubpaths(java.lang.String dir)
          Returns list of all file paths in this directory and all subdirectories.
static java.io.File getSystemRoot()
          Returns first available file system root.
static java.io.File[] getSystemRoots()
          Returns array of available file system roots.
static java.io.File getSystemTemp()
          Returns system directory for temporary files.
static java.lang.String getSystemTempPath()
          Returns path to system directory for temporary files.
static java.io.File getTopParent(java.io.File file)
          Returns top not-null parent for the specified file.
static java.io.File getUserHome()
          Returns user home directory.
static java.lang.String getUserHomePath()
          Returns path to user home directory.
static java.io.File getWorkingDirectory()
          Returns application working directory.
static java.lang.String getWorkingDirectoryPath()
          Returns application working directory.
static boolean grantExecutePermissions(java.io.File file)
          Grants file execution permission for all users for specified file.
static boolean isCdDrive(java.io.File file)
          Returns whether the specified file points to system CD/DVD/Bluray drive or not.
static boolean isComputer(java.io.File file)
          Returns whether the specified file points to system hard drive or not.
static boolean isDirectory(java.io.File file)
          Returns whether the specified file is directory or not.
static boolean isDrive(java.io.File file)
          Returns whether the specified file points to system hard drive or not.
static boolean isFile(java.io.File file)
          Returns whether the specified file is actually a file (and not a directory, disk or some system folder) or not.
static boolean isFileAccepted(java.io.File file, java.util.List<AbstractFileFilter> filters)
          Returns whether any of the specified file filters accept the file or not.
static boolean isHidden(java.io.File file)
          Returns whether the specified file is hidden or not.
static boolean isIllegalFileNameChar(char c)
          Returns whether the specified character is illegal or not.
static boolean isNameEditable(java.io.File file)
          Returns whether specified file's name can be edited.
static boolean isParent(java.io.File parent, java.io.File child)
          Returns whether the specified child file is one of parent file childs or not.
static java.io.File[] listFiles(java.io.File directory, java.io.FileFilter fileFilter)
          Returns directory files array or empty array (instead of null) if no files present.
static java.io.File normalize(java.io.File file)
          Returns normalized file without redundant parts in its path.
static java.lang.String readToString(java.lang.Class nearClass, java.lang.String resource)
          Returns text content read from the file located near specified class.
static java.lang.String readToString(java.io.File file)
          Returns text content read from the specified file.
static java.lang.String readToString(java.io.InputStream inputStream)
          Returns text content read from the input stream.
static java.lang.String readToString(java.io.Reader reader)
          Returns text content read from the specified reader.
static java.lang.String readToString(java.net.URL url)
          Returns text content read from the file at the specified url.
static java.io.File[] sortFiles(java.io.File[] files)
          Returns sorted array of files.
static java.util.List sortFiles(java.util.List<java.io.File> files)
          Returns sorted list of files.
static java.util.List<java.io.File> toFilesList(java.lang.Object... object)
          Converts objects array into list of files.
static AbstractFileFilter transformFileFilter(java.io.FileFilter fileFilter)
          Returns transformed file filter.
static AbstractFileFilter transformFileFilter(javax.swing.filechooser.FileFilter fileFilter)
          Returns transformed file filter.
static void writeStringToFile(java.lang.String text, java.io.File file)
          Writes text to the specified file overwriting any content inside the file.
static void writeStringToFile(java.lang.String text, java.io.File file, java.lang.String encoding)
          Writes text to the specified file overwriting any content inside the file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

KB

public static final long KB
Number of bytes in 1 kilobyte.

See Also:
Constant Field Values

MB

public static final long MB
Number of bytes in 1 megabyte.

See Also:
Constant Field Values

GB

public static final long GB
Number of bytes in 1 gigabyte.

See Also:
Constant Field Values

PB

public static final long PB
Number of bytes in 1 petabyte.

See Also:
Constant Field Values
Constructor Detail

FileUtils

public FileUtils()
Method Detail

clearFilesCaches

public static void clearFilesCaches(java.io.File... files)
Clears all caches for specified files.

Parameters:
files - files to process

clearFileCaches

public static void clearFileCaches(java.io.File file)
Clears all caches for specified file.

Parameters:
file - file to process

clearFileCaches

public static void clearFileCaches(java.lang.String path)
Clears all caches for file under the specified path.

Parameters:
path - file path

getFilePath

public static java.util.List<java.io.File> getFilePath(java.io.File file)
Returns list of files contained in path of the specified file.

For example if you have some file that points to some local file: "C:\folder\file.txt" You will get this list of files: "C:\", "C:\folder\", "C:\folder\file.txt"

Parameters:
file - file to process
Returns:
list of files contained in path of the specified file

getRelativePath

public static java.lang.String getRelativePath(java.io.File file,
                                               java.io.File folder)
Returns file path relative to specified folder or canonical path if file is not inside that folder.

Parameters:
file - file to get relative path to
folder - one of file's parent folders
Returns:
file path relative to specified folder or canonical path if file is not inside that folder

isNameEditable

public static boolean isNameEditable(java.io.File file)
Returns whether specified file's name can be edited.

Parameters:
file - file to edit
Returns:
true if specified file's name can be edited, false otherwise

displayFileName

public static void displayFileName(javax.swing.text.JTextComponent editor,
                                   java.io.File file)
Sets file name as text and selects its name part in any text component.

Parameters:
editor - text editor to process
file - file to process

getSystemTemp

public static java.io.File getSystemTemp()
Returns system directory for temporary files.

Returns:
system directory for temporary files

getSystemTempPath

public static java.lang.String getSystemTempPath()
Returns path to system directory for temporary files.

Returns:
path to system directory for temporary files

grantExecutePermissions

public static boolean grantExecutePermissions(java.io.File file)
Grants file execution permission for all users for specified file.

Parameters:
file - file for permissions change
Returns:
true if permissions change operation succeed, false otherwise

normalize

public static java.io.File normalize(java.io.File file)
Returns normalized file without redundant parts in its path.

Parameters:
file - file to normalize
Returns:
normalized file

getSystemRoot

public static java.io.File getSystemRoot()
Returns first available file system root.

Returns:
first available file system root

getSystemRoots

public static java.io.File[] getSystemRoots()
Returns array of available file system roots.

Returns:
array of available file system roots

getDiskRoots

public static java.io.File[] getDiskRoots()
Returns array of available system disks.

Returns:
array of available system disks

listFiles

public static java.io.File[] listFiles(java.io.File directory,
                                       java.io.FileFilter fileFilter)
Returns directory files array or empty array (instead of null) if no files present.

Parameters:
directory - directory to look into
fileFilter - file filter
Returns:
directory files array or empty array (instead of null) if no files present

computeMD5

public static java.lang.String computeMD5(java.io.File file)
Returns MD5 for specified file.

Parameters:
file - file to process
Returns:
MD5

computeMD5

public static java.lang.String computeMD5(java.io.File file,
                                          int bufferLength)
Returns MD5 for specified file and using a buffer of specified length.

Parameters:
file - file to process
bufferLength - buffer length
Returns:
MD5

computeMD5

public static java.lang.String computeMD5(java.io.InputStream is)
Returns MD5 using the specified data stream.

Parameters:
is - data stream to process
Returns:
MD5

computeMD5

public static java.lang.String computeMD5(java.io.InputStream is,
                                          int bufferLength)
Returns MD5 using the specified data stream and a buffer of specified length.

Parameters:
is - data stream to process
bufferLength - buffer length
Returns:
MD5

getWorkingDirectory

public static java.io.File getWorkingDirectory()
Returns application working directory.

Returns:
application working directory

getWorkingDirectoryPath

public static java.lang.String getWorkingDirectoryPath()
Returns application working directory.

Returns:
application working directory

getUserHome

public static java.io.File getUserHome()
Returns user home directory.

Returns:
user home directory

getUserHomePath

public static java.lang.String getUserHomePath()
Returns path to user home directory.

Returns:
path to user home directory

equals

public static boolean equals(java.io.File file1,
                             java.io.File file2)
Returns whether both files represent the same path in file system or not.

Parameters:
file1 - first file to be compared
file2 - second file to be compared
Returns:
true if both files represent the same path in file system, false otherwise

equals

public static boolean equals(java.util.List<java.io.File> files1,
                             java.util.List<java.io.File> files2)
Returns whether both list of files have equal files in the same positions or not.

Parameters:
files1 - first files list to be compared
files2 - second files list to be compared
Returns:
true if both list of files have equal files in the same positions, false otherwise

containtsFile

public static boolean containtsFile(java.util.List files,
                                    java.io.File file)
Returns whether list of files or file paths contains the specified file or not.

Parameters:
files - list of files to search in
file - file to look for
Returns:
true if list of files or file paths contains the specified file, false otherwise

isFileAccepted

public static boolean isFileAccepted(java.io.File file,
                                     java.util.List<AbstractFileFilter> filters)
Returns whether any of the specified file filters accept the file or not.

Parameters:
file - file to process
filters - file filters list
Returns:
true if any of the specified file filters accept the file, false otherwise

getProperFileName

public static java.lang.String getProperFileName(java.lang.String name)
Returns a valid for any file system file name based on specified name.

Parameters:
name - name to process
Returns:
file name valid for any file system

isIllegalFileNameChar

public static boolean isIllegalFileNameChar(char c)
Returns whether the specified character is illegal or not.

Parameters:
c - character to process
Returns:
true the specified character is illegal, false otherwise

canonicalPath

public static java.lang.String canonicalPath(java.io.File file)
Returns file canonical path if its possible or absolute path otherwise.

Parameters:
file - file to process
Returns:
file canonical path if its possible or absolute path otherwise

getTopParent

public static java.io.File getTopParent(java.io.File file)
Returns top not-null parent for the specified file. If file has no parents at all simply returns null.

Parameters:
file - file to process
Returns:
top not-null parent for the specified file or null if it has no parent files

isParent

public static boolean isParent(java.io.File parent,
                               java.io.File child)
Returns whether the specified child file is one of parent file childs or not.

Parameters:
parent - parent file
child - child file
Returns:
true if the specified child file is one of parent file childs, false otherwise

getFileNamePart

public static java.lang.String getFileNamePart(java.io.File file)
Returns file name without extension.

Parameters:
file - file to process
Returns:
file name without extension

getFileNamePart

public static java.lang.String getFileNamePart(java.lang.String name)
Returns file name without extension.

Parameters:
name - file name to trim
Returns:
file name without extension

getFileExtPart

public static java.lang.String getFileExtPart(java.lang.String file,
                                              boolean withDot)
Returns file extension either with or without dot.

Parameters:
file - file to process
withDot - whether return the extension with dot, or not
Returns:
file extension

getShortFileName

public static java.lang.String getShortFileName(java.lang.String name)
Returns shortened file name.

Parameters:
name - file name to shorten
Returns:
shortened file name

getShortFileName

public static java.lang.String getShortFileName(java.lang.String name,
                                                int length)
Returns shortened to the specified length file name. Note that file extension length is not counted.

Parameters:
name - file name to shorten
length - maximum allowed file name length
Returns:
shortened file name

sortFiles

public static java.util.List sortFiles(java.util.List<java.io.File> files)
Returns sorted list of files.

Parameters:
files - list of files to sort
Returns:
sorted list of files

sortFiles

public static java.io.File[] sortFiles(java.io.File[] files)
Returns sorted array of files.

Parameters:
files - array of files to sort
Returns:
sorted array of files

getAvailableName

public static java.lang.String getAvailableName(java.lang.String dir,
                                                java.lang.String name)
Returns available file name in the specified directory and which is similar the specified name.

Parameters:
dir - directory path to check
name - file name to check
Returns:
available file name

getAvailableName

public static java.lang.String getAvailableName(java.io.File dir,
                                                java.lang.String name)
Returns available file name in the specified directory and which is similar the specified name.

Parameters:
dir - directory to check
name - file name to check
Returns:
available file name

getAvailableName

public static java.lang.String getAvailableName(java.util.List<java.lang.String> exist,
                                                java.lang.String name)
Returns available file name that is not contained in the existing names list.

Parameters:
exist - list of existing file names
name - file name to check
Returns:
available file name

toFilesList

public static java.util.List<java.io.File> toFilesList(java.lang.Object... object)
Converts objects array into list of files. Non-file type objects will be simply ignored.

Parameters:
object - file object
Returns:
list of files

deleteFiles

public static void deleteFiles(java.lang.Object... files)
Deletes all specified files.

Parameters:
files - files to delete

deleteFiles

public static void deleteFiles(java.util.List files)
Deletes all specified files.

Parameters:
files - files to delete

deleteFile

public static void deleteFile(java.io.File file)
Deletes file or directory completely. All child files and directories will be removed first in case directory is deleted.

Parameters:
file - file to delete

clearDirectory

public static void clearDirectory(java.io.File dir)
Deletes all child files and directories for specified directory. Directory itself will not be deleted.

Parameters:
dir - directory to clear

transformFileFilter

public static AbstractFileFilter transformFileFilter(java.io.FileFilter fileFilter)
Returns transformed file filter.

Parameters:
fileFilter - IO file filter
Returns:
transformed file filter

transformFileFilter

public static AbstractFileFilter transformFileFilter(javax.swing.filechooser.FileFilter fileFilter)
Returns transformed file filter.

Parameters:
fileFilter - Swing file filter
Returns:
transformed file filter.

filterFiles

public static java.util.List<java.io.File> filterFiles(java.util.Collection<java.io.File> files,
                                                       AbstractFileFilter fileFilter)
Returns filtered files list.

Parameters:
files - files collection to filter
fileFilter - file filter
Returns:
filtered files list

createFileDescription

public static FileDescription createFileDescription(java.io.File file,
                                                    java.lang.String fileSize)
Returns complete file description.

Parameters:
file - file to process
fileSize - file size
Returns:
complete file description

getDisplayFileSize

public static java.lang.String getDisplayFileSize(java.io.File file)
Returns file size to display.

Parameters:
file - file to process
Returns:
file size to display

getDisplayFileSize

public static java.lang.String getDisplayFileSize(java.io.File file,
                                                  int digits)
Returns file size to display.

Parameters:
file - file to process
digits - number of digits after the dot
Returns:
file size to display

getFileSizeString

public static java.lang.String getFileSizeString(long size)
Returns file size to display.

Parameters:
size - size of the file
Returns:
file size to display

getFileSizeString

public static java.lang.String getFileSizeString(long size,
                                                 int digits)
Returns file size to display.

Parameters:
size - size of the file
digits - number of digits after the dot
Returns:
file size to display

copyDirectory

public static boolean copyDirectory(java.lang.String src,
                                    java.lang.String dst)
Copies src directory content into dst directory and returns whether operation succeed or not. Also ignores any exceptions that might occur during the copy process.

Parameters:
src - source directory path
dst - destination directory path
Returns:
true if copy operation succeed, false otherwise

copyDirectory

public static boolean copyDirectory(java.lang.String src,
                                    java.lang.String dst,
                                    boolean stopOnFail)
Copies src directory content into dst directory and returns whether operation succeed or not. Whether to stop copy operation if any exception occurs or not is set by stopOnFail argument.

Parameters:
src - source directory path
dst - destination directory path
stopOnFail - whether to stop copy operation if any exception occurs or not
Returns:
true if copy operation succeed, false otherwise

copyDirectory

public static boolean copyDirectory(java.io.File srcDir,
                                    java.io.File dstDir)
Copies src directory content into dst directory and returns whether operation succeed or not. Also ignores any exceptions that might occur during the copy process.

Parameters:
srcDir - source directory
dstDir - destination directory
Returns:
true if copy operation succeed, false otherwise

copyDirectory

public static boolean copyDirectory(java.io.File srcDir,
                                    java.io.File dstDir,
                                    boolean stopOnFail)
Copies src directory content into dst directory and returns whether operation succeed or not. Whether to stop copy operation if any exception occurs or not is set by stopOnFail argument.

Parameters:
srcDir - source directory
dstDir - destination directory
stopOnFail - whether to stop copy operation if any exception occurs or not
Returns:
true if copy operation succeed, false otherwise

copyFile

public static boolean copyFile(java.lang.String src,
                               java.lang.String dst)
Copies source file content into destination file. If destination directory doesn't exist it will be created in the process. If destination file doesn't exist it will be also created in the process.

Parameters:
src - source file path
dst - destination file path
Returns:
true if copy operation succeed, false otherwise

copyFile

public static boolean copyFile(java.io.File srcFile,
                               java.io.File dstFile)
Copies source file content into destination file. If destination directory doesn't exist it will be created in the process. If destination file doesn't exist it will be also created in the process.

Parameters:
srcFile - source file
dstFile - destination file
Returns:
true if copy operation succeed, false otherwise

copyFile

public static boolean copyFile(java.nio.channels.FileChannel srcFC,
                               java.nio.channels.FileChannel dstFC)
Copies file data from source file channel into destination file channel.

Parameters:
srcFC - source file channel
dstFC - destination file channel
Returns:
true if copy operation succeed, false otherwise

readToString

public static java.lang.String readToString(java.lang.Class nearClass,
                                            java.lang.String resource)
Returns text content read from the file located near specified class.

Parameters:
nearClass - class near which text file is located
resource - text file location
Returns:
text file content

readToString

public static java.lang.String readToString(java.net.URL url)
Returns text content read from the file at the specified url.

Parameters:
url - text file url
Returns:
text file content

readToString

public static java.lang.String readToString(java.io.InputStream inputStream)
Returns text content read from the input stream.

Parameters:
inputStream - text content input stream
Returns:
text content

readToString

public static java.lang.String readToString(java.io.File file)
Returns text content read from the specified file.

Parameters:
file - file to read
Returns:
text file content

readToString

public static java.lang.String readToString(java.io.Reader reader)
Returns text content read from the specified reader.

Parameters:
reader - text content reader
Returns:
text content

writeStringToFile

public static void writeStringToFile(java.lang.String text,
                                     java.io.File file)
Writes text to the specified file overwriting any content inside the file. If file or even its directory doesn't exist - they will be created.

Parameters:
text - text to write
file - file to write text into

writeStringToFile

public static void writeStringToFile(java.lang.String text,
                                     java.io.File file,
                                     java.lang.String encoding)
Writes text to the specified file overwriting any content inside the file. If file or even its directory doesn't exist - they will be created.

Parameters:
text - text to write
file - file to write text into

getSubpaths

public static java.util.List<java.lang.String> getSubpaths(java.lang.String dir)
Returns list of all file paths in this directory and all subdirectories.

Parameters:
dir - path of directory to process
Returns:
list of file paths

getSubpaths

public static java.util.List<java.lang.String> getSubpaths(java.io.File dir)
Returns list of all file paths in this directory and all subdirectories.

Parameters:
dir - directory to process
Returns:
list of file paths

getSubpaths

public static java.util.List<java.lang.String> getSubpaths(java.io.File dir,
                                                           java.lang.String path)
Returns list of all file paths in this directory and all subdirectories.

Parameters:
dir - directory to process
path - path to current position
Returns:
list of file paths

getSubpaths

public static java.util.List<java.lang.String> getSubpaths(java.io.File dir,
                                                           java.lang.String path,
                                                           java.util.List<java.lang.String> paths)
Returns list of all file paths in this directory and all subdirectories.

Parameters:
dir - directory to process
path - path to current position
paths - list of collected paths
Returns:
list of file paths

downloadFile

public static java.io.File downloadFile(java.lang.String url,
                                        java.io.File dstFile)
Downloads file from the specified url to destination file and returns it if download succeed or null if not.

Parameters:
url - file source url
dstFile - destination file
Returns:
downloaded file if download succeed, null otherwise

downloadFile

public static java.io.File downloadFile(java.lang.String url,
                                        java.io.File dstFile,
                                        FileDownloadListener listener)
Downloads file from the specified url to destination file and returns it if download succeed or null if not. You can observe and manipulate the download process by providing a file download listener.

Parameters:
url - file source url
dstFile - destination file
listener - file download process listener
Returns:
downloaded file if download succeed, null otherwise

downloadFile

public static java.io.File downloadFile(java.lang.String url,
                                        java.lang.String dst,
                                        boolean encodeUrl,
                                        java.lang.String contentType,
                                        int timeout)
Downloads file from the specified url to destination file and returns it if download succeed or null if not.

Parameters:
url - file source url
dst - destination file path
encodeUrl - whether encode the source url or not
contentType - content type limitation
timeout - connection and read timeout
Returns:
downloaded file if download succeed, null otherwise

downloadFile

public static java.io.File downloadFile(java.lang.String url,
                                        java.lang.String dst,
                                        boolean encodeUrl,
                                        java.lang.String contentType,
                                        int timeout,
                                        FileDownloadListener listener)
Downloads file from the specified url to destination file and returns it if download succeed or null if not. You can observe and manipulate the download process by providing a file download listener.

Parameters:
url - file source url
dst - destination file path
encodeUrl - whether encode the source url or not
contentType - content type limitation
timeout - connection and read timeout
listener - file download process listener
Returns:
downloaded file if download succeed, null otherwise

downloadFile

public static java.io.File downloadFile(java.lang.String url,
                                        java.io.File dstFile,
                                        boolean encodeUrl,
                                        java.lang.String contentType,
                                        int timeout)
Downloads file from the specified url to destination file and returns it if download succeed or null if not.

Parameters:
url - file source url
dstFile - destination file
encodeUrl - whether encode the source url or not
contentType - content type limitation
timeout - connection and read timeout
Returns:
downloaded file if download succeed, null otherwise

downloadFile

public static java.io.File downloadFile(java.lang.String url,
                                        java.io.File dstFile,
                                        boolean encodeUrl,
                                        java.lang.String contentType,
                                        int timeout,
                                        FileDownloadListener listener)
Downloads file from the specified url to destination file and returns it if download succeed or null if not. You can observe and manipulate the download process by providing a file download listener.

Parameters:
url - file source url
dstFile - destination file
encodeUrl - whether encode the source url or not
contentType - content type limitation
timeout - connection and read timeout
listener - file download process listener
Returns:
downloaded file if download succeed, null otherwise

getFileSize

public static int getFileSize(java.lang.String url)
Returns file size, located at the specified url.

Parameters:
url - file location url
Returns:
file size

getFileSize

public static int getFileSize(java.net.URL url)
Returns file size, located at the specified url.

Parameters:
url - file location url
Returns:
file size

findFilesRecursively

public static java.util.List<java.io.File> findFilesRecursively(java.lang.String dir,
                                                                java.util.List<java.lang.String> extension)
Returns list of files with specified extensions found in the specified directory and its subdirectories.

Parameters:
dir - path to directory to process
extension - file extensions list
Returns:
list of found files

findFilesRecursively

public static java.util.List<java.io.File> findFilesRecursively(java.io.File dir,
                                                                java.util.List<java.lang.String> extension)
Returns list of files with specified extensions found in the specified directory and its subdirectories.

Parameters:
dir - directory to process
extension - file extensions list
Returns:
list of found files

findFilesRecursively

public static java.util.List<java.io.File> findFilesRecursively(java.lang.String dir,
                                                                java.util.List<java.lang.String> extension,
                                                                boolean withDot)
Returns list of files with specified extensions found in the specified directory and its subdirectories.

Parameters:
dir - path to directory to process
extension - file extensions list
withDot - whether extensions contain dot or not
Returns:
list of found files

findFilesRecursively

public static java.util.List<java.io.File> findFilesRecursively(java.io.File dir,
                                                                java.util.List<java.lang.String> extension,
                                                                boolean withDot)
Returns list of files with specified extensions found in the specified directory and its subdirectories.

Parameters:
dir - directory to process
extension - file extensions list
withDot - whether extensions contain dot or not
Returns:
list of found files

findFilesRecursively

public static java.util.List<java.io.File> findFilesRecursively(java.lang.String dir,
                                                                java.util.List<java.lang.String> extension,
                                                                boolean withDot,
                                                                java.util.List<java.io.File> found)
Returns list of files with specified extensions found in the specified directory and its subdirectories.

Parameters:
dir - path to directory to process
extension - file extensions list
withDot - whether extensions contain dot or not
found - list in which found files should be stored
Returns:
list of found files

findFilesRecursively

public static java.util.List<java.io.File> findFilesRecursively(java.io.File dir,
                                                                java.util.List<java.lang.String> extension,
                                                                boolean withDot,
                                                                java.util.List<java.io.File> found)
Returns list of files with specified extensions found in the specified directory and its subdirectories.

Parameters:
dir - directory to process
extension - file extensions list
withDot - whether extensions contain dot or not
found - list in which found files should be stored
Returns:
list of found files

findFilesRecursively

public static java.util.List<java.io.File> findFilesRecursively(java.lang.String dir,
                                                                java.io.FileFilter filter)
Returns list of files accepted by file filter found in the specified directory and its subdirectories.

Parameters:
dir - path to directory to process
filter - file filter
Returns:
list of found files

findFilesRecursively

public static java.util.List<java.io.File> findFilesRecursively(java.io.File dir,
                                                                java.io.FileFilter filter)
Returns list of files accepted by file filter found in the specified directory and its subdirectories.

Parameters:
dir - directory to process
filter - file filter
Returns:
list of found files

findFilesRecursively

public static java.util.List<java.io.File> findFilesRecursively(java.lang.String dir,
                                                                java.io.FileFilter filter,
                                                                java.util.List<java.io.File> found)
Returns list of files accepted by file filter found in the specified directory and its subdirectories.

Parameters:
dir - path to directory to process
filter - file filter
found - list in which found files should be stored
Returns:
list of found files

findFilesRecursively

public static java.util.List<java.io.File> findFilesRecursively(java.io.File dir,
                                                                java.io.FileFilter filter,
                                                                java.util.List<java.io.File> found)
Returns list of files accepted by file filter found in the specified directory and its subdirectories.

Parameters:
dir - directory to process
filter - file filter
found - list in which found files should be stored
Returns:
list of found files

ensureDirectoryExists

public static boolean ensureDirectoryExists(java.lang.String dir)
Returns true if directory exists or was successfully created during this check, false otherwise.

Parameters:
dir - path to directory to check
Returns:
true if directory exists or was successfully created during this check, false otherwise

ensureDirectoryExists

public static boolean ensureDirectoryExists(java.io.File dir)
Returns true if directory exists or was successfully created during this check, false otherwise.

Parameters:
dir - directory to check
Returns:
true if directory exists or was successfully created during this check, false otherwise

clearIsDriveCache

public static void clearIsDriveCache()
Clears cache for "isDrive" method.


clearIsDriveCache

public static void clearIsDriveCache(java.lang.String absolutePath)
Clears cache for "isDrive" method for specified file path.


isDrive

public static boolean isDrive(java.io.File file)
Returns whether the specified file points to system hard drive or not.

Parameters:
file - file to process
Returns:
true if the specified file points to system hard drive, false otherwise

clearIsComputerCache

public static void clearIsComputerCache()
Clears cache for "isComputer" method.


clearIsComputerCache

public static void clearIsComputerCache(java.lang.String absolutePath)
Clears cache for "isComputer" method for specified file path.


isComputer

public static boolean isComputer(java.io.File file)
Returns whether the specified file points to system hard drive or not.

Parameters:
file - file to process
Returns:
true if the specified file points to system hard drive, false otherwise

clearIsCdDriveCache

public static void clearIsCdDriveCache()
Clears cache for "isCdDrive" method.


clearIsCdDriveCache

public static void clearIsCdDriveCache(java.lang.String absolutePath)
Clears cache for "isCdDrive" method for specified file path.


isCdDrive

public static boolean isCdDrive(java.io.File file)
Returns whether the specified file points to system CD/DVD/Bluray drive or not. This method bases on file type description and might not work on some systems which does not provide it. This method caches its result to improve its performance when used in various renderers.

Parameters:
file - file to process
Returns:
true if the specified file points to system CD, DVD or Bluray drive, false otherwise

clearIsFileCache

public static void clearIsFileCache()
Clears cache for "isFile" method.


clearIsFileCache

public static void clearIsFileCache(java.lang.String absolutePath)
Clears cache for "isFile" method for specified file path.


isFile

public static boolean isFile(java.io.File file)
Returns whether the specified file is actually a file (and not a directory, disk or some system folder) or not.

Parameters:
file - file to process
Returns:
true if the specified file is actually a file, false otherwise

clearIsDirectoryCache

public static void clearIsDirectoryCache()
Clears cache for "isDirectory" method.


clearIsDirectoryCache

public static void clearIsDirectoryCache(java.lang.String absolutePath)
Clears cache for "isDirectory" method for specified file path.


isDirectory

public static boolean isDirectory(java.io.File file)
Returns whether the specified file is directory or not.

Parameters:
file - file to process
Returns:
true if the specified file is directory, false otherwise

clearIsHiddenCache

public static void clearIsHiddenCache()
Clears cache for "isHidden" method.


clearIsHiddenCache

public static void clearIsHiddenCache(java.lang.String absolutePath)
Clears cache for "isHidden" method for specified file path.


isHidden

public static boolean isHidden(java.io.File file)
Returns whether the specified file is hidden or not.

Parameters:
file - file to process
Returns:
true if the specified file is hidden, false otherwise

clearFileDescriptionCache

public static void clearFileDescriptionCache()
Clears cache for "getFileDescription" method.


clearFileDescriptionCache

public static void clearFileDescriptionCache(java.lang.String absolutePath)
Clears cache for "getFileDescription" method for specified file path.


getFileDescription

public static FileDescription getFileDescription(java.io.File file,
                                                 java.lang.String fileSize)
Returns complete file description.

Parameters:
file - file to process
fileSize - file size on disk
Returns:
complete file description

clearDisplayFileNameCache

public static void clearDisplayFileNameCache()
Clears cache for "getDisplayFileName" method.


clearDisplayFileNameCache

public static void clearDisplayFileNameCache(java.lang.String absolutePath)
Clears cache for "getDisplayFileName" method for specified file path.


getDisplayFileName

public static java.lang.String getDisplayFileName(java.io.File file)
Returns file name to display.

Parameters:
file - file to process
Returns:
file name to display

clearDisplayFileCreationDateCache

public static void clearDisplayFileCreationDateCache()
Clears cache for "getDisplayFileCreationDate" method.


clearDisplayFileCreationDateCache

public static void clearDisplayFileCreationDateCache(java.lang.String absolutePath)
Clears cache for "getDisplayFileCreationDate" method for specified file path.


getDisplayFileCreationDate

public static java.lang.String getDisplayFileCreationDate(java.io.File file)
Returns file modification date to display.

Parameters:
file - file to process
Returns:
file modification date to display

clearDisplayFileModificationDateCache

public static void clearDisplayFileModificationDateCache()
Clears cache for "getDisplayFileModificationDate" method.


clearDisplayFileModificationDateCache

public static void clearDisplayFileModificationDateCache(java.lang.String absolutePath)
Clears cache for "getDisplayFileModificationDate" method for specified file path.


getDisplayFileModificationDate

public static java.lang.String getDisplayFileModificationDate(java.io.File file)
Returns file modification date to display.

Parameters:
file - file to process
Returns:
file modification date to display

clearFileTypeDescriptionCache

public static void clearFileTypeDescriptionCache()
Clears cache for "getFileTypeDescription" method.


clearFileTypeDescriptionCache

public static void clearFileTypeDescriptionCache(java.lang.String absolutePath)
Clears cache for "getFileTypeDescription" method for specified file path.


getFileTypeDescription

public static java.lang.String getFileTypeDescription(java.io.File file)
Returns file type description.

Parameters:
file - file to process
Returns:
file type description

getMyComputerIcon

public static javax.swing.ImageIcon getMyComputerIcon()
Returns default icon for "My computer" file.

Returns:
default icon for "My computer" file

getFileIcon

public static javax.swing.ImageIcon getFileIcon(java.io.File file)
Returns system file icon.

Parameters:
file - file to process
Returns:
system file icon

getFileIcon

public static javax.swing.ImageIcon getFileIcon(java.io.File file,
                                                boolean large)
Returns either large or small system file icon.

Parameters:
file - file to process
large - whether return large icon or not
Returns:
either large or small system file icon

getStandartFileIcon

public static javax.swing.ImageIcon getStandartFileIcon(java.io.File file,
                                                        boolean large)
Returns either large or small file icon from a standard icons set.

Parameters:
file - file to process
large - whether return large icon or not
Returns:
either large or small file icon

getStandartFileIcon

public static javax.swing.ImageIcon getStandartFileIcon(java.io.File file,
                                                        boolean large,
                                                        boolean enabled)
Returns either large or small file icon from a standard icons set.

Parameters:
file - file to process
large - whether return large icon or not
Returns:
either large or small file icon

getStandartFileIcon

public static javax.swing.ImageIcon getStandartFileIcon(boolean large,
                                                        java.lang.String extension,
                                                        float transparency)
Returns either large or small icon for the specified extension from a standard icons set.

Parameters:
large - whether return large icon or not
extension - file extension
transparency - icon transparency
Returns:
either large or small icon for the specified extension

getIconResource

public static javax.swing.ImageIcon getIconResource(java.lang.Class nearClass,
                                                    java.lang.String resource)
Returns resource icon. Note that returned icon will be cached using its placement.

Parameters:
nearClass - class near which the icon is located
resource - icon location
Returns:
resource icon

getIconResource

public static javax.swing.ImageIcon getIconResource(java.lang.Class nearClass,
                                                    java.lang.String resource,
                                                    float transparency)
Returns resource icon with the specified transparency. Note that returned icon will be cached using its placement and transparency value.

Parameters:
nearClass - class near which the icon is located
resource - icon location
transparency - custom icon transparency
Returns:
resource icon