public class GGPath
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static void |
closeInputStream(java.io.InputStream is)
Closes the given input stream.
|
static void |
closeOutputStream(java.io.OutputStream os)
Closes the given output stream.
|
static boolean |
copyDirectory(java.io.File srcDir,
java.io.File destDir,
boolean collect)
Copies all files from the source directory into the destination directory.
|
static boolean |
copyFile(java.io.File src,
java.io.File dest)
Copies binary data from the source file to the destination file.
|
static boolean |
copyFile(java.net.URL url,
java.io.File dest)
Copies binary data from the source URL to the destination file.
|
static boolean |
copyTree(java.io.File srcDir,
java.io.File destDir)
Copies all files with subdirectory structure from the source directory to
the destination directory.
|
static boolean |
createDirectoryTree(java.io.File dirPath)
Creates a directory structure.
|
static int |
getNbFiles(java.io.File dirPath)
Returns number of files (subdirectories are not counted) in given directory.
|
static boolean |
isDirectoryEmpty(java.io.File dirPath)
Returns true, if the directory is empty (no files and no subdirectories).
|
static java.io.InputStream |
openResource(java.lang.String relPath)
Loads a binary resource from the application JAR file,
e.g. get a BufferedImage reference from a image resource with bi = ImageIO.read(openResource(path)). |
static boolean |
pack(java.io.File jarFile,
java.io.File dirPath)
Creates a compressed JAR archive from a all files and subdirectories
in directory with given dirPath.
|
static java.lang.String |
readTextFile(java.io.File filePath)
Reads a text file into a string.
|
static java.lang.String |
readTextResource(java.lang.String relPath)
Reads a text resource from the application JAR file.
|
static boolean |
removeDir(java.io.File dirPath)
(Be very careful) Deletes all files and subdirectories and
the directory itself.
|
static boolean |
removeFiles(java.io.File dirPath,
boolean clean)
(Be very careful) Deletes all files in directory
(but not the directory itself).
|
static boolean |
unpack(java.io.File jarFile,
java.io.File dirPath)
Unpacks the given JAR archive in the given directory.
|
static boolean |
unzip(java.io.File zipFile,
java.io.File dirPath)
Unpacks the given ZIP archive in the given directory.
|
static boolean |
writeTextFile(java.io.File filePath,
java.lang.String text,
boolean createTree)
Writes the given string to the given destination file.
|
static boolean |
zip(java.io.File zipFile,
java.io.File dirPath)
Creates a ZIP archive from a all files and subdirectories
in directory with given dirPath.
|
public static boolean writeTextFile(java.io.File filePath, java.lang.String text, boolean createTree)
filePath
- a relative or absolute path to the filetext
- the text to writecreateTree
- if true, a nonexistent subdirectory structure is createdpublic static java.lang.String readTextFile(java.io.File filePath)
filePath
- a relative or absolute path to the filepublic static java.lang.String readTextResource(java.lang.String relPath)
relPath
- a relative path to the resource file starting from the
root of the JAR archivepublic static java.io.InputStream openResource(java.lang.String relPath)
relPath
- a relative path to the resource file starting
from the root of the JAR archivepublic static void closeInputStream(java.io.InputStream is)
is
- the stream to closepublic static void closeOutputStream(java.io.OutputStream os)
os
- the stream to closepublic static boolean removeFiles(java.io.File dirPath, boolean clean)
dirPath
- path to a directory. A trailing file separator is ignoredclean
- if true, all subdirectories are removed also; otherwise only
files in dirPath are deleted and the subdirectories with their files are
maintainedpublic static boolean removeDir(java.io.File dirPath)
dirPath
- path to a directory. A trailing file separator is ignoredpublic static boolean createDirectoryTree(java.io.File dirPath)
dirPath
- a relative or absolute directory path that may contain
subdirectories, e.g. /dir/subdir1/subdir2. A trailing file separator is ignored.
Under Windows the absolute path may be proceeded by a drive designator (e.g. 'c:').public static boolean copyFile(java.net.URL url, java.io.File dest)
url
- the source URL, e.g. "http://myserver.com/image.gif"dest
- a relative or absolute file path of the destination filepublic static boolean copyFile(java.io.File src, java.io.File dest)
src
- a relative or absolute file path of the source filedest
- a relative or absolute file path of the destination filepublic static boolean copyDirectory(java.io.File srcDir, java.io.File destDir, boolean collect)
srcDir
- the source directory (absolute or relative)destDir
- the destination directory (absolute or relative)collect
- if true, all files in subdirectories of the source
directory are copied to the root of the destination directory
(use copyTree() to maintain the subdirectory structure under the destination
directory)public static boolean copyTree(java.io.File srcDir, java.io.File destDir)
srcDir
- the source directory (absolute or relative)destDir
- the destination directory (absolute or relative)public static int getNbFiles(java.io.File dirPath)
dirPath
- path to a directory. A trailing file separator is ignoredpublic static boolean isDirectoryEmpty(java.io.File dirPath)
dirPath
- path to a directory. A trailing file separator is ignoredpublic static boolean unpack(java.io.File jarFile, java.io.File dirPath)
jarFile
- the JAR to unpackdirPath
- path to a directory. A trailing file separator is ignoredpublic static boolean pack(java.io.File jarFile, java.io.File dirPath)
jarFile
- the JAR archive to createdirPath
- path to the directory that holds the
files/subdirectories to add to the archive. An emtpy directory is illegal.
A trailing file separator is ignoredpublic static boolean unzip(java.io.File zipFile, java.io.File dirPath)
zipFile
- the ZIP to unpackdirPath
- path to a directory. A trailing file separator is ignoredpublic static boolean zip(java.io.File zipFile, java.io.File dirPath)
zipFile
- the ZIP archive to createdirPath
- path to the directory that holds the
files/subdirectories to add to the archive. An empty directory is illegal.
A trailing file separator is ignored