Apache JMeter
2.2

org.apache.jorphan.util
Class JOrphanUtils

java.lang.Object
  extended byorg.apache.jorphan.util.JOrphanUtils

public final class JOrphanUtils
extends Object

This class contains frequently-used static utility methods.

Version:
$Revision: 411627 $ Last updated: $Date: 2006-06-05 01:39:22 +0100 (Mon, 05 Jun 2006) $
Author:
Jordi Salvat i Alabart Created 27th December 2002

Method Summary
static String booleanToString(boolean value)
          Convert a boolean to its string representation Equivalent to Boolean.valueOf(boolean).toString() but valid also for JDK 1.3, which does not have valueOf(boolean)
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)
static void closeQuietly(InputStream is)
          close a stream with no error thrown
static void closeQuietly(OutputStream os)
          close a stream with no error thrown
static void closeQuietly(Reader rd)
          close a Reader with no error thrown
static void closeQuietly(Writer wr)
          close a Writer with no error thrown
static String decode(String string, String encoding)
          Version of URLDecoder().decode(string,encoding) for JDK1.3 Also supports JDK1.4 (but will be a bit slower)
static String encode(String string, String encoding)
          Version of URLEncoder().encode(string,encoding) for JDK1.3 Also supports JDK1.4 (but will be a bit slower)
static byte[] getByteArraySlice(byte[] array, int begin, int end)
          Returns a slice of a byte array.
static StringBuffer leftAlign(StringBuffer in, int len)
          Left aligns some text in a StringBuffer N.B. modifies the input buffer
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
static String replaceFirst(String source, String search, String replace)
          Simple-minded String.replace() for JDK1.3 Should probably be recoded...
static StringBuffer rightAlign(StringBuffer in, int len)
          Right aligns some text in a StringBuffer N.B. modifies the input buffer
static String[] split(String splittee, String splitChar)
           
static String[] split(String splittee, String splitChar, boolean truncate)
          This is _almost_ equivalent to the String.split method in JDK 1.4.
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).
static String substitute(String input, String pattern, String sub)
          Replace all patterns in a String
static String trim(String input, String delims)
          Trim a string by the tokens provided.
static Boolean valueOf(boolean value)
          Version of Boolean.valueOf(boolean) for JDK 1.3
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

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.

Parameters:
splittee - String to be split
splitChar - Character(s) to split the string on, these are treated as a single unit
truncate - Should adjacent and leading/trailing splitChars be removed?
Returns:
Array of all the tokens.
See Also:
split(String, String, String)

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)

Parameters:
splittee - String to be split.
delims - Delimiter character(s) to split the string on
def - Default value to place between two split chars that have nothing between them. If null, then ignore omitted elements.
Returns:
Array of all the tokens.
Throws:
NullPointerException - if splittee or delims are null
See Also:
split(String, String, boolean), This is a rewritten version of JMeterUtils.split()

rightAlign

public static StringBuffer rightAlign(StringBuffer in,
                                      int len)
Right aligns some text in a StringBuffer N.B. modifies the input buffer

Parameters:
in - StringBuffer containing some text
len - output length desired
Returns:
input StringBuffer, with leading spaces

leftAlign

public static StringBuffer leftAlign(StringBuffer in,
                                     int len)
Left aligns some text in a StringBuffer N.B. modifies the input buffer

Parameters:
in - StringBuffer containing some text
len - output length desired
Returns:
input StringBuffer, with trailing spaces

booleanToString

public static String booleanToString(boolean value)
Convert a boolean to its string representation Equivalent to Boolean.valueOf(boolean).toString() but valid also for JDK 1.3, which does not have valueOf(boolean)

Parameters:
value - boolean to convert
Returns:
"true" or "false"

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)

Parameters:
value - boolean to convert
Returns:
"TRUE" or "FALSE"

valueOf

public static Boolean valueOf(boolean value)
Version of Boolean.valueOf(boolean) for JDK 1.3

Parameters:
value - boolean to convert
Returns:
Boolean.TRUE or Boolean.FALSE

encode

public static String encode(String string,
                            String encoding)
                     throws UnsupportedEncodingException
Version of URLEncoder().encode(string,encoding) for JDK1.3 Also supports JDK1.4 (but will be a bit slower)

Parameters:
string - to be encoded
encoding - (ignored for JDK1.3)
Returns:
the encoded string
Throws:
UnsupportedEncodingException

decode

public static String decode(String string,
                            String encoding)
                     throws UnsupportedEncodingException
Version of URLDecoder().decode(string,encoding) for JDK1.3 Also supports JDK1.4 (but will be a bit slower)

Parameters:
string - to be decoded
encoding - (ignored for JDK1.3)
Returns:
the encoded string
Throws:
UnsupportedEncodingException

replaceFirst

public static String replaceFirst(String source,
                                  String search,
                                  String replace)
Simple-minded String.replace() for JDK1.3 Should probably be recoded...

Parameters:
source - input string
search - string to look for (no regular expressions)
replace - string to replace the search string
Returns:
the output string

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

Parameters:
source - input string
search - char to look for (no regular expressions)
replace - string to replace the search string
Returns:
the output string

substitute

public static String substitute(String input,
                                String pattern,
                                String sub)
Replace all patterns in a String

Parameters:
input - - string to be transformed
pattern - - pattern to replace
sub - - replacement
Returns:
the updated string
See Also:
- JDK1.4 only

trim

public static String trim(String input,
                          String delims)
Trim a string by the tokens provided.

Parameters:
input - string to trim
delims - list of delimiters
Returns:
input trimmed at the first delimiter

getByteArraySlice

public static byte[] getByteArraySlice(byte[] array,
                                       int begin,
                                       int end)
Returns a slice of a byte array. TODO - add bounds checking?

Parameters:
array - - input array
begin - - start of slice
end - - end of slice
Returns:
slice from the input array

closeQuietly

public static void closeQuietly(InputStream is)
close a stream with no error thrown

Parameters:
is - - InputStream (may be null)

closeQuietly

public static void closeQuietly(OutputStream os)
close a stream with no error thrown

Parameters:
os - - OutputStream (may be null)

closeQuietly

public static void closeQuietly(Writer wr)
close a Writer with no error thrown


closeQuietly

public static void closeQuietly(Reader rd)
close a Reader with no error thrown


Apache JMeter
2.2

Copyright © 1998-2006 Apache Software Foundation. All Rights Reserved.