public class Util
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
Util.Comparator<A,B>
Compare two object.
|
static class |
Util.HeaderEntry
A class that holds the parse result for one entry of a manifest header
following the general OSGi manifest header syntax.
|
Modifier and Type | Field and Description |
---|---|
protected static char |
CITCHAR
Default citation char for splitwords().
|
static java.lang.String |
FWDIR_DEFAULT |
static java.lang.String |
FWDIR_PROP
Pre OSGi 4.2 property used by KF, replaced by Constants.FRAMEWORK_STORAGE
as of OSGi R4 v4.2.
|
protected static java.lang.String |
WHITESPACE
Default whitespace string for splitwords().
|
Constructor and Description |
---|
Util() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
base64Encode(java.lang.String s) |
static <A,B> int |
binarySearch(java.util.List<A> pl,
Util.Comparator<A,B> c,
B k)
Do binary search for a package entry in the list with the same version
number add the specifies package entry.
|
static int |
compareStringVersion(java.lang.String ver1,
java.lang.String ver2)
Compare to strings formatted as '
|
static java.lang.String |
encode(byte[] in,
int len)
Encode a raw byte array to a Base64 String.
|
static void |
encode(java.io.InputStream in,
java.io.OutputStream out,
int len) |
static boolean |
filterMatch(java.lang.String filter,
java.lang.String s)
Check wild-card filter matches the string
|
static java.lang.String |
getContent(java.io.File f) |
static FileTree |
getFileStorage(FrameworkContext ctx,
java.lang.String name) |
static FileTree |
getFileStorage(FrameworkContext ctx,
java.lang.String name,
boolean create)
Check for local file storage directory.
|
static java.lang.String |
getFrameworkDir(FrameworkContext ctx) |
static java.lang.String |
getFrameworkDir(java.util.Map<java.lang.String,java.lang.String> props) |
static java.lang.reflect.Method |
getMethod(java.lang.Class<?> c,
java.lang.String name,
java.lang.Class<?>[] args)
Get method from class
|
static java.util.Set<java.lang.String> |
parseEnumeration(java.lang.String d,
java.lang.String s)
Parse strings of format:
ENTRY (, ENTRY)*
|
static java.util.List<Util.HeaderEntry> |
parseManifestHeader(java.lang.String a,
java.lang.String s,
boolean single,
boolean unique,
boolean single_entry)
Parse manifest header values on format:
|
static void |
putContent(java.io.File f,
java.lang.String content) |
static void |
putContent(java.io.File f,
java.lang.String content,
boolean useUTF8) |
static java.lang.String |
replace(java.lang.String s,
java.lang.String v1,
java.lang.String v2)
Replace all occurrences of a substring with another string.
|
static java.util.Map<java.lang.String,java.lang.Object> |
safeDTOMap(java.util.Map<java.lang.String,java.lang.Object> m) |
static java.lang.Object |
safeDTOObject(java.lang.Object val) |
static <A> void |
sort(java.util.List<A> a,
Util.Comparator<A,A> cf,
boolean bReverse)
Sort a vector with objects comparable using a comparison function.
|
static java.lang.String[] |
splitwords(java.lang.String s)
Utility method to split a string into words separated by whitespace.
|
static java.util.List<java.lang.String> |
splitWords(java.lang.String s,
char sepChar,
boolean trim)
Split a string into words separated by a separator char.
|
static java.lang.String[] |
splitwords(java.lang.String s,
java.lang.String whiteSpace)
Utility method to split a string into words separated by whitespace.
|
static java.lang.String[] |
splitwords(java.lang.String s,
java.lang.String whiteSpace,
char citChar)
Split a string into words separated by whitespace.
|
static long |
timeMillis()
Use System.nanoTime() if available, otherwise revert to
System.currentTimeMillis().
|
static boolean |
validDTOType(java.lang.Class c) |
public static final java.lang.String FWDIR_PROP
public static final java.lang.String FWDIR_DEFAULT
protected static java.lang.String WHITESPACE
protected static char CITCHAR
public static java.lang.String getFrameworkDir(java.util.Map<java.lang.String,java.lang.String> props)
public static java.lang.String getFrameworkDir(FrameworkContext ctx)
public static FileTree getFileStorage(FrameworkContext ctx, java.lang.String name, boolean create)
public static FileTree getFileStorage(FrameworkContext ctx, java.lang.String name)
public static int compareStringVersion(java.lang.String ver1, java.lang.String ver2) throws java.lang.NumberFormatException
ver1
- First version string.ver2
- Second version string.java.lang.NumberFormatException
- on syntax error in input.public static java.util.Set<java.lang.String> parseEnumeration(java.lang.String d, java.lang.String s)
d
- Directive being parseds
- String to parsejava.lang.IllegalArgumentException
- If syntax error in input string.public static java.util.List<Util.HeaderEntry> parseManifestHeader(java.lang.String a, java.lang.String s, boolean single, boolean unique, boolean single_entry)
ENTRY (',' ENTRY)* ENTRY = key (';' key)* (';' PARAM)* PARAM = attribute (':' TYPE)? '=' value PARAM = directive ':=' value TYPE = SCALAR | LIST SCALAR = 'String' | 'Version' | 'Long' | 'Double' LIST = 'List<' SCALAR '>'The default attribute value type is 'String'. For list values the 'List' and its following '<' are treated as separate tokens to comply with the OSGi TCK. The parse result is one
Util.HeaderEntry
-instance for each entry.
If single
is true then the entry only contains one key that can be
accesses by calling Util.HeaderEntry.getKey()
.
If unique
is true the attribute values in the map are scalars
otherwise the values from different attribute definitions with the same
name are wrapped in a List<?>
.a
- Name of attribute being parsed, for error messages.s
- String to parse.single
- If true, only allow one key per ENTRY.unique
- Only allow unique attributes for each ENTRY.single_entry
- If true, only allow one ENTRY in s
.Util.HeaderEntry
-object, one per entry in s
.java.lang.IllegalArgumentException
- If syntax error in input string.public static java.lang.String[] splitwords(java.lang.String s)
Equivalent to splitwords(s, WHITESPACE)
public static java.lang.String[] splitwords(java.lang.String s, java.lang.String whiteSpace)
Equivalent to splitwords(s, WHITESPACE, CITCHAR)
public static java.lang.String[] splitwords(java.lang.String s, java.lang.String whiteSpace, char citChar)
Citation chars may be used to group words with embedded whitespace.
s
- String to split.whiteSpace
- whitespace to use for splitting. Any of the characters in
the whiteSpace string are considered whitespace between words and
will be removed from the result. If no words are found, return an
array of length zero.citChar
- Citation character used for grouping words with embedded
whitespace. Typically '"'public static java.util.List<java.lang.String> splitWords(java.lang.String s, char sepChar, boolean trim)
s
- String to split.sepChar
- separator char to split on.trim
- trim whitespace from the words if true
.public static java.lang.String replace(java.lang.String s, java.lang.String v1, java.lang.String v2)
The returned string will shrink or grow as necessary depending on the lengths of v1 and v2.
Implementation note: This method avoids using the standard String manipulation methods to increase execution speed. Using the replace method does however include two new operations in the case when matches are found.
s
- Source string.v1
- String to be replaced with v2
.v2
- String replacing v1
.public static java.lang.String getContent(java.io.File f)
public static void putContent(java.io.File f, java.lang.String content) throws java.io.IOException
java.io.IOException
public static void putContent(java.io.File f, java.lang.String content, boolean useUTF8) throws java.io.IOException
java.io.IOException
public static <A> void sort(java.util.List<A> a, Util.Comparator<A,A> cf, boolean bReverse)
a
- Vector to sortcf
- comparison functionpublic static <A,B> int binarySearch(java.util.List<A> pl, Util.Comparator<A,B> c, B k)
pl
- Sorted list of package entries to search.c
- comparator determining the ordering.k
- The key of the Package entry to search for.(-(<i>insertion point</i>) - 1)
. The insertion point is
defined as the point at which the key would be inserted into the
list.public static java.lang.String base64Encode(java.lang.String s) throws java.io.IOException
java.io.IOException
public static java.lang.String encode(byte[] in, int len) throws java.io.IOException
in
- Byte array to encode.len
- Length of Base64 lines. 0 means no line breaks.java.io.IOException
public static void encode(java.io.InputStream in, java.io.OutputStream out, int len) throws java.io.IOException
java.io.IOException
public static boolean filterMatch(java.lang.String filter, java.lang.String s)
public static java.lang.reflect.Method getMethod(java.lang.Class<?> c, java.lang.String name, java.lang.Class<?>[] args)
public static long timeMillis()
public static java.util.Map<java.lang.String,java.lang.Object> safeDTOMap(java.util.Map<java.lang.String,java.lang.Object> m)
public static java.lang.Object safeDTOObject(java.lang.Object val)
public static boolean validDTOType(java.lang.Class c)