|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.scijava.util.FileUtils
public final class FileUtils
Useful methods for working with file paths.
Field Summary | |
---|---|
static int |
DEFAULT_SHORTENER_THRESHOLD
|
static String |
SHORTENER_BACKSLASH
|
static String |
SHORTENER_BACKSLASH_REGEX
|
static String |
SHORTENER_ELLIPSE
|
static String |
SHORTENER_SLASH
|
static String |
SHORTENER_SLASH_REGEX
|
Method Summary | |
---|---|
static Collection<URL> |
appendContents(Collection<URL> result,
URL directory)
Recursively adds contents from the referenced directory to an existing collection. |
static Collection<URL> |
appendContents(Collection<URL> result,
URL directory,
boolean recurse,
boolean filesOnly)
Add contents from the referenced directory to an existing collection. |
static File |
createTemporaryDirectory(String prefix,
String suffix)
Creates a temporary directory. |
static File |
createTemporaryDirectory(String prefix,
String suffix,
File directory)
Creates a temporary directory. |
static boolean |
deleteRecursively(File directory)
Deletes a directory recursively. |
static File[] |
getAllVersions(File directory,
String filename)
Lists all versions of a given (possibly versioned) file name. |
static String |
getExtension(File file)
Extracts the file extension from a file. |
static String |
getExtension(String path)
Extracts the file extension from a file path. |
static String |
getPath(File file)
Gets the absolute path to the given file, with the directory separator standardized to forward slash, like most platforms use. |
static String |
getPath(String path,
String separator)
Gets a standardized path based on the given one, with the directory separator standardized from the specific separator to forward slash, like most platforms use. |
static String |
limitPath(String path,
int limit)
Compacts a path into a given number of characters. |
static Collection<URL> |
listContents(URL directory)
Recursively lists the contents of the referenced directory. |
static Collection<URL> |
listContents(URL directory,
boolean recurse,
boolean filesOnly)
Lists all contents of the referenced directory. |
static Matcher |
matchVersionedFilename(String filename)
Deprecated. see stripFilenameVersion(String) |
static String |
shortenPath(String path)
Shortens the path to a maximum of 4 path elements. |
static String |
shortenPath(String path,
int threshold)
Shortens the path based on the given maximum number of path elements. |
static String |
stripFilenameVersion(String filename)
|
static File |
urlToFile(String url)
Converts the given URL string to its corresponding File . |
static File |
urlToFile(URL url)
Converts the given URL to its corresponding File . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT_SHORTENER_THRESHOLD
public static final String SHORTENER_BACKSLASH_REGEX
public static final String SHORTENER_SLASH_REGEX
public static final String SHORTENER_BACKSLASH
public static final String SHORTENER_SLASH
public static final String SHORTENER_ELLIPSE
Method Detail |
---|
public static String getPath(File file)
file
- The file whose path will be obtained and standardized.
public static String getPath(String path, String separator)
path
- The path to standardize.separator
- The directory separator to be standardized.
public static String getExtension(File file)
file
- the file object
public static String getExtension(String path)
path
- the path to the file (relative or absolute)
public static String stripFilenameVersion(String filename)
public static File[] getAllVersions(File directory, String filename)
directory
- the directory to scanfilename
- the file name to use
public static File urlToFile(URL url)
URL
to its corresponding File
.
This method is similar to calling new File(url.toURI())
except that
it also handles "jar:file:" URLs, returning the path to the JAR file.
url
- The URL to convert.
FileInputStream
IllegalArgumentException
- if the URL does not correspond to a file.public static File urlToFile(String url)
File
.
url
- The URL to convert.
FileInputStream
IllegalArgumentException
- if the URL does not correspond to a file.public static String shortenPath(String path)
path
- the path to the file (relative or absolute)
public static String shortenPath(String path, int threshold)
path
- the path to the file (relative or absolute)threshold
- the number of directories to keep unshortened
public static String limitPath(String path, int limit)
path
- the path to the file (relative or absolute)limit
- the number of characters to which the path should be limited
public static File createTemporaryDirectory(String prefix, String suffix) throws IOException
Since there is no atomic operation to do that, we create a temporary file, delete it and create a directory in its place. To avoid race conditions, we use the optimistic approach: if the directory cannot be created, we try to obtain a new temporary file rather than erroring out.
It is the caller's responsibility to make sure that the directory is deleted.
prefix
- The prefix string to be used in generating the file's name;
see File.createTempFile(String, String, File)
suffix
- The suffix string to be used in generating the file's name;
see File.createTempFile(String, String, File)
IOException
public static File createTemporaryDirectory(String prefix, String suffix, File directory) throws IOException
Since there is no atomic operation to do that, we create a temporary file, delete it and create a directory in its place. To avoid race conditions, we use the optimistic approach: if the directory cannot be created, we try to obtain a new temporary file rather than erroring out.
It is the caller's responsibility to make sure that the directory is deleted.
prefix
- The prefix string to be used in generating the file's name;
see File.createTempFile(String, String, File)
suffix
- The suffix string to be used in generating the file's name;
see File.createTempFile(String, String, File)
directory
- The directory in which the file is to be created, or null
if the default temporary-file directory is to be used
IOException
public static boolean deleteRecursively(File directory)
directory
- The directory to delete.
File.delete()
)public static Collection<URL> listContents(URL directory)
file
and
jar
.
directory
- The directory whose contents should be listed.
URL
s representing the directory's contents.listContents(URL, boolean, boolean)
public static Collection<URL> listContents(URL directory, boolean recurse, boolean filesOnly)
file
and jar
.
directory
- The directory whose contents should be listed.recurse
- Whether to list contents recursively, as opposed to only the
directory's direct contents.filesOnly
- Whether to exclude directories in the resulting collection
of contents.
URL
s representing the directory's contents.public static Collection<URL> appendContents(Collection<URL> result, URL directory)
file
and jar
.
result
- The collection to which contents should be added.directory
- The directory whose contents should be listed.
URL
s representing the directory's contents.appendContents(Collection, URL, boolean, boolean)
public static Collection<URL> appendContents(Collection<URL> result, URL directory, boolean recurse, boolean filesOnly)
file
and jar
.
result
- The collection to which contents should be added.directory
- The directory whose contents should be listed.recurse
- Whether to append contents recursively, as opposed to only
the directory's direct contents.filesOnly
- Whether to exclude directories in the resulting collection
of contents.
URL
s representing the directory's contents.@Deprecated public static Matcher matchVersionedFilename(String filename)
stripFilenameVersion(String)
Matcher
object dissecting a versioned file name.
filename
- the file name
Matcher
object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |