public final class Utility
extends java.lang.Object
Constructor and Description |
---|
Utility() |
Modifier and Type | Method and Description |
---|---|
static void |
close(java.lang.AutoCloseable closeable)
Helper that ignores exceptions during close, because what are you going to
do?
|
static java.io.File |
createNormalFile(java.io.File parent,
java.lang.String fileName,
boolean overwrite,
boolean ignore) |
static java.io.File |
getDirectory(java.io.File parent,
java.lang.String dirName,
boolean create) |
static java.io.File |
getDirectory(java.lang.String dirPath,
boolean create) |
static java.lang.String |
getFileFromClassPath(java.lang.String partialPath)
Gets the contents of a file from the class path as a String.
|
static java.lang.String |
getInstallPath() |
static java.io.File |
makeTemporaryDirectory(java.io.File baseDir,
java.lang.String prefix)
Creates a randomly-named temporary directory.
|
static void |
streamOut(java.io.InputStream in,
java.io.OutputStream out,
int bufferSize) |
static int |
versionCompare(java.lang.String v1,
java.lang.String v2)
Handles comparison between version numbers (the right way(TM)).
|
static void |
writeTemplateBinaryFile(java.io.File file,
byte[] contents) |
static void |
writeTemplateFile(java.io.File file,
java.lang.String contents,
java.util.Map<java.lang.String,java.lang.String> replacements) |
public static void close(java.lang.AutoCloseable closeable)
public static java.io.File createNormalFile(java.io.File parent, java.lang.String fileName, boolean overwrite, boolean ignore) throws java.io.IOException
parent
- Parent directoryfileName
- New file nameoverwrite
- Is overwriting an existing file allowed?java.io.IOException
- If the file cannot be created, or if the file already
existed and overwrite was false.public static java.io.File getDirectory(java.io.File parent, java.lang.String dirName, boolean create) throws java.io.IOException
parent
- Parent directory of the requested directory.dirName
- Requested name for the directory.create
- Create the directory if it does not already exist?File
representing a directory that now exists.java.io.IOException
- If the directory is not found and/or cannot be created.public static java.io.File getDirectory(java.lang.String dirPath, boolean create) throws java.io.IOException
dirPath
- Requested path for the directory.create
- Create the directory if it does not already exist?File
representing a directory that now exists.java.io.IOException
- If the directory is not found and/or cannot be created.public static java.lang.String getFileFromClassPath(java.lang.String partialPath) throws java.io.IOException
Utility
class.partialPath
- the partial path to the resource on the class pathjava.io.IOException
- if the file could not be found or an error occurred
while reading itpublic static java.lang.String getInstallPath()
public static java.io.File makeTemporaryDirectory(java.io.File baseDir, java.lang.String prefix) throws java.io.IOException
baseDir
- base directory to contain the new directory. May be
null
, in which case the directory given by the
java.io.tmpdir
system property will be used.prefix
- the initial characters of the new directory namejava.io.IOException
public static void streamOut(java.io.InputStream in, java.io.OutputStream out, int bufferSize) throws java.io.IOException
java.io.IOException
public static void writeTemplateBinaryFile(java.io.File file, byte[] contents) throws java.io.IOException
java.io.IOException
public static void writeTemplateFile(java.io.File file, java.lang.String contents, java.util.Map<java.lang.String,java.lang.String> replacements) throws java.io.IOException
java.io.IOException
public static int versionCompare(java.lang.String v1, java.lang.String v2)
v1
- the first version to compare.v2
- the second version to compare.java.lang.IllegalArgumentException
- if the version number are not proper (i.e. the do not comply
with the following regular expression
[0-9]+(.[0-9]+)*(_[a-zA-Z0-9]+)?