|
RbUtils 0.13 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.ktc.rbutils.api.file.FileTools
public class FileTools
General file manipulation utilities.
| Field Summary | |
|---|---|
static String |
DOS_SEPARATOR
The Dos file separator String. |
static char |
DOS_SEPARATOR_CHAR
The Dos file separator character. |
static String |
EXTENSION_SEPARATOR
The extension separator String. |
static char |
EXTENSION_SEPARATOR_CHAR
The extension separator character. |
static String |
JAVA_EXTENSION
The file extension of a java file. |
static String |
PACKAGE_SEPARATOR
The package separator String. |
static char |
PACKAGE_SEPARATOR_CHAR
The package separator character. |
static String |
UNIX_SEPARATOR
The Unix file separator String. |
static char |
UNIX_SEPARATOR_CHAR
The Unix file separator character. |
| Constructor Summary | |
|---|---|
protected |
FileTools()
Dummy constructor. |
| Method Summary | |
|---|---|
static int |
countFiles(File directory,
String[] extensions,
boolean recursive)
Returns the number of files found in a directory. |
static boolean |
equalNormalized(File file1,
File file2)
Checks whether two File are equal after both have been normalized and using
the case rules of the system. |
static void |
forceNewFile(File file)
Cleans and creates a new file in the file system. |
static Locale |
getLocaleFrom(File file)
Returns the locale of the file according to its filename. |
static String |
getNameWithoutExtension(File file)
Returns the filename of a File without extension. |
static File |
getNewInstance(File file)
Get a new instance of a File. |
static String |
getStrippedFileName(File root,
File file)
Create a stripped down version of a filename. |
static String |
getStrippedFileName(File root,
File file,
boolean forceUnixSeparator)
Create a stripped down version of a filename. |
static String |
inferPackageClassName(File root,
File file,
boolean removedLocale)
Returns the package (if file is a directory) or class (if file
is a file in the filesystem) name of a File according to its relative path
from a root directory. |
static String |
inferPackageClassName(File root,
File file,
boolean removedLocale,
boolean onlySubPkg)
Returns the package (if file is a directory) or class (if file
is a file in the filesystem) name of a File according to its relative path
from a root directory. |
static String |
inferPackageName(File root,
File file)
Returns the package (if file is a directory) or class (if file
is a file in the filesystem) name of a File according to its relative path
from a root directory. |
static boolean |
isRootParentOfFile(File root,
File file)
Determines if file is in the root directory. |
static String |
normalizeNoEndSeparator(File file)
Normalizes the absolute path of a File with the
{org.apache.commons.io.FilenameUtils#normalizeNoEndSeparator(java.lang.String)
normalizeNoEndSeparator()} method. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String JAVA_EXTENSION
public static final char EXTENSION_SEPARATOR_CHAR
public static final String EXTENSION_SEPARATOR
public static final char PACKAGE_SEPARATOR_CHAR
public static final String PACKAGE_SEPARATOR
public static final char UNIX_SEPARATOR_CHAR
public static final String UNIX_SEPARATOR
public static final char DOS_SEPARATOR_CHAR
public static final String DOS_SEPARATOR
| Constructor Detail |
|---|
protected FileTools()
UnsupportedOperationException - if this class is instanciated| Method Detail |
|---|
public static String inferPackageClassName(File root,
File file,
boolean removedLocale,
boolean onlySubPkg)
throws FileNotFoundException
file is a directory) or class (if file
is a file in the filesystem) name of a File according to its relative path
from a root directory.
The name of this package uses the Java language dot notation for the package. i.e
java.lang.
It can be the sub-package name (the name of the package which contains this class/package or
a full class/package name (name of the sub-package and the name of this class/package).
If root and file denote the same directory, , the returned
value is the package separator.
If file is in the root directory and onlySubPkg
is true, the empty string is returned.
root - the root directory used to resolved package or class names against
filefile - the file used to resolve its package/class nameremovedLocale - if true, the locale is removed from the class name;
otherwise, the locale is kept (only used if file is a file in the
filesytem or onlySubPkg is false)onlySubPkg - if true, returns only the sub-package name ; otherwise,
returns the full class/package name
NullArgumentException - if root or
file is null
FileNotFoundException - if root does not exist
NotDirectoryException - if root is not a directory
public static String inferPackageClassName(File root,
File file,
boolean removedLocale)
throws FileNotFoundException
file is a directory) or class (if file
is a file in the filesystem) name of a File according to its relative path
from a root directory.
The name of this package uses the Java language dot notation for the package. i.e
java.lang.
The returned value is the full class/package name (name of the sub-package and the name of
this class/package).
root - the root directory used to resolve package or class names against
filefile - the file used to resolved its package/class nameremovedLocale - if true, the locale is removed from the class name;
otherwise, the locale is kept
NullArgumentException - if root or
file is null
FileNotFoundException - if root does not exist
NotDirectoryException - if root is not a directory
public static String inferPackageName(File root,
File file)
throws FileNotFoundException
file is a directory) or class (if file
is a file in the filesystem) name of a File according to its relative path
from a root directory.
The name of this package uses the Java language dot notation for the package. i.e
java.lang.
The returned value is the sub-package name (the name of the package which contains this
class/package.
If file is the root directory , the returned value is the
package separator.
If file is in the root directory , the returned value is the
empty string.
root - the root directory used to resolve package or class names against
filefile - the file used to resolved its package/class name
NullArgumentException - if root or
file is null
FileNotFoundException - if root does not exist
NotDirectoryException - if root is not a directorypublic static String getNameWithoutExtension(File file)
File without extension.
file - the File from which the name without extension is desired
NullArgumentException - if file is
null
public static String getStrippedFileName(File root,
File file)
throws FileNotFoundException
root - the root directory used to resolve the stripped file name against
filefile - the file used to resolve its stripped file name
NullArgumentException - if root or
file is null
FileNotFoundException - if root does not exist
NotDirectoryException - if root is not a directory
public static String getStrippedFileName(File root,
File file,
boolean forceUnixSeparator)
throws FileNotFoundException
If file is in root, returns an empty String.
root - the root directory used to resolved the stripped file name against
filefile - the file used to resolve its stripped file nameforceUnixSeparator - if true, the returned value uses the
UNIX_SEPARATOR_CHAR as file separator; otherwise, it uses the
system file separator
NullArgumentException - if root or
file is null
FileNotFoundException - if root does not exist
NotDirectoryException - if root is not a directory
NotRootParentOfFileException - if file is not in root
public static boolean isRootParentOfFile(File root,
File file)
throws FileNotFoundException
file is in the root directory.
root - the directoryfile - the file (as file in the file system)
true if file is in the root directory;
otherwise false
NullArgumentException - if root or
file is null
FileNotFoundException - if root does not exist
NotDirectoryException - if root is not a directory
public static Locale getLocaleFrom(File file)
throws FileNotFoundException
file according to its filename. Note: this
method will work as expected if and only if the filename of the File does not
contain the underscore character '_' (except for the locale part).
file - file from which the locale is desired
NullArgumentException - if file is
null
FileNotFoundException - if file does not exist
NotFileException - if file is not a file in the
file systempublic static File getNewInstance(File file)
File.
file - a file from which a new instance is desired
NullArgumentException - if file is
null
public static boolean equalNormalized(File file1,
File file2)
File are equal after both have been normalized and using
the case rules of the system.
Both filenames are first passed to normalizeNoEndSeparator(File). The check is then
performed case-sensitive on Unix and case-insensitive on Windows.
file1 - the first file to queryfile2 - the second file to query
true if the two File are equals; false
otherwise
NullArgumentException - if file1 or
file2 is nullpublic static String normalizeNoEndSeparator(File file)
File with the
{org.apache.commons.io.FilenameUtils#normalizeNoEndSeparator(java.lang.String)
normalizeNoEndSeparator()} method.
file - the file to be normalized.
NullArgumentException - if file is
nullFilenameUtils.normalizeNoEndSeparator(java.lang.String)
public static int countFiles(File directory,
String[] extensions,
boolean recursive)
throws FileNotFoundException
directory - the directory to search in.extensions - an array of extensions, ex. {"java","xml"}. If this parameter is null, all
files are accepted.recursive - If true all subdirectories are searched, too.
NullArgumentException - if directory is
null
FileNotFoundException - if directory does not exist
NotDirectoryException - if directory is not a directory
public static void forceNewFile(File file)
throws IOException
The previous file is deleted if it exists. All parent directories of the file are first created. Finally, a new file is created.
file - the file to be created.
IOException - if an error occurs on file deletion, on file creation, or on parent
directories creation.
|
Back to the RbUtils Home Page | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||