public final class Utility extends Object
Constructor and Description |
---|
Utility() |
Modifier and Type | Method and Description |
---|---|
static void |
close(InputStream is)
Helper that ignores exceptions during close, because what are you going to
do?
|
static void |
close(OutputStream os)
Helper that ignores exceptions during close, because what are you going to
do?
|
static void |
close(RandomAccessFile f)
Helper that ignores exceptions during close, because what are you going to
do?
|
static void |
close(Reader reader)
Helper that ignores exceptions during close, because what are you going to
do?
|
static void |
close(Socket socket)
Helper that ignores exceptions during close, because what are you going to
do?
|
static void |
close(Writer writer)
Helper that ignores exceptions during close, because what are you going to
do?
|
static File |
createNormalFile(File parent,
String fileName,
boolean overwrite,
boolean ignore) |
static File |
getDirectory(File parent,
String dirName,
boolean create) |
static File |
getDirectory(String dirPath,
boolean create) |
static String |
getFileFromClassPath(String partialPath)
Gets the contents of a file from the class path as a String.
|
static String |
getInstallPath() |
static File |
makeTemporaryDirectory(File baseDir,
String prefix)
Creates a randomly-named temporary directory.
|
static void |
streamOut(File file,
OutputStream out,
int bufferSize) |
static void |
streamOut(InputStream in,
OutputStream out,
int bufferSize) |
static int |
versionCompare(String v1,
String v2)
Handles comparison between version numbers (the right way(TM)).
|
static void |
writeTemplateBinaryFile(File file,
byte[] contents) |
static void |
writeTemplateFile(File file,
String contents,
Map<String,String> replacements) |
public static void close(InputStream is)
public static void close(OutputStream os)
public static void close(RandomAccessFile f)
public static void close(Reader reader)
public static void close(Socket socket)
public static void close(Writer writer)
public static File createNormalFile(File parent, String fileName, boolean overwrite, boolean ignore) throws IOException
parent
- Parent directoryfileName
- New file nameoverwrite
- Is overwriting an existing file allowed?IOException
- If the file cannot be created, or if the file already
existed and overwrite was false.public static File getDirectory(File parent, String dirName, boolean create) throws 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.IOException
- If the directory is not found and/or cannot be created.public static File getDirectory(String dirPath, boolean create) throws IOException
dirPath
- Requested path for the directory.create
- Create the directory if it does not already exist?File
representing a directory that now exists.IOException
- If the directory is not found and/or cannot be created.public static String getFileFromClassPath(String partialPath) throws IOException
Utility
class.partialPath
- the partial path to the resource on the class pathIOException
- if the file could not be found or an error occurred
while reading itpublic static String getInstallPath()
public static File makeTemporaryDirectory(File baseDir, String prefix) throws 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 nameIOException
public static void streamOut(File file, OutputStream out, int bufferSize) throws IOException
IOException
public static void streamOut(InputStream in, OutputStream out, int bufferSize) throws IOException
IOException
public static void writeTemplateBinaryFile(File file, byte[] contents) throws IOException
IOException
public static void writeTemplateFile(File file, String contents, Map<String,String> replacements) throws IOException
IOException
public static int versionCompare(String v1, String v2)
v1
- the first version to compare.v2
- the second version to compare.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]+)?Copyright © 2018. All rights reserved.