Package com.google.gwt.util.tools
Class Utility
java.lang.Object
com.google.gwt.util.tools.Utility
A smattering of useful functions.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidclose(AutoCloseable closeable) Helper that ignores exceptions during close, because what are you going to do?static FilecreateNormalFile(File parent, String fileName, boolean overwrite, boolean ignore) static FilegetDirectory(File parent, String dirName, boolean create) static FilegetDirectory(String dirPath, boolean create) static StringgetFileFromClassPath(String partialPath) Gets the contents of a file from the class path as a String.static Stringstatic FilemakeTemporaryDirectory(File baseDir, String prefix) Creates a randomly-named temporary directory.static voidstreamOut(InputStream in, OutputStream out, int bufferSize) static intversionCompare(String v1, String v2) Handles comparison between version numbers (the right way(TM)).static voidwriteTemplateBinaryFile(File file, byte[] contents) static void
-
Constructor Details
-
Utility
public Utility()
-
-
Method Details
-
close
Helper that ignores exceptions during close, because what are you going to do? -
createNormalFile
public static File createNormalFile(File parent, String fileName, boolean overwrite, boolean ignore) throws IOException - Parameters:
parent- Parent directoryfileName- New file nameoverwrite- Is overwriting an existing file allowed?- Returns:
- Handle to the file
- Throws:
IOException- If the file cannot be created, or if the file already existed and overwrite was false.
-
getDirectory
- Parameters:
parent- Parent directory of the requested directory.dirName- Requested name for the directory.create- Create the directory if it does not already exist?- Returns:
- A
Filerepresenting a directory that now exists. - Throws:
IOException- If the directory is not found and/or cannot be created.
-
getDirectory
- Parameters:
dirPath- Requested path for the directory.create- Create the directory if it does not already exist?- Returns:
- A
Filerepresenting a directory that now exists. - Throws:
IOException- If the directory is not found and/or cannot be created.
-
getFileFromClassPath
Gets the contents of a file from the class path as a String. Note: this method is only guaranteed to work for resources in the same class loader that contains thisUtilityclass.- Parameters:
partialPath- the partial path to the resource on the class path- Returns:
- the contents of the file
- Throws:
IOException- if the file could not be found or an error occurred while reading it
-
getInstallPath
-
makeTemporaryDirectory
Creates a randomly-named temporary directory.- Parameters:
baseDir- base directory to contain the new directory. May benull, in which case the directory given by thejava.io.tmpdirsystem property will be used.prefix- the initial characters of the new directory name- Returns:
- a newly-created temporary directory; the caller must delete this directory (either when done or on VM exit)
- Throws:
IOException
-
streamOut
- Throws:
IOException
-
writeTemplateBinaryFile
- Throws:
IOException
-
writeTemplateFile
public static void writeTemplateFile(File file, String contents, Map<String, String> replacements) throws IOException- Throws:
IOException
-
versionCompare
Handles comparison between version numbers (the right way(TM)). Examples of version strings: 1.6.7, 1.2_b10- Parameters:
v1- the first version to compare.v2- the second version to compare.- Returns:
- a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
- Throws:
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]+)?
-