public final class JavaUtils
extends java.lang.Object
getImageFromURL
which supports loading an Image
object from an image
file. Method translateToXMLCDATA
supports all forbidden characters for XML elements
and attributes now.
For the other methods see the documentation comments below.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
LINE_SEPARATOR
Provides the linefeed appropriate for the system.
|
static java.lang.String |
PROPERTY_JNLP_BASE_URL
System property holding the deploy URL used for Web Start.
|
static java.lang.String |
PROPERTY_JNLP_DEPLOY_ID
System property holding the current application ID from deploy.properties.
|
static java.lang.String |
PROPERTY_JNLP_LOCALES
System property holding the supported locales for Web Start.
|
static java.lang.String |
PROPERTY_JNLP_RESTART_EXE
System property holding the installer restart executable.
|
static java.lang.String |
PROPERTY_JNLP_RESTART_URL
System property holding the Java restart URL used for Web Start.
|
Constructor and Description |
---|
JavaUtils()
Constructor method for i18n purposes only.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.Object |
addToArray(java.lang.Object array,
java.lang.Object newval)
Adds another element to the given array (saves
System.arraycopy() calls). |
static boolean |
arrayEquals(java.lang.Object array1,
java.lang.Object array2)
Compares two arrays field by field since Java lacks
equals() for arrays. |
static boolean |
arrayEqualsNull(java.lang.Object array1,
java.lang.Object array2)
Compares two arrays field by field since Java lacks
equals() for arrays. |
static void |
browse(java.lang.String uri)
Let's the system browse the given uniform resource identifier like an URL.
|
static boolean |
canRestart()
Can the running application be restarted programmtically?
|
static java.io.File |
changeInstallerMaxMem(int maxmem)
Tries to change the maximum amount of memory in the installer specific deployment file.
|
static boolean |
checkJavaVersion(java.lang.String regex)
Checks if the current Java version is OK for the given version pattern.
|
static <T> T[] |
convertToArray(java.util.Vector<T> container,
T[] array)
Converts the given
Vector to an array representation. |
static byte[] |
convertToBytes(java.lang.String hexdata)
Converts a hexadecimal value to the corresponding raw bytes array.
|
static java.lang.String |
convertToHex(byte[] rawdata,
boolean uppercase)
Converts binary data to a sequence of hex digits of full length (leading/trailing zeroes).
|
static java.lang.String |
convertToHex(byte[] rawdata,
boolean uppercase,
boolean spaces)
Converts binary data to a sequence of hex digits of full length (leading/trailing zeroes).
|
static java.lang.String |
convertToHex(byte b,
boolean uppercase)
Converts a single byte to hex representation.
|
static <T> java.util.Vector<T> |
convertToVector(T[] array)
Converts the given array to a
Vector representation. |
static boolean |
elementOf(java.lang.Object object,
java.lang.Object array)
Checks if the given object is element of the given array (equals).
|
static boolean |
equalsNull(java.lang.Object obj1,
java.lang.Object obj2)
Convenience method to compare objects using
equals() which may be null . |
static java.lang.Object |
findKey(java.util.Hashtable container,
java.lang.Object value)
Searches the given container and provides the key for the given value object.
|
static java.lang.String |
formatNumber(long number)
Formats a long number for the current locale setting.
|
static java.lang.String |
generateShort(long value)
Generates the short forms of long numbers like '99 MB'.
|
static java.lang.String |
generateShort(long value,
java.lang.String pattern)
Generates the short forms of long numbers like '99 MB'.
|
static java.lang.String |
generateShort(long value,
java.lang.String pattern,
java.util.Locale locale)
Generates the short forms of long numbers like '99.9 MB'.
|
static java.lang.String |
generateShortBytes(long value,
java.lang.String pattern,
java.util.Locale locale)
Generates the short forms of long numbers like '123456789' (bytes) without unit identifier.
|
static java.lang.String |
generateShortGB(long value,
java.lang.String pattern,
java.util.Locale locale)
Generates the short forms of long numbers like '12345.3' (mega bytes) without unit identifier.
|
static java.lang.String |
generateShortKB(long value)
Generates the short forms of long numbers like '99 KB' (kilo bytes only).
|
static java.lang.String |
generateShortKB(long value,
java.lang.String pattern,
java.util.Locale locale)
Generates the short forms of long numbers like '12345.3' (kilo bytes) without unit identifier.
|
static java.lang.String |
generateShortMB(long value,
java.lang.String pattern,
java.util.Locale locale)
Generates the short forms of long numbers like '12345.3' (mega bytes) without unit identifier.
|
static java.lang.String |
generateShortTB(long value,
java.lang.String pattern,
java.util.Locale locale)
Generates the short forms of long numbers like '12345.3' (tera bytes) without unit identifier.
|
static java.lang.String |
getMethod(boolean full)
Detemrines the name of the current method from the stack trace.
|
static java.lang.String |
getUserHome()
Determines the user's home directory either from system or InstallAnywhere.
|
static java.util.Vector<Locale> |
getWebStartLocales()
Scans for the <
locales system property added optionally by Web Start. |
static int |
indexOf(java.lang.Object object,
java.lang.Object array)
Determines the index of the given element in the array.
|
static boolean |
isDevelopment()
Is the application currently being executed in a development environment?
|
static boolean |
isInstalled()
Has the application been installed with an installer?
|
static boolean |
isInteger(java.lang.String value)
Determines whether the given parameter is an integer value or not.
|
static boolean |
isLinux()
Is the VM running on a Linux operating system?
|
static boolean |
isLong(java.lang.String value)
Determines whether the given parameter is a
Long value or not. |
static boolean |
isMacOSX()
Is the VM running on an Apple Mac OS X operating system?
|
static boolean |
isMethodCalled(java.lang.Class clazz)
Determines whether the given method call is part of the stack trace.
|
static boolean |
isMethodCalled(java.lang.Class clazz,
java.lang.String method)
Determines whether the given method call is part of the stack trace.
|
static boolean |
isSolaris()
Is the VM running on a Solaris operating system?
|
static boolean |
isWebStart()
Is the application running with Java Web Start?
|
static boolean |
isWindows()
Is the VM running on a Microsoft Windows operating system?
|
static java.lang.Class |
mapToPrimitive(java.lang.Class clazz)
Provides the associated primitive type (
Integer -> int ). |
static java.lang.Object |
minimizeArray(java.lang.Object array)
Creates an array where the
null elements of the given array are eliminated. |
static <T> void |
moveDown(java.util.Vector<T> container,
T element)
Convenience method to move down an element within a container.
|
static <T> void |
moveUp(java.util.Vector<T> container,
T element)
Convenience method to move up an element within a container.
|
static java.lang.String |
nextIdentifier(java.lang.String item,
java.util.Hashtable itemset)
Determines the next item string for a set of strings.
|
static long |
parseTotalBytes(java.lang.String raw)
Parses byte size abbreviations like "10M" and returns the number of bytes.
|
static java.lang.Object |
prependToArray(java.lang.Object array,
java.lang.Object newval)
Prepends another element to the given array (saves
System.arraycopy() calls). |
static java.lang.String |
printStackTrace(java.lang.Exception exc,
java.lang.String encoding)
Prints the stack trace of the given exception as text instead of
System.out . |
static void |
restartInstaller()
Tries to restart the running application programmatically.
|
static void |
restartJNLP(java.io.File tempjnlp,
java.lang.String restartURL)
Tries to restart the running application programmatically.
|
static void |
runWebStart(java.lang.String params)
Tries to start the Java Control Panel application from the current path.
|
static java.lang.Object |
subarray(java.lang.Object array,
int beginindex,
int endindex)
Creates a subarray.
|
static void |
uninstallInstaller(java.lang.String regex)
Tries to uninstall the running application programmatically.
|
static boolean |
vectorEquals(java.util.Vector v1,
java.util.Vector v2)
Compares two containers element by element.
|
public static final java.lang.String LINE_SEPARATOR
public static final java.lang.String PROPERTY_JNLP_RESTART_URL
public static final java.lang.String PROPERTY_JNLP_LOCALES
public static final java.lang.String PROPERTY_JNLP_BASE_URL
public static final java.lang.String PROPERTY_JNLP_DEPLOY_ID
public static final java.lang.String PROPERTY_JNLP_RESTART_EXE
public JavaUtils() throws java.lang.InstantiationException
I18NExtractor
).
java.lang.InstantiationException
- Error indicationpublic static java.lang.String nextIdentifier(java.lang.String item, java.util.Hashtable itemset)
item
- The string which shall be modifieditemset
- Set of existing strings as keys in Hashtable
null
if something went wrongpublic static java.lang.String generateShort(long value)
value
- Numeric value to be shortenednull
if error occurspublic static java.lang.String generateShort(long value, java.lang.String pattern)
value
- Numeric value to be shortenedpattern
- DecimalFormat pattern like '#.##'null
if error occurspublic static java.lang.String generateShort(long value, java.lang.String pattern, java.util.Locale locale)
value
- Numeric value to be shortenedpattern
- DecimalFormat pattern like '#.##'locale
- The localenull
if error occursjava.lang.NullPointerException
- If parameters are null
java.lang.IllegalArgumentException
- If pattern is invalidpublic static java.lang.String generateShortKB(long value)
value
- Numeric value to be shortenednull
if error occurspublic static java.lang.String generateShortBytes(long value, java.lang.String pattern, java.util.Locale locale)
value
- Numeric value to be shortenedpattern
- DecimalFormat pattern like '#.##'locale
- The localejava.lang.NullPointerException
- If parameters are null
java.lang.IllegalArgumentException
- If pattern is invalidpublic static java.lang.String generateShortKB(long value, java.lang.String pattern, java.util.Locale locale)
value
- Numeric value to be shortenedpattern
- DecimalFormat pattern like '#.##'locale
- The localejava.lang.NullPointerException
- If parameters are null
java.lang.IllegalArgumentException
- If pattern is invalidpublic static java.lang.String generateShortMB(long value, java.lang.String pattern, java.util.Locale locale)
value
- Numeric value to be shortenedpattern
- DecimalFormat pattern like '#.##'locale
- The localejava.lang.NullPointerException
- If parameters are null
java.lang.IllegalArgumentException
- If pattern is invalidpublic static java.lang.String generateShortGB(long value, java.lang.String pattern, java.util.Locale locale)
value
- Numeric value to be shortenedpattern
- DecimalFormat pattern like '#.##'locale
- The localejava.lang.NullPointerException
- If parameters are null
java.lang.IllegalArgumentException
- If pattern is invalidpublic static java.lang.String generateShortTB(long value, java.lang.String pattern, java.util.Locale locale)
value
- Numeric value to be shortenedpattern
- DecimalFormat pattern like '#.##'locale
- The localejava.lang.NullPointerException
- If parameters are null
java.lang.IllegalArgumentException
- If pattern is invalidpublic static java.lang.String getUserHome()
lax.root.install.dir
is
used while user.home
is used if InstallAnywhere is absent.
System
public static boolean arrayEquals(java.lang.Object array1, java.lang.Object array2)
equals()
for arrays.
Returns true
only if the given arrays are exactly of the same type and
dimensions and additionally hold the same field contents (equals).
array1
- The first array to be comparedarray2
- The second array to be comparedjava.lang.NullPointerException
- If array1 and/or array2 is null
public static boolean arrayEqualsNull(java.lang.Object array1, java.lang.Object array2)
equals()
for arrays.
Returns true
only if all the objects are equal or both null
.
array1
- The first array to be comparedarray2
- The second array to be comparedjava.lang.NullPointerException
- If array1 and/or array2 is null
public static java.lang.Object addToArray(java.lang.Object array, java.lang.Object newval)
System.arraycopy()
calls).
array
- Target array of arbitrary typenewval
- Element to add, may be null
java.lang.IllegalArgumentException
- Parameters are invalidpublic static java.lang.Object prependToArray(java.lang.Object array, java.lang.Object newval)
System.arraycopy()
calls).
array
- Target array of arbitrary typenewval
- Element to add, may be null
java.lang.IllegalArgumentException
- Parameters are invalidpublic static boolean elementOf(java.lang.Object object, java.lang.Object array)
object
- The object to be checkedarray
- The array to check againstjava.lang.NullPointerException
- If object and/or array is null
public static java.lang.Class mapToPrimitive(java.lang.Class clazz)
Integer
-> int
).
The types boolean, byte, char, short, int, long, float, double, and void are supported.
clazz
- Class to be mappedclazz
if not availablepublic static java.lang.String getMethod(boolean full)
full
- Print full class info?public static boolean isWindows()
public static boolean isMacOSX()
public static boolean isLinux()
public static boolean isSolaris()
public static boolean isWebStart()
public static boolean isInstalled()
public static boolean isDevelopment()
public static java.lang.String convertToHex(byte b, boolean uppercase)
b
- Data to be converteduppercase
- Use uppercase hex characters, lowercase if false
public static java.lang.String convertToHex(byte[] rawdata, boolean uppercase)
rawdata
- The binary data to be transformeduppercase
- Use uppercase hex characters, lowercase if false
public static java.lang.String convertToHex(byte[] rawdata, boolean uppercase, boolean spaces)
rawdata
- The binary data to be transformeduppercase
- Use uppercase hex characters, lowercase if false
spaces
- Insert SPACEs between hex valuespublic static byte[] convertToBytes(java.lang.String hexdata)
hexdata
- The hexadecimal data to be transformednull
if hex value is invalidjava.lang.NullPointerException
- If parameter is invalidpublic static long parseTotalBytes(java.lang.String raw)
raw
- String like "10M" to be parsedjava.lang.NullPointerException
- If parameter is null
java.lang.IllegalArgumentException
- If parameter does not apply to regexpublic static boolean canRestart()
public static void restartJNLP(java.io.File tempjnlp, java.lang.String restartURL)
javaws
executable if available.
tempjnlp
- The temporary file for the JNLP downloadrestartURL
- Restart with this URL (e.g. Web Start), may be null
public static void restartInstaller()
public static java.lang.String formatNumber(long number)
number
- The number to be formattedpublic static java.util.Vector<Locale> getWebStartLocales()
locales
system property added optionally by Web Start.
null
if not setpublic static boolean isMethodCalled(java.lang.Class clazz, java.lang.String method)
isMethodCalled()
method without method parameter then (class check only).
clazz
- Class reference for searchmethod
- Method name for the searchpublic static boolean isMethodCalled(java.lang.Class clazz)
clazz
- Class reference for searchpublic static java.io.File changeInstallerMaxMem(int maxmem)
maxmem
- Memory size in megabytesnull
= successpublic static void runWebStart(java.lang.String params)
params
- Parameters for the javaws executable (optional)public static boolean isInteger(java.lang.String value)
value
- Value to be parsedpublic static boolean isLong(java.lang.String value)
Long
value or not.
value
- Value to be parsedpublic static void browse(java.lang.String uri)
uri
- Uniform resource identifierpublic static java.lang.Object findKey(java.util.Hashtable container, java.lang.Object value)
container
- The containervalue
- Value to be searchednull
public static boolean equalsNull(java.lang.Object obj1, java.lang.Object obj2)
equals()
which may be null
.
Returns true
only if the objects are equal or both null
.
obj1
- First object to be comparedobj2
- Second object to be comparedpublic static <T> void moveUp(java.util.Vector<T> container, T element)
container
- The containerelement
- The element to be movedjava.lang.NullPointerException
- If a parameter is null
public static <T> void moveDown(java.util.Vector<T> container, T element)
container
- The containerelement
- The element to be movedjava.lang.NullPointerException
- If a parameter is null
public static java.lang.Object minimizeArray(java.lang.Object array)
null
elements of the given array are eliminated.
array
- Target array of arbitrary typejava.lang.IllegalArgumentException
- Parameters are invalidpublic static <T> T[] convertToArray(java.util.Vector<T> container, T[] array)
Vector
to an array representation.
There's currently no way to create generic arrays so it must be passed here.
container
- The vector to be convertedarray
- The array to be filled, same length as vectorjava.lang.NullPointerException
- If a parameter is null
java.lang.IndexOutOfBoundsException
- If the container has not the same size than the arraypublic static <T> java.util.Vector<T> convertToVector(T[] array)
Vector
representation.
array
- The array to be convertedjava.lang.NullPointerException
- If a parameter is null
public static boolean checkJavaVersion(java.lang.String regex)
regex
- The version pattern like "(^1[\.]6$)"public static java.lang.String printStackTrace(java.lang.Exception exc, java.lang.String encoding)
System.out
.
exc
- The exception to printencoding
- The charset like "UTF-8"null
indicates errorpublic static int indexOf(java.lang.Object object, java.lang.Object array)
object
- The object to be checkedarray
- The array to check againstjava.lang.NullPointerException
- If object and/or array is null
public static java.lang.Object subarray(java.lang.Object array, int beginindex, int endindex)
array
- Target array of arbitrary typebeginindex
- The first index to copyendindex
- The end index, copied to endindex-1java.lang.IllegalArgumentException
- Parameters are invalidpublic static boolean vectorEquals(java.util.Vector v1, java.util.Vector v2)
true
only if the given containers are exactly of the same type and
size and additionally hold the same elements (equals).
v1
- The first container to be comparedv2
- The second container to be comparedjava.lang.NullPointerException
- If v1 and/or v2 is null
public static void uninstallInstaller(java.lang.String regex)
regex
- The regex to detect the uninstaller executableCopyright © 2005-2023 Leisenfels GmbH. All rights reserved.