java.lang.Object
imagingbook.core.FileUtils
This class defines various static methods for managing
file-based resources and JAR manifest files.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancheckClass(String classname) Checks 'by name' if a particular class exists.static voidcopyToFile(InputStream in, File file) Reads all data from the given input stream and copies them to to a file.static StringgetClassPath(Class<?> clazz) Find the path from which a given class was loaded.static StringDeprecated.static StringgetCurrentDirectory(Class<?> clazz) Returns the current directory associated with the specified class.static StringgetFileExtension(String name) Extracts the extension part of a pathname as a string.static ManifestgetJarManifest(Class<?> clazz) Finds the manifest (from META-INF/MANIFEST.MF) of the JAR file from which clazz was loaded.static StringgetModuleName(Class<?> clazz) static StringgetModuleName2(Class<?> clazz) static Stringstatic voidstatic voidLists (to System.out) the paths where classes are loaded from.static FileselectFolder(String startDirectory, String dialogTitle) Opens a dialog for the user to select a single folder (no files).static voidsetCurrentDirectory(Class<?> clazz, String pathname) Associates a current directory with the specified class by setting a system property to make this persistent through class reloads.static voidsetCurrentDirectory(Class<?> clazz, Path path) static voidsetCurrentDirectory(String pathname) Deprecated.static StringstripFileExtension(String name) Removes the extension part of a pathname.
-
Constructor Details
-
FileUtils
public FileUtils()
-
-
Method Details
-
stripFileExtension
Removes the extension part of a pathname. Examples:
"foo.txt" → "foo", "foo" → "foo", "foo." → "foo.", ".txt" → ".txt".- Parameters:
name- the pathname- Returns:
- the pathname without the extension (if valid)
-
getFileExtension
Extracts the extension part of a pathname as a string. Examples:
"foo.txt" → "txt", "foo" → "", "foo." → "", ".txt" → "".- Parameters:
name- the pathname- Returns:
- the extension or an empty string
-
getClassPath
Find the path from which a given class was loaded.- Parameters:
clazz- a class.- Returns:
- the path of the .class file for the given class or null (e.g. if the class is anonymous).
-
printClassPath
Lists (to System.out) the paths where classes are loaded from. -
checkClass
Checks 'by name' if a particular class exists.- Parameters:
classname- fully qualified name of the class, e.g. imagingbook.lib.util.FileUtils- Returns:
trueif the class was found,falseotherwise
-
copyToFile
Reads all data from the given input stream and copies them to to a file.- Parameters:
in- the input streamfile- the output file- Throws:
IOException- if anything goes wrong
-
getJarManifest
Finds the manifest (from META-INF/MANIFEST.MF) of the JAR file from which clazz was loaded. See: http://stackoverflow.com/a/1273432- Parameters:
clazz- A class in the JAR file of interest.- Returns:
- A
Manifestobject or null if clazz was not loaded from a JAR file.
-
selectFolder
Opens a dialog for the user to select a single folder (no files). Contained files and sub-folders are shown. Uses native (system) look-and-feel; original look-and-feel is restored.- Parameters:
startDirectory- the directory to start from (pass""or"."for the current directory)dialogTitle- the string shown in the title bar of the dialog window- Returns:
- a
Fileobject representing the selected directory ornullif the dialog was canceled
-
setCurrentDirectory
Deprecated.Sets a system property to memorize the current directory. UsegetCurrentDirectory()to retrieve this value. If the specified pathname is not a directory (i.e., a plain file), its parent directory is used.- Parameters:
pathname- a directory of file path
-
setCurrentDirectory
Associates a current directory with the specified class by setting a system property to make this persistent through class reloads. UsegetCurrentDirectory(Class)to retrieve this value. If the specified pathname is not a directory (i.e., a plain file), its parent directory is used.- Parameters:
clazz- the class to associate the directory withpathname- a directory of file path
-
setCurrentDirectory
-
getCurrentDirectory
Deprecated.Returns the current directory path. If the directory was set withsetCurrentDirectory(String)before this path is returned, otherwise the value for the "user.dir" system property.- Returns:
- a string with the current directory path
-
getCurrentDirectory
Returns the current directory associated with the specified class. (usually of typePlugInorPlugInFilter). If the directory was set withsetCurrentDirectory(Class,String)before this path is returned,nullotherwise.- Parameters:
clazz- the class to associate the directory with- Returns:
- a string with the current directory path or null if not registered
-
getTempDirectory
-
getModuleName
-
getModuleName2
- Throws:
URISyntaxException
-
main
- Throws:
URISyntaxException
-