|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.avis.util.Text
public final class Text
General text formatting utilities.
Method Summary | |
---|---|
static void |
appendEscaped(StringBuilder builder,
String string,
char charToEscape)
Append a string to a builder, escaping (with '\') any instances of a special character. |
static void |
appendEscaped(StringBuilder builder,
String string,
String charsToEscape)
Append a string to a builder, escaping (with '\') any instances of a set of special characters. |
static void |
appendHex(StringBuilder str,
byte b)
Append the hex form of a byte to a builder. |
static void |
appendHexBytes(StringBuilder str,
byte[] bytes)
Append a byte array to a builder in form: 01 e2 fe ff ... |
static String |
bytesToHex(byte[] bytes)
Turn an array of bytes into a hex-encoded string e.g. |
static String |
className(Class<?> type)
Return just the name (minus the package) of a class. |
static String |
className(Object object)
Return just the name (minus the package) of an object's class. |
static byte[] |
dataToBytes(byte[] expr)
Turn a data block expression into a block of bytes. |
static String |
expandBackslashes(String text)
Expand C-like backslash codes such as \n \x90 etc into their literal values. |
static int |
findFirstNonEscaped(String str,
char toFind)
Find the first index of the given character, skipping instances that are escaped by '\'. |
static int |
findFirstNonEscaped(String str,
int start,
char toFind)
Find the first index of the given character, skipping instances that are escaped by '\'. |
static String |
formatNotification(Map<String,Object> attributes)
Generate a string value of the notification. |
static byte |
hexToByte(String byteExpr)
Parse a string expression as a hex-coded unsigned byte. |
static byte[] |
hexToBytes(String string)
Parse a series of hex pairs as a sequence of unsigned bytes. |
static String |
idFor(Object instance)
Generate a hex ID for an object. |
static String |
join(List<?> items,
String separator)
Join a list of objects into a string. |
static String |
join(Object[] items)
Join a list of objects into a string. |
static String |
join(Object[] items,
String separator)
Join a list of objects into a string. |
static String |
mapToString(Map<?,?> map)
Generate human friendly string dump of a Map. |
static String |
quotedStringToString(String valueExpr)
Parse a string value in the format "string", allowing escaped "'s inside the string. |
static String |
shortException(Throwable ex)
Generate a short exception message without package name and message (if null). |
static byte[] |
slice(byte[] bytes,
int start,
int end)
|
static String[] |
split(String text)
Shortcut to execute split on any whitespace character. |
static String[] |
split(String text,
String regex)
String.split ("") returns {""} rather than {} like you might expect: this returns empty array on "". |
static Number |
stringToNumber(String valueExpr)
Parse a numeric int, long or double value. |
static byte[] |
stringToOpaque(String valueExpr)
Parse an opaque value expression e.g. |
static Object |
stringToValue(String expr)
Parse a string expression as a value. |
static String |
stripBackslashes(String text)
Remove any \'s from a string. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static String className(Object object)
public static String className(Class<?> type)
public static String shortException(Throwable ex)
public static String idFor(Object instance)
public static String formatNotification(Map<String,Object> attributes)
attributes
- The attribute name/value pairs.
public static void appendEscaped(StringBuilder builder, String string, char charToEscape)
public static void appendEscaped(StringBuilder builder, String string, String charsToEscape)
public static void appendHexBytes(StringBuilder str, byte[] bytes)
public static void appendHex(StringBuilder str, byte b)
public static byte hexToByte(String byteExpr) throws InvalidFormatException
InvalidFormatException
public static Object stringToValue(String expr) throws InvalidFormatException
expr
- The string expression.
InvalidFormatException
- if expr is not parseable.stringToNumber(String)
,
stringToOpaque(String)
,
quotedStringToString(String)
public static Number stringToNumber(String valueExpr) throws InvalidFormatException
InvalidFormatException
public static String quotedStringToString(String valueExpr) throws InvalidFormatException
InvalidFormatException
public static byte[] stringToOpaque(String valueExpr) throws InvalidFormatException
InvalidFormatException
public static byte[] hexToBytes(String string) throws InvalidFormatException
InvalidFormatException
public static String bytesToHex(byte[] bytes)
public static byte[] dataToBytes(byte[] expr) throws InvalidFormatException
Hex pairs: [0a 02 ff 31] String: "hello" Raw data: #data
expr
- The data block expression
InvalidFormatException
- if the expression was not valid.public static byte[] slice(byte[] bytes, int start, int end)
public static int findFirstNonEscaped(String str, char toFind)
public static int findFirstNonEscaped(String str, int start, char toFind)
public static String stripBackslashes(String text) throws InvalidFormatException
InvalidFormatException
public static String[] split(String text)
public static String[] split(String text, String regex)
public static String join(Object[] items)
items
- The items to stringify.
public static String join(Object[] items, String separator)
items
- The items to stringify.separator
- The separator between items.
public static String join(List<?> items, String separator)
items
- The items to stringify.separator
- The separator between items.
public static String mapToString(Map<?,?> map)
public static String expandBackslashes(String text) throws InvalidFormatException
InvalidFormatException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |