This class contains frequently-used static utility methods.
baToHexString
public static String baToHexString(ba[] )
Convert binary byte array to hex string.
- hex representation of binary input
booleanToSTRING
public static String booleanToSTRING(boolean value)
Convert a boolean to its string representation Equivalent to
Boolean.valueOf(boolean).toString().toUpperCase() but valid also for JDK
1.3, which does not have valueOf(boolean)
value
- boolean to convert
closeQuietly
public static void closeQuietly(InputStream is)
close a stream with no error thrown
is
- - InputStream (may be null)
closeQuietly
public static void closeQuietly(OutputStream os)
close a stream with no error thrown
os
- - OutputStream (may be null)
closeQuietly
public static void closeQuietly(Reader rd)
close a Reader with no error thrown
rd
- - Reader (may be null)
closeQuietly
public static void closeQuietly(ServerSocket sock)
close a Socket with no error thrown
sock
- - ServerSocket (may be null)
closeQuietly
public static void closeQuietly(Socket sock)
close a Socket with no error thrown
sock
- - Socket (may be null)
closeQuietly
public static void closeQuietly(Writer wr)
close a Writer with no error thrown
wr
- - Writer (may be null)
getByteArraySlice
public static byte[] getByteArraySlice(byte[] array,
int begin,
int end)
Returns a slice of a byte array.
TODO - add bounds checking?
array
- -
input arraybegin
- -
start of sliceend
- -
end of slice
- slice from the input array
isXML
public static boolean isXML(byte[] target)
Detects if some content starts with the standard XML prefix.
target
- the content to check
- true if the document starts with the standard XML prefix.
leftAlign
public static StringBuffer leftAlign(StringBuffer in,
int len)
Left aligns some text in a StringBuffer N.B. modifies the input buffer
in
- StringBuffer containing some textlen
- output length desired
- input StringBuffer, with trailing spaces
replaceAllChars
public static String replaceAllChars(String source,
char search,
String replace)
Version of String.replaceAll() for JDK1.3
See below for another version which replaces strings rather than chars
source
- input stringsearch
- char to look for (no regular expressions)replace
- string to replace the search string
replaceFirst
public static String replaceFirst(String source,
String search,
String replace)
Simple-minded String.replace() for JDK1.3 Should probably be recoded...
source
- input stringsearch
- string to look for (no regular expressions)replace
- string to replace the search string
rightAlign
public static StringBuffer rightAlign(StringBuffer in,
int len)
Right aligns some text in a StringBuffer N.B. modifies the input buffer
in
- StringBuffer containing some textlen
- output length desired
- input StringBuffer, with leading spaces
split
public static String[] split(String splittee,
String splitChar)
split
public static String[] split(String splittee,
String delims,
String def)
Takes a String and a tokenizer character string, and returns a new array of
strings of the string split by the tokenizer character(s).
Trailing delimiters are significant (unless the default = null)
splittee
- String to be split.delims
- Delimiter character(s) to split the string ondef
- Default value to place between two split chars that have
nothing between them. If null, then ignore omitted elements.
split
public static String[] split(String splittee,
String splitChar,
boolean truncate)
This is _almost_ equivalent to the String.split method in JDK 1.4. It is
here to enable us to support earlier JDKs.
Note that unlike JDK1.4 split(), it optionally ignores leading split Characters,
and the splitChar parameter is not a Regular expression
This piece of code used to be part of JMeterUtils, but was moved here
because some JOrphan classes use it too.
splittee
- String to be splitsplitChar
- Character(s) to split the string on, these are treated as a single unittruncate
- Should adjacent and leading/trailing splitChars be removed?
startsWith
public static boolean startsWith(byte[] target,
byte[] search,
int offset)
Check if a byte array starts with the given byte array.
target
- array to scansearch
- array to search foroffset
- starting offset (>=0)
- true if the search array matches the target at the current offset
String.startsWith(String, int)
substitute
public static String substitute(String input,
String pattern,
String sub)
Replace all patterns in a String
input
- - string to be transformedpattern
- - pattern to replacesub
- - replacement
trim
public static String trim(String input,
String delims)
Trim a string by the tokens provided.
input
- string to trimdelims
- list of delimiters
- input trimmed at the first delimiter