public class SUtil
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
SUtil.AccessiblePrintStream
An subclass of print stream to allow accessing the underlying stream.
|
static interface |
SUtil.AndroidUtils |
Modifier and Type | Field and Description |
---|---|
protected static SUtil.AndroidUtils |
androidutils
Cached AndroidUtils
|
static java.lang.String[] |
BYTE_UNITS
Units for representing byte values.
|
static java.text.DecimalFormat |
BYTEFORMATTER1
The byte formatter for one predecimal digit.
|
static java.text.DecimalFormat |
BYTEFORMATTER2
The byte formatter for two predecimal digits.
|
static java.text.DecimalFormat |
BYTEFORMATTER3
The byte formatter for three predecimal digits.
|
static int |
CONVERT_ALL
Constant that indicates a conversion of all known characters.
|
static int |
CONVERT_ALL_EXCEPT_AMP
Constant that indicates a conversion of all known characters except &.
|
static int |
CONVERT_NONE
Constant that indicates a conversion of no characters.
|
protected static long |
convidcnt
The counter for conversation ids.
|
static java.lang.Class[] |
EMPTY_CLASS_ARRAY
An empty class array.
|
static java.util.Enumeration |
EMPTY_ENUMERATION
An empty enumeration.
|
static java.lang.Object[] |
EMPTY_OBJECT_ARRAY
An empty class array.
|
static java.lang.String[] |
EMPTY_STRING_ARRAY
An empty string array.
|
protected static LRU<java.lang.String,Tuple2<java.lang.Long,java.lang.String>> |
HASHES
LRU for hashes.
|
protected static java.util.Map<java.lang.String,java.lang.String> |
htmlwraps
Mapping from single characters to encoded version for displaying on
xml-style interfaces.
|
static java.lang.String |
JADEXDIR
Directory were jadex stores files generated during runtime, to be used for later runs.
|
protected static LRU<java.lang.String,java.lang.Long> |
LASTMODS
LRU for directory modification dates.
|
static java.lang.String |
LF
Line separator.
|
static java.lang.String[] |
macs
Cached for speed.
|
protected static java.util.Map<java.lang.String,java.lang.String> |
MIMETYPES
The mime types.
|
protected static java.util.List<java.net.NetworkInterface> |
NIS
The cached network interfaces.
|
protected static long |
NISTIME
The time of the last caching of network interfaces.
|
static java.lang.String |
NULL
A Null value.
|
protected static java.io.OutputStream |
OUT_FOR_SYSTEM_IN |
protected static IResultCommand<ResourceInfo,java.net.URLConnection>[] |
RESOURCEINFO_MAPPERS |
static java.lang.ThreadLocal<java.text.DateFormat> |
SDF
Simple date format.
|
static java.lang.ThreadLocal<java.text.DateFormat> |
SDF2 |
static java.lang.ThreadLocal<java.text.DateFormat> |
SDF3 |
protected static java.lang.String |
seps
Holds the single characters.
|
static int |
SORT_DOWN
Constant for sorting down.
|
static int |
SORT_UP
Constant for sorting up.
|
Constructor and Description |
---|
SUtil() |
Modifier and Type | Method and Description |
---|---|
static void |
addSystemErrListener(IChangeListener listener)
Add a listener to System.err.
|
static void |
addSystemOutListener(IChangeListener listener)
Add a listener to System.out.
|
static SUtil.AndroidUtils |
androidUtils()
Get the AndroidUtils, if available.
|
static boolean |
arrayContains(java.lang.Object array,
java.lang.Object value)
Check if an element is contained in an array.
|
static boolean |
arrayEquals(java.lang.Object array1,
java.lang.Object array2)
Test if two arrays are content equal or both null.
|
static int |
arrayHashCode(java.lang.Object a)
Calculate a hash code for an array.
|
static <T> java.util.List<T> |
arrayToList(java.lang.Object a)
Transform an array to a vector.
|
static <T> java.util.Set<T> |
arrayToSet(java.lang.Object a)
Transform an array to a vector.
|
static java.lang.String |
arrayToString(java.lang.Object array)
Get a string representation for an array.
|
static byte[] |
base16Decode(java.lang.String data)
Decodes a Base16-encoded String and returns the data.
|
static java.lang.String |
base16Encode(byte[] data)
Encodes a set of data as a Base16 String (hex).
|
static java.lang.String |
beanToString(java.lang.Object bean,
java.lang.ClassLoader cl)
Converts a bean to a string.
|
static int |
bytesToInt(byte[] buffer)
Convert bytes to an integer.
|
static long |
bytesToLong(byte[] buffer)
Convert bytes to an integer.
|
static short |
bytesToShort(byte[] buffer)
Convert bytes to a short.
|
static java.lang.String |
bytesToString(long bytes)
Get bytes as human readable string.
|
static <T,E> java.util.List<java.util.Map<T,E>> |
calculateCartesianProduct(T[] names,
E[] values)
Calculate the cartesian product of parameters.
|
static java.util.Set<java.net.URL> |
collectClasspathURLs(java.lang.ClassLoader baseloader)
Get other contained (but not directly managed) urls from parent classloaders.
|
protected static void |
collectClasspathURLs(java.lang.ClassLoader classloader,
java.util.Set<java.net.URL> set,
java.util.Set<java.lang.String> jarnames)
Collect all URLs belonging to a class loader.
|
static void |
collectManifestURLs(java.net.URL url,
java.util.Set<java.net.URL> set,
java.util.Set<java.lang.String> jarnames)
Collect all URLs as specified in a manifest.
|
static int |
compareTo(java.lang.String a,
java.lang.String b)
Compares two strings, ignoring case.
|
static byte[] |
computeFileHash(java.lang.String filename)
Compute a file hash.
|
static byte[] |
computeFileHash(java.lang.String filename,
java.lang.String algorithm)
Compute a file hash.
|
static boolean |
containsDigit(java.lang.String s)
Test if a string contains a digit.
|
static java.lang.String |
convertPathToPackage(java.lang.String path,
java.net.URL[] urls)
Find a package name from a path.
|
static java.lang.String |
convertPathToRelative(java.lang.String absolute)
Convert an absolute path to a relative path based on the current user
directory.
|
static java.lang.String |
convertURLToString(java.net.URL url)
Convert an URL to a local file name.
|
static <T> T[] |
copyArray(T[] original)
Copy an array.
|
static void |
copyFile(java.io.File source,
java.io.File target)
Copy a file.
|
static void |
copyStream(java.io.InputStream is,
java.io.OutputStream os)
Copy all data from input to output stream.
|
static int |
countOccurrences(java.lang.String string,
char find)
Count the occurrences of a char in a string.
|
static <T> java.util.List<T> |
createArrayList(T[] values)
Create an array list from values.
|
static <K,T> java.util.Map<K,T> |
createHashMap(K[] keys,
T[] values)
Create a hash map from keys and values.
|
static <T> java.util.Set<T> |
createHashSet(T[] values)
Create a hash set from values.
|
static java.util.regex.Pattern |
createRegexFromGlob(java.lang.String glob)
Create a regex from a normal bnf pattern.
|
static java.lang.String |
createUniqueId(java.lang.String name)
Create a globally unique conversation id.
|
static java.lang.String |
createUniqueId(java.lang.String name,
int length)
Create a globally unique conversation id.
|
static java.lang.Object |
cutArrays(java.lang.Object a1,
java.lang.Object a2)
Cut two arrays.
|
static boolean |
deleteDirectory(java.io.File dir)
Delete a directory completely (including all subdirs and files).
|
static boolean |
equals(java.lang.Object val1,
java.lang.Object val2) |
static java.lang.String |
escapeString(java.lang.String str)
Escape a java string.
|
static java.io.File[] |
findOutputDirs(java.lang.String projectroot)
Try to find the correct classpath root directories for current build tool chain.
|
static java.lang.String |
firstToUpperCase(java.lang.String str)
Convert a string to the same string with first
letter in upper case.
|
static java.lang.String |
formatByteSize(long bytes)
Converts a number of bytes
into a human-friendly binary prefix unit string
(kiB, MiB, GiB, ...).
|
static int |
getArrayDimension(java.lang.Object array)
Get the array dimension.
|
static java.util.List<java.net.URL> |
getClasspathURLs(java.lang.ClassLoader classloader,
boolean includebootpath)
Get the current classpath as a list of URLs
|
static java.lang.String |
getCodeSource(java.lang.String filename,
java.lang.String pck)
Get the source code base using a packagename and a filename.
|
static java.io.File |
getDefaultDirectory()
Get the home directory.
|
static java.lang.String |
getDisplayName(java.io.File file)
Get the display name (e.g.
|
static java.lang.String |
getDurationHMS(long ms)
Get a string representation for a duration.
|
static java.lang.String |
getExceptionStacktrace(java.lang.Exception e)
Get the exception stacktrace.
|
protected static int |
getExtremeElementIndex(java.util.Vector source,
int direction)
Remove the least element form a collection.
|
static java.io.File |
getFile(java.net.URL url)
Get the file from an URL.
|
static java.io.File[] |
getFiles(java.io.File file,
boolean hiding)
Get the files of a directory.
|
static java.lang.String |
getHashCode(java.io.File f)
Get the hash code for a file or directory.
|
static java.io.File |
getHomeDirectory()
Get the home directory.
|
static java.net.InetAddress |
getInet4Address()
Get a IPV4 address of the local host.
|
static java.net.InetAddress |
getInet6Address()
Get a IPV4 address of the local host.
|
static java.net.InetAddress |
getInetAddress()
Get an address of the local host.
|
static java.lang.String |
getJarName(java.lang.String filename)
Get the name of a jar file without extension and version info.
|
static long |
getLastModified(java.io.File f)
Recursively get the newest last modified of a file or directory tree.
|
static long |
getLastModified(java.io.File f,
boolean nocache)
Recursively get the newest last modified of a file or directory tree.
|
static java.lang.String |
getMacAddress()
Get the mac address.
|
static java.lang.String[] |
getMacAddresses()
Get the mac address.
|
static java.lang.String[] |
getNetworkAddresses()
Get the addresses to be used for transports.
|
static java.util.List<java.net.NetworkInterface> |
getNetworkInterfaces()
Get the network interfaces.
|
static java.net.InetAddress |
getNetworkIp(java.net.InetAddress addr,
short prefixlen)
Get the network ip for an internet address and the prefix length.
|
static short |
getNetworkPrefixLength(java.net.InetAddress iadr)
Get the network prefix length for IPV4 address
24=C, 16=B, 8=A classes.
|
static java.io.OutputStream |
getOutForSystemIn()
Get an output stream that is automatically fed into the new System.in,
i.e.
|
static java.lang.String |
getOutputDirsExpression(java.lang.String projectroot)
Try to find the correct classpath root directories for current build tool chain.
|
static java.io.File |
getParentDirectory(java.io.File file)
Get the parent directory.
|
static java.lang.String |
getPlural(java.lang.String s)
Get the plural of a word in singular.
|
static int |
getPrefixLength(java.io.File file)
Get the prefix length of a file.
|
static java.io.InputStream |
getResource(java.lang.String name,
java.lang.ClassLoader classloader)
Get an input stream for whatever provided.
|
static java.io.InputStream |
getResource0(java.lang.String name,
java.lang.ClassLoader classloader)
Get an input stream for whatever provided.
|
static ResourceInfo |
getResourceInfo0(java.lang.String name,
java.lang.ClassLoader classloader)
Get an input stream for whatever provided.
|
static java.lang.String |
getSingular(java.lang.String s)
Get the singular of a word in plural.
|
static java.lang.String |
getStackTrace(java.lang.Exception e)
Get the exception stack trace as string.
|
static java.lang.String[] |
getStringArray(java.lang.String key,
java.util.Properties props)
Get a string array of properties that are separated by commas.
|
static java.lang.String |
guessContentTypeByFilename(java.lang.String name)
Guess the mime type by the file name.
|
protected static void |
hashDirectory(java.lang.String root,
java.io.File dir,
java.security.MessageDigest md)
Get the hash code of a directory recursively.
|
protected static void |
hashStream(java.io.InputStream is,
java.security.MessageDigest md) |
static java.lang.String |
hex(byte[] data)
Convert a byte array to a string representation.
|
static java.lang.String |
hex(byte[] data,
boolean uppercase)
Convert a byte array to a string representation.
|
static java.lang.String |
hex(byte[] data,
java.lang.String delim,
int block)
Convert a byte array to a string representation.
|
static java.lang.String |
hex(byte[] data,
java.lang.String delim,
int block,
boolean uppercase)
Convert a byte array to a string representation.
|
static java.lang.String |
hex(char ch)
Convert char to hex vavlue.
|
static int |
indexOfFilename(java.lang.String url,
java.util.List<java.lang.String> urlstrings)
Test if a file name is contained.
|
static byte[] |
intToBytes(int val)
Convert an integer to bytes.
|
static boolean |
isFloppyDrive(java.io.File file)
Check if a file represents a floppy.
|
static boolean |
isGuiThread()
Test if a call is running on a gui (e.g.
|
static boolean |
isInRange(java.util.Date date,
java.util.Date start,
java.util.Date end)
Test if the date is in the range.
|
static boolean |
isJavaSourceFilename(java.lang.String filename)
Test if a file is a Java source file.
|
static boolean |
isUTF8(byte[] bytes)
Test if starts with UTF-8 BOM.
|
static java.lang.Object[] |
iteratorToArray(java.util.Iterator it,
java.lang.Class clazz)
Transform an iterator to an array.
|
static java.util.List |
iteratorToList(java.util.Iterator it)
Transform an iterator to a list.
|
static java.util.List |
iteratorToList(java.util.Iterator it,
java.util.List ret)
Transform an iterator to a list.
|
static <T> T[] |
joinArbitraryArrays(java.lang.Object[] as)
Joins any arrays of (possibly) different type.
|
static java.lang.Object |
joinArrays(java.lang.Object a1,
java.lang.Object a2)
Joins two arrays of the same type.
|
static java.lang.String |
loadBinary(java.lang.String file)
Load a binary file as base 64 string, e.g.
|
protected static LRU<java.lang.String,Tuple2<java.lang.Long,java.lang.String>> |
loadHashCache()
Load the stored hashes.
|
static int |
log2(int num)
Fast way to compute log2(x).
|
static int |
log2(long num)
Fast way to compute log2(x).
|
static byte[] |
longToBytes(long val)
Convert an integer to bytes.
|
static void |
main(java.lang.String[] args)
Main method for testing.
|
static java.lang.String |
makeConform(java.lang.String input)
Convert an output to html/wml conform presentation.
|
static java.lang.String |
makeConform(java.lang.String input,
int flag)
Convert an output to html/wml conform presentation.
|
static java.lang.String |
makeEnglishConform(java.lang.String input)
Convert an output readable in english.
|
static void |
moveFile(java.io.File source,
java.io.File target)
Moves a file to a target location.
|
static byte[] |
readFile(java.io.File file)
Reads a file into memory (byte array).
|
static java.lang.String |
readFile(java.lang.String filename)
Read a file to string.
|
static byte[] |
readStream(java.io.InputStream is)
Reads an input stream into memory (byte array).
|
static java.lang.String |
removeBOM(java.lang.String text)
Remove BOM from UTF text.
|
static java.lang.String |
removeExtension(java.lang.String fn)
Remove file extension.
|
static void |
removeSystemErrListener(IChangeListener listener)
Remove a listener from System.err.
|
static void |
removeSystemOutListener(IChangeListener listener)
Remove a listener from System.out.
|
static void |
replace(java.lang.String source,
java.lang.StringBuffer dest,
java.lang.String old,
java.lang.String newstring)
Parse a source string replacing occurrences and storing the result in the
given string buffer.
|
static java.lang.String |
replace(java.lang.String source,
java.lang.String old,
java.lang.String newstring)
Parse a source string replacing occurrences and returning the result.
|
static void |
rethrowAsUnchecked(java.lang.Throwable e)
Re-throws a throwable as a RuntimeException.
|
static <T> java.util.Collection<T> |
safeCollection(java.util.Collection<T> coll)
Helper method to allow iterating over possibly null collections.
|
static <T> java.util.List<T> |
safeList(java.util.List<T> list)
Helper method to allow iterating over possibly null lists.
|
static <K,E> java.util.Map<K,E> |
safeMap(java.util.Map<K,E> map)
Helper method to allow iterating over possibly null maps.
|
static <T> java.util.Set<T> |
safeSet(java.util.Set<T> set)
Helper method to allow iterating over possibly null sets.
|
protected static void |
saveHashCache()
Save the caclulated hashes.
|
static byte[] |
shortToBytes(int val)
Convert a short to bytes.
|
static void |
sleep(long millis)
Sleep the current thread, ignore exceptions.
|
static java.lang.String[] |
splitCommandline(java.lang.String line)
Taken from ant.
|
static java.lang.String |
stripTags(java.lang.String source)
Strip tags (e.g.
|
static java.lang.Object |
substractArrays(java.lang.Object a1,
java.lang.Object a2)
First array minus second array.
|
protected static void |
testIntByteConversion() |
static java.net.URI |
toURI(java.net.URL url)
Convert a URL to a URI but ignore exceptions
|
static java.net.URI |
toURI0(java.net.URL url)
Convert a URL to a URI but ignore exceptions
|
static java.net.URL |
toURL(java.lang.Object url)
Convert a file/string/url.
|
static java.net.URL |
toURL0(java.net.URI uri)
Convert a URI to a URL but ignore exceptions
|
static java.net.URL[] |
toURLs(java.lang.Object[] urls)
Convert a file/string/url array.
|
static void |
unzip(java.util.zip.ZipFile zip,
java.io.File dir)
Unzip a file into a specific dir.
|
static java.io.File |
urlToFile(java.lang.String url)
Convert an URL to a file.
|
static java.lang.String |
wrapText(java.lang.String text)
Wrap a text at a given line length.
|
static java.lang.String |
wrapText(java.lang.String text,
int wrap)
Wrap a text at a given line length.
|
static void |
writeDirectory(java.io.File dir,
java.io.OutputStream out)
Write a directory as jar to an output stream.
|
protected static void |
writeDirectory(java.lang.String prefix,
java.io.File dir,
java.util.zip.ZipOutputStream zos,
byte[] buf)
Write a directory as jar to an output stream.
|
static void |
writeFile(java.lang.String val,
java.lang.String filename)
Write a string to a file.
|
static void |
writeFile(java.lang.String val,
java.lang.String filename,
java.lang.String charset)
Write a string to a file.
|
public static final java.lang.String JADEXDIR
public static final java.lang.String LF
public static final java.lang.String[] BYTE_UNITS
public static final java.text.DecimalFormat BYTEFORMATTER1
public static final java.text.DecimalFormat BYTEFORMATTER2
public static final java.text.DecimalFormat BYTEFORMATTER3
public static final int CONVERT_ALL
public static final int CONVERT_ALL_EXCEPT_AMP
public static final int CONVERT_NONE
public static final java.lang.String NULL
protected static volatile java.util.Map<java.lang.String,java.lang.String> MIMETYPES
public static final java.lang.ThreadLocal<java.text.DateFormat> SDF
public static final java.lang.ThreadLocal<java.text.DateFormat> SDF2
public static final java.lang.ThreadLocal<java.text.DateFormat> SDF3
protected static final java.util.Map<java.lang.String,java.lang.String> htmlwraps
protected static volatile SUtil.AndroidUtils androidutils
protected static final java.lang.String seps
public static final java.util.Enumeration EMPTY_ENUMERATION
public static final java.lang.String[] EMPTY_STRING_ARRAY
public static final java.lang.Class[] EMPTY_CLASS_ARRAY
public static final java.lang.Object[] EMPTY_OBJECT_ARRAY
protected static final IResultCommand<ResourceInfo,java.net.URLConnection>[] RESOURCEINFO_MAPPERS
public static final int SORT_UP
public static final int SORT_DOWN
protected static long convidcnt
protected static java.io.OutputStream OUT_FOR_SYSTEM_IN
protected static volatile java.util.List<java.net.NetworkInterface> NIS
protected static long NISTIME
public static volatile java.lang.String[] macs
protected static LRU<java.lang.String,Tuple2<java.lang.Long,java.lang.String>> HASHES
protected static LRU<java.lang.String,java.lang.Long> LASTMODS
public static java.lang.String[] getStringArray(java.lang.String key, java.util.Properties props)
key
- The key.props
- The properties.public static java.lang.Object joinArrays(java.lang.Object a1, java.lang.Object a2)
a1
- The first array.a2
- The second array.public static <T> T[] joinArbitraryArrays(java.lang.Object[] as)
as
- The array of arrays to join..public static java.lang.Object cutArrays(java.lang.Object a1, java.lang.Object a2)
a1
- The first array.a2
- The second array.public static java.lang.Object substractArrays(java.lang.Object a1, java.lang.Object a2)
a1
- The first array.a2
- The second array.public static <T> java.util.List<T> arrayToList(java.lang.Object a)
a
- The array.public static <T> java.util.Set<T> arrayToSet(java.lang.Object a)
a
- The array.public static java.util.List iteratorToList(java.util.Iterator it)
public static java.util.List iteratorToList(java.util.Iterator it, java.util.List ret)
public static java.lang.Object[] iteratorToArray(java.util.Iterator it, java.lang.Class clazz)
public static boolean arrayContains(java.lang.Object array, java.lang.Object value)
array
- The array.value
- The value.public static int getArrayDimension(java.lang.Object array)
array
- The array.public static boolean equals(java.lang.Object val1, java.lang.Object val2)
public static boolean arrayEquals(java.lang.Object array1, java.lang.Object array2)
array1
- The first array.array2
- The second array.public static int arrayHashCode(java.lang.Object a)
public static java.lang.String arrayToString(java.lang.Object array)
array
- The array.public static java.lang.String getSingular(java.lang.String s)
s
- The plural word.public static java.lang.String getPlural(java.lang.String s)
s
- The word.public static int compareTo(java.lang.String a, java.lang.String b)
a
- The first string.b
- The second string.public static boolean isInRange(java.util.Date date, java.util.Date start, java.util.Date end)
date
- The date.start
- The start.end
- The end.public static java.lang.String removeExtension(java.lang.String fn)
fn
- The filename..public static java.lang.String wrapText(java.lang.String text)
text
- The text to wrap.public static java.lang.String wrapText(java.lang.String text, int wrap)
text
- The text to wrap.wrap
- The column width.protected static int getExtremeElementIndex(java.util.Vector source, int direction)
public static java.lang.String makeConform(java.lang.String input)
input
- The input string.public static java.lang.String makeConform(java.lang.String input, int flag)
input
- The input string.flag
- CONVERT_ALL, CONVERT_NONE, CONVERT_ALL_EXCEPT_AMP;public static java.lang.String stripTags(java.lang.String source)
public static java.lang.String makeEnglishConform(java.lang.String input)
input
- The input string.public static void replace(java.lang.String source, java.lang.StringBuffer dest, java.lang.String old, java.lang.String newstring)
source
- The source string.dest
- The destination string buffer.old
- The string to replace.newstring
- The string to use as replacement.public static java.lang.String replace(java.lang.String source, java.lang.String old, java.lang.String newstring)
source
- The source string.old
- The string to replace.newstring
- The string to use as replacement.public static java.io.InputStream getResource(java.lang.String name, java.lang.ClassLoader classloader) throws java.io.IOException
name
- The resource description.java.io.IOException
- when the resource was not found.public static java.io.InputStream getResource0(java.lang.String name, java.lang.ClassLoader classloader)
name
- The resource description.public static ResourceInfo getResourceInfo0(java.lang.String name, java.lang.ClassLoader classloader)
name
- The resource description.public static void copyStream(java.io.InputStream is, java.io.OutputStream os)
public static java.lang.String getDurationHMS(long ms)
ms
- The duration in ms.public static java.lang.String convertPathToPackage(java.lang.String path, java.net.URL[] urls)
path
- The directory.public static java.util.List<java.net.URL> getClasspathURLs(java.lang.ClassLoader classloader, boolean includebootpath)
public static java.util.Set<java.net.URL> collectClasspathURLs(java.lang.ClassLoader baseloader)
protected static void collectClasspathURLs(java.lang.ClassLoader classloader, java.util.Set<java.net.URL> set, java.util.Set<java.lang.String> jarnames)
public static java.lang.String getJarName(java.lang.String filename)
public static void collectManifestURLs(java.net.URL url, java.util.Set<java.net.URL> set, java.util.Set<java.lang.String> jarnames)
public static <T,E> java.util.List<java.util.Map<T,E>> calculateCartesianProduct(T[] names, E[] values)
names
- The names.values
- The values (must be some form of collection, i.e. array,
list, iterator etc.)public static boolean isJavaSourceFilename(java.lang.String filename)
filename
- The filename.public static <K,T> java.util.Map<K,T> createHashMap(K[] keys, T[] values)
keys
- The keys.values
- The values.public static <T> java.util.Set<T> createHashSet(T[] values)
values
- The values.public static <T> java.util.List<T> createArrayList(T[] values)
values
- The values.public static java.lang.String createUniqueId(java.lang.String name)
public static java.lang.String createUniqueId(java.lang.String name, int length)
protected static void testIntByteConversion()
public static java.lang.String convertPathToRelative(java.lang.String absolute)
public static java.net.URL[] toURLs(java.lang.Object[] urls)
urls
- The url strings.public static java.net.URL toURL(java.lang.Object url)
public static java.net.URL toURL0(java.net.URI uri)
public static java.net.URI toURI0(java.net.URL url)
public static java.net.URI toURI(java.net.URL url)
public static final void sleep(long millis)
millis
- Time to sleep in millisecondspublic static final void rethrowAsUnchecked(java.lang.Throwable e)
e
- The throwable to be thrown as RuntimeExceptionpublic static void main(java.lang.String[] args)
public static java.lang.String formatByteSize(long bytes)
bytes
- Number of bytes.public static short bytesToShort(byte[] buffer)
public static byte[] shortToBytes(int val)
public static int bytesToInt(byte[] buffer)
public static byte[] intToBytes(int val)
public static long bytesToLong(byte[] buffer)
public static byte[] longToBytes(long val)
public static java.net.InetAddress getNetworkIp(java.net.InetAddress addr, short prefixlen)
addr
- The internet address.prefixlen
- The prefix length.public static java.lang.String bytesToString(long bytes)
public static java.lang.String convertURLToString(java.net.URL url)
url
- The url.public static int indexOfFilename(java.lang.String url, java.util.List<java.lang.String> urlstrings)
public static java.io.File urlToFile(java.lang.String url)
public static void addSystemOutListener(IChangeListener listener)
public static void removeSystemOutListener(IChangeListener listener)
public static void addSystemErrListener(IChangeListener listener)
public static void removeSystemErrListener(IChangeListener listener)
public static java.io.OutputStream getOutForSystemIn() throws java.io.IOException
java.io.IOException
public static java.net.InetAddress getInet4Address()
public static java.net.InetAddress getInet6Address()
public static java.net.InetAddress getInetAddress()
public static short getNetworkPrefixLength(java.net.InetAddress iadr)
iadr
- The address.public static <T> T[] copyArray(T[] original)
public static java.lang.String getCodeSource(java.lang.String filename, java.lang.String pck)
filename
- The filename.pck
- The package name.public static int countOccurrences(java.lang.String string, char find)
string
- The string.find
- The char to find.public static java.util.List<java.net.NetworkInterface> getNetworkInterfaces() throws java.net.SocketException
java.net.SocketException
public static java.lang.String[] getNetworkAddresses() throws java.net.SocketException
java.net.SocketException
public static void unzip(java.util.zip.ZipFile zip, java.io.File dir)
zip
- The zip file.dir
- The target dir.public static boolean deleteDirectory(java.io.File dir)
dir
- The dir to delete.public static java.io.File getHomeDirectory()
public static java.io.File getDefaultDirectory()
public static java.io.File getParentDirectory(java.io.File file)
public static java.io.File[] getFiles(java.io.File file, boolean hiding)
public static int getPrefixLength(java.io.File file)
public static boolean isFloppyDrive(java.io.File file)
public static java.lang.String getDisplayName(java.io.File file)
public static boolean isGuiThread()
public static java.lang.String escapeString(java.lang.String str)
str
- The string to escape.public static java.lang.String hex(char ch)
public static java.lang.String hex(byte[] data)
public static java.lang.String hex(byte[] data, boolean uppercase)
public static java.lang.String hex(byte[] data, java.lang.String delim, int block)
public static java.lang.String hex(byte[] data, java.lang.String delim, int block, boolean uppercase)
public static java.lang.String base16Encode(byte[] data)
data
- The data.public static byte[] base16Decode(java.lang.String data)
data
- The encoded data.public static java.lang.String[] splitCommandline(java.lang.String line)
line
- The command line to process.public static java.io.File getFile(java.net.URL url)
url
- The file URL.public static void copyFile(java.io.File source, java.io.File target) throws java.io.IOException
source
- The source file.target
- The target file or directory (will be deleted first).java.io.IOException
public static void moveFile(java.io.File source, java.io.File target) throws java.io.IOException
source
- The source file.target
- The target file location (will be deleted first, if it exists).java.io.IOException
public static byte[] readFile(java.io.File file) throws java.io.IOException
file
- The file.java.io.IOException
- Exception on IO errors.public static byte[] readStream(java.io.InputStream is) throws java.io.IOException
is
- The InputStream.java.io.IOException
- Exception on IO errors.public static java.lang.String getStackTrace(java.lang.Exception e)
e
- The exception.public static int log2(int num)
num
- The number.public static int log2(long num)
num
- The number.public static byte[] computeFileHash(java.lang.String filename)
filename
- The filename.public static byte[] computeFileHash(java.lang.String filename, java.lang.String algorithm)
filename
- The filename.algorithm
- The hash algorithm.public static java.lang.String firstToUpperCase(java.lang.String str)
str
- The string.public static java.lang.String getMacAddress()
public static java.lang.String[] getMacAddresses()
public static java.util.regex.Pattern createRegexFromGlob(java.lang.String glob)
public static java.lang.String beanToString(java.lang.Object bean, java.lang.ClassLoader cl)
bean
- The bean.cl
- The classloader.public static java.lang.String readFile(java.lang.String filename)
filename
- The file name.public static void writeFile(java.lang.String val, java.lang.String filename)
val
- The string to write.filename
- The file name.public static void writeFile(java.lang.String val, java.lang.String filename, java.lang.String charset)
val
- The string to write.filename
- The file name.public static SUtil.AndroidUtils androidUtils()
public static java.lang.String loadBinary(java.lang.String file)
public static java.lang.String removeBOM(java.lang.String text)
text
- The text.public static boolean isUTF8(byte[] bytes)
bytes
- The text.public static java.lang.String getExceptionStacktrace(java.lang.Exception e)
e
- The exception.public static java.lang.String guessContentTypeByFilename(java.lang.String name)
name
- The filenamepublic static boolean containsDigit(java.lang.String s)
s
- The string.public static java.lang.String getHashCode(java.io.File f)
protected static LRU<java.lang.String,Tuple2<java.lang.Long,java.lang.String>> loadHashCache()
protected static void saveHashCache()
public static long getLastModified(java.io.File f)
public static long getLastModified(java.io.File f, boolean nocache)
protected static void hashDirectory(java.lang.String root, java.io.File dir, java.security.MessageDigest md) throws java.lang.Exception
java.lang.Exception
protected static void hashStream(java.io.InputStream is, java.security.MessageDigest md) throws java.lang.Exception
java.lang.Exception
public static void writeDirectory(java.io.File dir, java.io.OutputStream out)
protected static void writeDirectory(java.lang.String prefix, java.io.File dir, java.util.zip.ZipOutputStream zos, byte[] buf) throws java.lang.Exception
java.lang.Exception
public static <T> java.util.List<T> safeList(java.util.List<T> list)
public static <T> java.util.Collection<T> safeCollection(java.util.Collection<T> coll)
public static <T> java.util.Set<T> safeSet(java.util.Set<T> set)
public static <K,E> java.util.Map<K,E> safeMap(java.util.Map<K,E> map)
public static java.lang.String getOutputDirsExpression(java.lang.String projectroot)
public static java.io.File[] findOutputDirs(java.lang.String projectroot)