public class SUtil extends Object
Modifier and Type | Class and Description |
---|---|
static class |
SUtil.AccessiblePrintStream
An subclass of print stream to allow accessing the underlying stream.
|
Modifier and Type | Field and Description |
---|---|
static String[] |
BYTE_UNITS
Units for representing byte values.
|
static DecimalFormat |
BYTEFORMATTER1
The byte formatter for one predecimal digit.
|
static DecimalFormat |
BYTEFORMATTER2
The byte formatter for two predecimal digits.
|
static 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.
|
static Class[] |
EMPTY_CLASS_ARRAY
An empty class array.
|
static Enumeration |
EMPTY_ENUMERATION
An empty enumeration.
|
static String[] |
EMPTY_STRING_ARRAY
An empty string array.
|
static String |
LF
Line separator.
|
static String |
NULL
A Null value.
|
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 boolean |
arrayContains(Object array,
Object value)
Check if an element is contained in an array.
|
static boolean |
arrayEquals(Object array1,
Object array2)
Test if two arrays are content equal or both null.
|
static int |
arrayHashCode(Object a)
Calculate a hash code for an array.
|
static <T> List<T> |
arrayToList(Object a)
Transform an array to a vector.
|
static <T> Set<T> |
arrayToSet(Object a)
Transform an array to a vector.
|
static String |
arrayToString(Object array)
Get a string representation for an array.
|
static int |
bytesToInt(byte[] buffer)
Convert bytes to an integer.
|
static long |
bytesToLong(byte[] buffer)
Convert bytes to an integer.
|
static String |
bytesToString(long bytes)
Get bytes as human readable string.
|
static List |
calculateCartesianProduct(String[] names,
Object[] values)
Calculate the cartesian product of parameters.
|
static int |
compareTo(String a,
String b)
Compares two strings, ignoring case.
|
static String |
convertPathToPackage(String path,
URL[] urls)
Find a package name from a path.
|
static String |
convertPathToRelative(String absolute)
Convert an absolute path to a relative path based on the current user
directory.
|
static String |
convertURLToString(URL url)
Convert an URL to a local file name.
|
static void |
copyFile(File source,
File target)
Copy a file.
|
static int |
countOccurrences(String string,
char find)
Count the occurrences of a char in a string.
|
static <T> List<T> |
createArrayList(T[] values)
Create an array list from values.
|
static <K,T> Map<K,T> |
createHashMap(K[] keys,
T[] values)
Create a hash map from keys and values.
|
static Set<Object> |
createHashSet(Object[] values)
Create a hash set from values.
|
static String |
createUniqueId(String name)
Create a globally unique conversation id.
|
static String |
createUniqueId(String name,
int length)
Create a globally unique conversation id.
|
static Object |
cutArrays(Object a1,
Object a2)
Cut two arrays.
|
static boolean |
deleteDirectory(File dir)
Delete a directory completely (including all subdirs and files).
|
static boolean |
equals(Object val1,
Object val2) |
static String |
escapeString(String str)
Escape a java string.
|
static int |
getArrayDimension(Object array)
Get the array dimension.
|
static String |
getCodeSource(String filename,
String pck)
Get the source code base using a packagename and a filename.
|
static String |
getDisplayName(File file)
Get the display name (e.g. of a system drive).
|
static String |
getDurationHMS(long ms)
Get a string representation for a duration.
|
static InetAddress |
getInet4Address()
Get a IPV4 address of the local host.
|
static InetAddress |
getInet6Address()
Get a IPV4 address of the local host.
|
static InetAddress |
getInetAddress()
Get an address of the local host.
|
static String[] |
getNetworkAddresses()
Get the addresses to be used for transports.
|
static List<NetworkInterface> |
getNetworkInterfaces()
Get the network interfaces.
|
static InetAddress |
getNetworkIp(InetAddress addr,
short prefixlen)
Get the network ip for an internet address and the prefix length.
|
static short |
getNetworkPrefixLength(InetAddress iadr)
Get the network prefix length for IPV4 address
24=C, 16=B, 8=A classes.
|
static OutputStream |
getOutForSystemIn(IThreadPool tp)
Get an output stream that is automatically fed into the new System.in,
i.e. this method replaces System.in and delivers an output stream to
which can be written.
|
static String |
getPlural(String s)
Get the plural of a word in singular.
|
static InputStream |
getResource(String name,
ClassLoader classloader)
Get an input stream for whatever provided. 1.
|
static InputStream |
getResource0(String name,
ClassLoader classloader)
Get an input stream for whatever provided. 1.
|
static ResourceInfo |
getResourceInfo0(String name,
ClassLoader classloader)
Get an input stream for whatever provided. 1.
|
static String |
getSingular(String s)
Get the singular of a word in plural.
|
static String |
getStackTrace(Exception e)
Get the exception stack trace as string.
|
static String[] |
getStringArray(String key,
Properties props)
Get a string array of properties that are separated by commas.
|
static String |
hex(char ch)
Convert char to hex vavlue.
|
static int |
indexOfFilename(String url,
List<String> urlstrings)
Test if a file name is contained.
|
static byte[] |
intToBytes(int val)
Convert an integer to bytes.
|
static boolean |
isFloppyDrive(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(Date date,
Date start,
Date end)
Test if the date is in the range.
|
static boolean |
isJavaSourceFilename(String filename)
Test if a file is a Java source file.
|
static Object[] |
iteratorToArray(Iterator it,
Class clazz)
Transform an iterator to an array.
|
static List |
iteratorToList(Iterator it)
Transform an iterator to a list.
|
static List |
iteratorToList(Iterator it,
List ret)
Transform an iterator to a list.
|
static Object[] |
joinArbitraryArrays(Object[] as)
Joins any arrays of (possibly) different type. todo: Does not support
basic types yet.
|
static Object |
joinArrays(Object a1,
Object a2)
Joins two arrays of the same type.
|
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(String[] args)
Main method for testing.
|
static String |
makeConform(String input)
Convert an output to html/wml conform presentation.
|
static String |
makeConform(String input,
int flag)
Convert an output to html/wml conform presentation.
|
static String |
makeEnglishConform(String input)
Convert an output readable in english.
|
static String |
removeExtension(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(String source,
StringBuffer dest,
String old,
String newstring)
Parse a source string replacing occurrences and storing the result in the
given string buffer.
|
static String |
replace(String source,
String old,
String newstring)
Parse a source string replacing occurrences and returning the result.
|
static String[] |
splitCommandline(String line)
Taken from ant.
|
static String |
stripTags(String source)
Strip tags (e.g. html) from a string, leaving only the text content.
|
static Object |
substractArrays(Object a1,
Object a2)
First array minus second array.
|
static URL |
toURL(Object url)
Convert a file/string/url.
|
static URL[] |
toURLs(Object[] urls)
Convert a file/string/url array.
|
static void |
unzip(ZipFile zip,
File dir)
Unzip a file into a specific dir.
|
static File |
urlToFile(String url)
Convert an URL to a file.
|
static String |
wrapText(String text)
Wrap a text at a given line length.
|
static String |
wrapText(String text,
int wrap)
Wrap a text at a given line length.
|
public static final String LF
public static final String[] BYTE_UNITS
public static final DecimalFormat BYTEFORMATTER1
public static final DecimalFormat BYTEFORMATTER2
public static final 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 String NULL
public static final Enumeration EMPTY_ENUMERATION
public static final String[] EMPTY_STRING_ARRAY
public static final Class[] EMPTY_CLASS_ARRAY
public static final int SORT_UP
public static final int SORT_DOWN
public static String[] getStringArray(String key, Properties props)
key
- The key.props
- The properties.public static Object joinArrays(Object a1, Object a2)
a1
- The first array.a2
- The second array.public static Object[] joinArbitraryArrays(Object[] as)
as
- The array of arrays to join..public static Object cutArrays(Object a1, Object a2)
a1
- The first array.a2
- The second array.public static Object substractArrays(Object a1, Object a2)
a1
- The first array.a2
- The second array.public static <T> List<T> arrayToList(Object a)
a
- The array.public static <T> Set<T> arrayToSet(Object a)
a
- The array.public static List iteratorToList(Iterator it, List ret)
public static Object[] iteratorToArray(Iterator it, Class clazz)
public static boolean arrayContains(Object array, Object value)
array
- The array.value
- The value.public static int getArrayDimension(Object array)
array
- The array.public static boolean arrayEquals(Object array1, Object array2)
array1
- The first array.array2
- The second array.public static int arrayHashCode(Object a)
public static String arrayToString(Object array)
array
- The array.public static String getSingular(String s)
s
- The plural word.public static String getPlural(String s)
s
- The word.public static int compareTo(String a, String b)
a
- The first string.b
- The second string.public static boolean isInRange(Date date, Date start, Date end)
date
- The date.start
- The start.end
- The end.public static String removeExtension(String fn)
fn
- The filename..public static String wrapText(String text)
text
- The text to wrap.public static String wrapText(String text, int wrap)
text
- The text to wrap.wrap
- The column width.public static String makeConform(String input)
input
- The input string.public static String makeConform(String input, int flag)
input
- The input string.flag
- CONVERT_ALL, CONVERT_NONE, CONVERT_ALL_EXCEPT_AMP;public static String stripTags(String source)
public static String makeEnglishConform(String input)
input
- The input string.public static void replace(String source, StringBuffer dest, String old, 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 String replace(String source, String old, String newstring)
source
- The source string.old
- The string to replace.newstring
- The string to use as replacement.public static InputStream getResource(String name, ClassLoader classloader) throws IOException
name
- The resource description.IOException
- when the resource was not found.public static InputStream getResource0(String name, ClassLoader classloader)
name
- The resource description.public static ResourceInfo getResourceInfo0(String name, ClassLoader classloader)
name
- The resource description.public static String getDurationHMS(long ms)
ms
- The duration in ms.public static String convertPathToPackage(String path, URL[] urls)
path
- The directory.public static List calculateCartesianProduct(String[] names, Object[] values)
names
- The names.values
- The values (must be some form of collection, i.e. array,
list, iterator etc.)public static boolean isJavaSourceFilename(String filename)
filename
- The filename.public static <K,T> Map<K,T> createHashMap(K[] keys, T[] values)
keys
- The keys.values
- The values.public static Set<Object> createHashSet(Object[] values)
values
- The values.public static <T> List<T> createArrayList(T[] values)
values
- The values.public static String createUniqueId(String name)
public static String createUniqueId(String name, int length)
public static String convertPathToRelative(String absolute)
public static URL[] toURLs(Object[] urls)
urls
- The url strings.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 InetAddress getNetworkIp(InetAddress addr, short prefixlen)
addr
- The internet address.prefixlen
- The prefix length.public static String bytesToString(long bytes)
public static String convertURLToString(URL url)
url
- The url.public static int indexOfFilename(String url, List<String> urlstrings)
public static File urlToFile(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 OutputStream getOutForSystemIn(IThreadPool tp) throws IOException
tp
- The thread pool.IOException
public static InetAddress getInet4Address()
public static InetAddress getInet6Address()
public static InetAddress getInetAddress()
public static short getNetworkPrefixLength(InetAddress iadr)
iadr
- The address.public static String getCodeSource(String filename, String pck)
filename
- The filename.pck
- The package name.public static int countOccurrences(String string, char find)
string
- The string.find
- The char to find.public static List<NetworkInterface> getNetworkInterfaces() throws SocketException
SocketException
public static String[] getNetworkAddresses() throws SocketException
SocketException
public static void unzip(ZipFile zip, File dir)
zip
- The zip file.dir
- The target dir.public static boolean deleteDirectory(File dir)
dir
- The dir to delete.public static boolean isFloppyDrive(File file)
public static String getDisplayName(File file)
public static boolean isGuiThread()
public static String escapeString(String str)
str
- The string to escape.public static String hex(char ch)
public static String[] splitCommandline(String line)
line
- The command line to process.public static void copyFile(File source, File target) throws IOException
source
- The source file.target
- The target file or directory (will be deleted first).IOException
public static String getStackTrace(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 void main(String[] args)
Copyright © 2012. All Rights Reserved.