Package org.apache.openjpa.lib.util
Class Files
java.lang.Object
org.apache.openjpa.lib.util.Files
Utility operations on files.
- Author:
- Abe White
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic File
Backup the given file to a new file called <file-name>~.static boolean
Copy a file.static File
getClassFile
(Class cls) Return the class file of the given class, or null if the class is in a jar.static File
getFile
(String name, ClassLoader loader) Check the given string for a matching file.static OutputStream
getOutputStream
(String file, ClassLoader loader) Return an output stream to the stream(stdout or stderr) or file named by the given string.static File
getPackageFile
(File base, String pkg, boolean mkdirs) Return the file for the given package.static File
getSourceFile
(Class cls) Return the source file for the given class, or null if the source is not in the CLASSPATH.static Writer
getWriter
(String file, ClassLoader loader) Return a writer to the stream(stdout or stderr) or file named by the given string.static Writer
getWriter
(String file, ClassLoader loader, String enc) Return a writer to the stream(stdout or stderr) or file named by the given string set to the provided charset encoding.static File
Revert the given backup file to the original location.
-
Constructor Details
-
Files
public Files()
-
-
Method Details
-
backup
Backup the given file to a new file called <file-name>~. If the file does not exist or a backup could not be created, returns null. -
revert
Revert the given backup file to the original location. If the given file's name does not end in '~', the '~' is appended before proceeding. If the backup file does not exist or could not be reverted, returns null. -
getSourceFile
Return the source file for the given class, or null if the source is not in the CLASSPATH. -
getClassFile
Return the class file of the given class, or null if the class is in a jar. -
getPackageFile
Return the file for the given package. If the given base directory matches the given package structure, it will be used as-is. If not, the package structure will be added beneath the base directory. If the base directory is null, the current working directory will be used as the base. -
getFile
Check the given string for a matching file. The string is first tested to see if it is an existing file path. If it does not represent an existing file, it is checked as a resource name of a file. If no resource exists, then it is interpreted as a path to a file that does not exist yet.- Parameters:
name
- the file path or resource nameloader
- a class loader to use in resource lookup, or null to use the thread's context loader
-
getWriter
Return a writer to the stream(stdout or stderr) or file named by the given string.- Throws:
IOException
- See Also:
-
getWriter
Return a writer to the stream(stdout or stderr) or file named by the given string set to the provided charset encoding.- Throws:
IOException
- See Also:
-
getOutputStream
Return an output stream to the stream(stdout or stderr) or file named by the given string. -
copy
Copy a file. Return false iffrom
does not exist.- Throws:
IOException
-