|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.shell.support.util.FileUtils
public final class FileUtils
Utilities for handling File
instances.
Field Summary | |
---|---|
static String |
CURRENT_DIRECTORY
The relative file path to the current directory. |
Method Summary | |
---|---|
static String |
backOneDirectory(String fileIdentifier)
Returns the given file system path minus its last element |
static boolean |
copyRecursively(File source,
File destination,
boolean deleteDestinationOnExit)
Copies the specified source directory to the destination. |
static boolean |
deleteRecursively(File file)
Deletes the specified File . |
static boolean |
denotesAbsolutePath(String fileName)
Checks if the provided fileName denotes an absolute path on the file system. |
static String |
ensureTrailingSeparator(String path)
Ensures that the given path has exactly one trailing File.separator |
static String |
getCanonicalPath(File file)
Returns the canonical path of the given File . |
static File |
getFile(Class<?> loadingClass,
String filename)
Loads the given file from the classpath. |
static String |
getFileSeparatorAsRegex()
Returns the platform-specific file separator as a regular expression. |
static String |
getFirstDirectory(String fileIdentifier)
Returns the part of the given path that represents a directory, in other words the given path if it's already a directory, or the parent directory if it's a file. |
static InputStream |
getInputStream(Class<?> loadingClass,
String filename)
Loads the given file from the classpath. |
static String |
getPath(Class<?> loadingClass,
String relativeFilename)
Determines the path to the requested file, relative to the given class. |
static String |
getSystemDependentPath(Collection<String> pathElements)
Returns an operating-system-dependent path consisting of the given elements, separated by File.separator . |
static String |
getSystemDependentPath(String... pathElements)
Returns an operating-system-dependent path consisting of the given elements, separated by File.separator . |
static boolean |
matchesAntPath(String antPattern,
String canonicalPath)
Indicates whether the given canonical path matches the given Ant-style pattern |
static String |
read(File file)
Returns the contents of the given File as a String. |
static String |
readBanner(Class<?> loadingClass,
String resourceName)
Reads a banner from the given resource. |
static String |
readBanner(Reader reader)
Reads a banner from the given resource. |
static String |
removeLeadingAndTrailingSeparators(String path)
Removes any leading or trailing File.separator s from the given path. |
static String |
removeTrailingSeparator(String path)
Removes any trailing File.separator s from the given path |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String CURRENT_DIRECTORY
Method Detail |
---|
public static boolean deleteRecursively(File file)
File
.
If the File
refers to a directory, any contents of that directory (including other directories)
are also deleted.
If the File
does not already exist, this method immediately returns true.
file
- to delete (required; the file may or may not exist)
public static boolean copyRecursively(File source, File destination, boolean deleteDestinationOnExit)
Both the source must exist. If the destination does not already exist, it will be created. If the destination does exist, it must be a directory (not a file).
source
- the already-existing source directory (required)destination
- the destination directory (required)deleteDestinationOnExit
- indicates whether to mark any created destinations for deletion on exit
public static boolean denotesAbsolutePath(String fileName)
fileName
- name of a file, which could be an absolute path
public static String getFirstDirectory(String fileIdentifier)
fileIdentifier
- the path to parse (required)
public static String backOneDirectory(String fileIdentifier)
fileIdentifier
-
public static String removeTrailingSeparator(String path)
File.separator
s from the given path
path
- the path to modify (can be null
)
public static boolean matchesAntPath(String antPattern, String canonicalPath)
antPattern
- the pattern to check against (can't be blank)canonicalPath
- the path to check (can't be blank)
public static String removeLeadingAndTrailingSeparators(String path)
File.separator
s from the given path.
path
- the path to modify (can be null
)
null
if null
was givenpublic static String ensureTrailingSeparator(String path)
File.separator
path
- the path to modify (can't be null
)
public static String getSystemDependentPath(String... pathElements)
File.separator
.
pathElements
- the path elements from uppermost downwards (can't be empty)
public static String getSystemDependentPath(Collection<String> pathElements)
File.separator
.
pathElements
- the path elements from uppermost downwards (can't be empty)
public static String getCanonicalPath(File file)
File
.
file
- the file for which to find the canonical path (can be null
)
null
if a null
file is givenpublic static String getFileSeparatorAsRegex()
public static String getPath(Class<?> loadingClass, String relativeFilename)
loadingClass
- the class to whose package the given file is relative (required)relativeFilename
- the name of the file relative to that package (required)
null
)public static File getFile(Class<?> loadingClass, String filename)
loadingClass
- the class from whose package to load the file (required)filename
- the name of the file to load, relative to that package (required)
null
)
IllegalArgumentException
- if the given file cannot be foundpublic static InputStream getInputStream(Class<?> loadingClass, String filename)
loadingClass
- the class from whose package to load the file (required)filename
- the name of the file to load, relative to that package (required)
null
)
IllegalArgumentException
- if the given file cannot be foundpublic static String readBanner(Reader reader)
public static String readBanner(Class<?> loadingClass, String resourceName)
public static String read(File file)
file
- the file to read from (must be an existing file)
IllegalStateException
- in case of I/O errors
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |