Quadcap Embeddable Server

com.quadcap.util.Util Class Reference

List of all members.

Detailed Description

This class aggregates a bunch of various string manipulation utilities.

Author:
Stan Bailes

Definition at line 75 of file Util.java.

Static Public Member Functions

Vector split (String s, char delim)
 Split a string into a vector of elements.

Vector split (String s, char delim, int cnt)
Hashtable parseArgs (String args[])
String readFile (String filename)
String strBytes (byte[] buf, int offset, int len)
String hexBytes (byte[] buf)
String hexBytes (byte[] buf, int off, int len)
String hexInts (byte[] buf)
String hexInts (byte[] buf, int off, int len)
String strBytes (byte[] buf)
boolean boolProperty (String s)
int intProperty (String s, int defVal)
String strProperty (String s, String defVal)
byte[] bytes (String s)
byte[] strCharsAsBytes (String s)
 To hell with character encodings ;-).

void bytesToChars (byte[] bbuf, int boff, char[] cbuf, int coff, int clen)
void charsToBytes (char[] cbuf, int coff, byte[] bbuf, int boff, int clen)
byte[] bytes (int i)
 Convert an int to a byte array, MSB first.

byte[] bytes (long i)
 Convert a long to a byte array, MSB first.

int integer (byte[] buf)
 Convert a byte array which represents an integer into an integer.

int integer (byte[] buf, int pos)
 Extract an integer from four bytes in a byte array.

void putInt (byte[] buf, int pos, int val)
void putLong (byte[] buf, int pos, long val)
final long bytesToLong (byte[] buf)
 Convert a byte array which represents a long into a long.

final long bytesToLong (byte[] buf, int offset)
 Convert a byte array which represents a long into a long.

int compareBytes (byte[] k1, int s1, int c1, byte[] k2, int s2, int c2)
 Byte-array comparison.

int compareBytes (byte[] b1, byte[] b2)
File userFile (String name)
 Return a File object corresponding to the specified file name.

String[] listFiles (final File f)
 Like File.list(), but returns directories first, and sorts alpha.

String getStackTrace (Throwable t)
String stackTrace ()
 Return a string showing the current stack trace.

String stackTrace (boolean condense)
String stackTrace (Throwable e, boolean condense)
 Return a string showing the current stack trace.

void copyStream (InputStream in, OutputStream out) throws IOException
int execCommand (String cmd, OutputStream out, OutputStream err)
int execCommand (String[] cmdarray, OutputStream out, OutputStream err)
int waitFor (Process p, OutputStream out, OutputStream err) throws IOException
int execCommand (String cmd, OutputStream out)
String execCommand (String cmd)
String execCommand (String[] cmd)
String execCommand (String a, String b)
String execCommand (String a, String b, String c)
Thread makeCopyThread (final InputStream in, final OutputStream out)
 Create a thread which copies bytes from an input stream to an output stream until end of file is reached.

final void sleep (long ms)
 Utility to sleep without having to worry about catching InterruptedException.

final void join (Thread t)
 Utility to join without having to worry about catching InterruptedException.

final int waitFor (Process p)
 Utility to wait for a process without having to worry about catching InterruptedException.

final Properties parsePropsString (String extraProps)
 Parse a semicolon-separated property list:.

Object checkCapacity (Object array, int desiredcap)
 Generic array resizer.

List parseIntList (String s)
 Parse a comma-separated list of integers or integer ranges.

int compareObjects (Object a, Object b)
String htmlEscape (String s)

Static Public Attributes

char[] hexMap

Static Package Attributes

HashMap traces = new HashMap()
int lastTrace = 0


Member Function Documentation

boolean com.quadcap.util.Util.boolProperty String  s  )  [static]
 

Definition at line 224 of file Util.java.

References com.quadcap.util.Util.boolProperty().

Referenced by com.quadcap.util.Util.boolProperty().

byte [] com.quadcap.util.Util.bytes long  i  )  [static]
 

Convert a long to a byte array, MSB first.

Parameters:
i the long value

Definition at line 292 of file Util.java.

byte [] com.quadcap.util.Util.bytes int  i  )  [static]
 

Convert an int to a byte array, MSB first.

Parameters:
i the int value

Definition at line 278 of file Util.java.

byte [] com.quadcap.util.Util.bytes String  s  )  [static]
 

Definition at line 237 of file Util.java.

References com.quadcap.util.Util.bytes().

Referenced by com.quadcap.util.Util.bytes().

void com.quadcap.util.Util.bytesToChars byte[]  bbuf,
int  boff,
char[]  cbuf,
int  coff,
int  clen
[static]
 

Definition at line 253 of file Util.java.

References com.quadcap.util.Util.bytesToChars().

Referenced by com.quadcap.util.Util.bytesToChars().

final long com.quadcap.util.Util.bytesToLong byte[]  buf,
int  offset
[static]
 

Convert a byte array which represents a long into a long.

Parameters:
buf the byte array, MSB first.
Returns:
the long value stored in the byte array.

Definition at line 370 of file Util.java.

final long com.quadcap.util.Util.bytesToLong byte[]  buf  )  [static]
 

Convert a byte array which represents a long into a long.

Parameters:
buf the byte array, MSB first.
Returns:
the long value stored in the byte array.

Definition at line 360 of file Util.java.

References com.quadcap.util.Util.bytesToLong().

Referenced by com.quadcap.util.Util.bytesToLong().

void com.quadcap.util.Util.charsToBytes char[]  cbuf,
int  coff,
byte[]  bbuf,
int  boff,
int  clen
[static]
 

Definition at line 263 of file Util.java.

References com.quadcap.util.Util.charsToBytes().

Referenced by com.quadcap.util.Util.charsToBytes(), and com.quadcap.util.Util.strCharsAsBytes().

Object com.quadcap.util.Util.checkCapacity Object  array,
int  desiredcap
[static]
 

Generic array resizer.

Definition at line 688 of file Util.java.

References com.quadcap.util.Util.checkCapacity().

Referenced by com.quadcap.util.Util.checkCapacity().

int com.quadcap.util.Util.compareBytes byte[]  b1,
byte[]  b2
[static]
 

Definition at line 410 of file Util.java.

int com.quadcap.util.Util.compareBytes byte[]  k1,
int  s1,
int  c1,
byte[]  k2,
int  s2,
int  c2
[static]
 

Byte-array comparison.

Parameters:
k1 the byte array containing key 1.
s1 the starting offset of key 1 in k1.
c1 the length of key 1.
k2 the byte array containing key 2.
s2 the starting offset of key 2 in k2.
c2 the length of key 2.
Returns:
< zeroif key1 is less than key2
zeroif key1 is equal to key2
> zeroif key1 is greater than key2

Definition at line 394 of file Util.java.

References com.quadcap.util.Util.compareBytes().

Referenced by com.quadcap.util.Util.compareBytes().

int com.quadcap.util.Util.compareObjects Object  a,
Object  b
[static]
 

Definition at line 730 of file Util.java.

References com.quadcap.util.Util.compareObjects().

Referenced by com.quadcap.util.Util.compareObjects().

void com.quadcap.util.Util.copyStream InputStream  in,
OutputStream  out
throws IOException [static]
 

Definition at line 527 of file Util.java.

References com.quadcap.util.Util.copyStream().

Referenced by com.quadcap.util.Util.copyStream().

String com.quadcap.util.Util.execCommand String  a,
String  b,
String  c
[static]
 

Definition at line 596 of file Util.java.

String com.quadcap.util.Util.execCommand String  a,
String  b
[static]
 

Definition at line 593 of file Util.java.

String com.quadcap.util.Util.execCommand String[]  cmd  )  [static]
 

Definition at line 587 of file Util.java.

String com.quadcap.util.Util.execCommand String  cmd  )  [static]
 

Definition at line 581 of file Util.java.

int com.quadcap.util.Util.execCommand String  cmd,
OutputStream  out
[static]
 

Definition at line 577 of file Util.java.

int com.quadcap.util.Util.execCommand String[]  cmdarray,
OutputStream  out,
OutputStream  err
[static]
 

Definition at line 549 of file Util.java.

References com.quadcap.util.Util.waitFor().

int com.quadcap.util.Util.execCommand String  cmd,
OutputStream  out,
OutputStream  err
[static]
 

Definition at line 535 of file Util.java.

References com.quadcap.util.Util.execCommand(), and com.quadcap.util.Util.waitFor().

Referenced by com.quadcap.util.Util.execCommand().

String com.quadcap.util.Util.getStackTrace Throwable  t  )  [static]
 

Definition at line 455 of file Util.java.

References com.quadcap.util.Util.getStackTrace().

Referenced by com.quadcap.util.Util.getStackTrace().

String com.quadcap.util.Util.hexBytes byte[]  buf,
int  off,
int  len
[static]
 

Definition at line 184 of file Util.java.

References com.quadcap.util.Util.hexMap.

String com.quadcap.util.Util.hexBytes byte[]  buf  )  [static]
 

Definition at line 179 of file Util.java.

References com.quadcap.util.Util.hexBytes().

Referenced by com.quadcap.util.Util.hexBytes().

String com.quadcap.util.Util.hexInts byte[]  buf,
int  off,
int  len
[static]
 

Definition at line 203 of file Util.java.

References com.quadcap.util.Util.hexMap.

String com.quadcap.util.Util.hexInts byte[]  buf  )  [static]
 

Definition at line 199 of file Util.java.

References com.quadcap.util.Util.hexInts().

Referenced by com.quadcap.util.Util.hexInts().

String com.quadcap.util.Util.htmlEscape String  s  )  [static]
 

Definition at line 744 of file Util.java.

References com.quadcap.util.Util.htmlEscape().

Referenced by com.quadcap.util.Util.htmlEscape().

int com.quadcap.util.Util.integer byte[]  buf,
int  pos
[static]
 

Extract an integer from four bytes in a byte array.

Parameters:
buf the byte array
pos the offset in the array of the first (MSB) byte of the int
Returns:
the integer value stored in the byte array.

Definition at line 327 of file Util.java.

int com.quadcap.util.Util.integer byte[]  buf  )  [static]
 

Convert a byte array which represents an integer into an integer.

Parameters:
buf the byte array, MSB first.
Returns:
the integer value stored in the byte array.

Definition at line 311 of file Util.java.

References com.quadcap.util.Util.integer().

Referenced by com.quadcap.util.Util.integer().

int com.quadcap.util.Util.intProperty String  s,
int  defVal
[static]
 

Definition at line 228 of file Util.java.

References com.quadcap.util.Util.intProperty().

Referenced by com.quadcap.util.Util.intProperty().

final void com.quadcap.util.Util.join Thread  t  )  [static]
 

Utility to join without having to worry about catching InterruptedException.

Parameters:
t the thread to wait for

Definition at line 643 of file Util.java.

References com.quadcap.util.Util.join().

Referenced by com.quadcap.util.Util.join().

String [] com.quadcap.util.Util.listFiles final File  f  )  [static]
 

Like File.list(), but returns directories first, and sorts alpha.

Definition at line 433 of file Util.java.

References com.quadcap.util.Util.listFiles().

Referenced by com.quadcap.util.Util.listFiles().

Thread com.quadcap.util.Util.makeCopyThread final InputStream  in,
final OutputStream  out
[static]
 

Create a thread which copies bytes from an input stream to an output stream until end of file is reached.

Definition at line 604 of file Util.java.

References com.quadcap.util.Util.makeCopyThread().

Referenced by com.quadcap.util.Util.makeCopyThread(), and com.quadcap.util.Util.waitFor().

Hashtable com.quadcap.util.Util.parseArgs String  args[]  )  [static]
 

Definition at line 106 of file Util.java.

References com.quadcap.util.Util.parseArgs().

Referenced by com.quadcap.util.Util.parseArgs().

List com.quadcap.util.Util.parseIntList String  s  )  [static]
 

Parse a comma-separated list of integers or integer ranges.

Example: 1,2 Example: 1,3-5,77

Returns:
a List of Integers

Definition at line 708 of file Util.java.

References com.quadcap.util.Util.parseIntList().

Referenced by com.quadcap.util.Util.parseIntList().

final Properties com.quadcap.util.Util.parsePropsString String  extraProps  )  [static]
 

Parse a semicolon-separated property list:.

prop1=val1;prop2=val2

Definition at line 671 of file Util.java.

References com.quadcap.util.Util.parsePropsString().

Referenced by com.quadcap.util.Util.parsePropsString().

void com.quadcap.util.Util.putInt byte[]  buf,
int  pos,
int  val
[static]
 

Definition at line 336 of file Util.java.

References com.quadcap.util.Util.putInt().

Referenced by com.quadcap.util.Util.putInt().

void com.quadcap.util.Util.putLong byte[]  buf,
int  pos,
long  val
[static]
 

Definition at line 343 of file Util.java.

References com.quadcap.util.Util.putLong().

Referenced by com.quadcap.util.Util.putLong().

String com.quadcap.util.Util.readFile String  filename  )  [static]
 

Definition at line 127 of file Util.java.

References com.quadcap.util.Util.readFile().

Referenced by com.quadcap.util.Util.readFile().

final void com.quadcap.util.Util.sleep long  ms  )  [static]
 

Utility to sleep without having to worry about catching InterruptedException.

Parameters:
ms milliseconds to sleep.

Definition at line 629 of file Util.java.

References com.quadcap.util.Util.sleep().

Referenced by com.quadcap.util.Util.sleep().

Vector com.quadcap.util.Util.split String  s,
char  delim,
int  cnt
[static]
 

Definition at line 83 of file Util.java.

Vector com.quadcap.util.Util.split String  s,
char  delim
[static]
 

Split a string into a vector of elements.

Definition at line 79 of file Util.java.

References com.quadcap.util.Util.split().

Referenced by com.quadcap.util.Util.split().

String com.quadcap.util.Util.stackTrace Throwable  e,
boolean  condense
[static]
 

Return a string showing the current stack trace.

Definition at line 480 of file Util.java.

References com.quadcap.util.Util.lastTrace, and com.quadcap.util.Util.traces.

String com.quadcap.util.Util.stackTrace boolean  condense  )  [static]
 

Definition at line 473 of file Util.java.

References com.quadcap.util.Util.stackTrace().

String com.quadcap.util.Util.stackTrace  )  [static]
 

Return a string showing the current stack trace.

Definition at line 469 of file Util.java.

Referenced by com.quadcap.util.Util.stackTrace().

String com.quadcap.util.Util.strBytes byte[]  buf  )  [static]
 

Definition at line 219 of file Util.java.

String com.quadcap.util.Util.strBytes byte[]  buf,
int  offset,
int  len
[static]
 

Definition at line 148 of file Util.java.

References com.quadcap.util.Util.hexMap, and com.quadcap.util.Util.strBytes().

Referenced by com.quadcap.util.Util.strBytes().

byte [] com.quadcap.util.Util.strCharsAsBytes String  s  )  [static]
 

To hell with character encodings ;-).

Definition at line 246 of file Util.java.

References com.quadcap.util.Util.charsToBytes(), and com.quadcap.util.Util.strCharsAsBytes().

Referenced by com.quadcap.util.Util.strCharsAsBytes().

String com.quadcap.util.Util.strProperty String  s,
String  defVal
[static]
 

Definition at line 233 of file Util.java.

References com.quadcap.util.Util.strProperty().

Referenced by com.quadcap.util.Util.strProperty().

File com.quadcap.util.Util.userFile String  name  )  [static]
 

Return a File object corresponding to the specified file name.

If the name is relative, it is located relative to the user's current directory. This is helpful for the case when we run as a service from the /winnt/system32 directory and want to open files relative to our install root.

Parameters:
name the file name
Returns:
the file

Definition at line 424 of file Util.java.

References com.quadcap.util.Util.userFile().

Referenced by com.quadcap.util.Util.userFile().

final int com.quadcap.util.Util.waitFor Process  p  )  [static]
 

Utility to wait for a process without having to worry about catching InterruptedException.

Parameters:
p the process to wait for

Definition at line 657 of file Util.java.

int com.quadcap.util.Util.waitFor Process  p,
OutputStream  out,
OutputStream  err
throws IOException [static]
 

Definition at line 563 of file Util.java.

References com.quadcap.util.Util.makeCopyThread(), and com.quadcap.util.Util.waitFor().

Referenced by com.quadcap.util.Util.execCommand(), and com.quadcap.util.Util.waitFor().


Member Data Documentation

char [] com.quadcap.util.Util.hexMap [static]
 

Initial value:

{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}

Definition at line 145 of file Util.java.

Referenced by com.quadcap.util.Util.hexBytes(), com.quadcap.util.Util.hexInts(), and com.quadcap.util.Util.strBytes().

int com.quadcap.util.Util.lastTrace = 0 [static, package]
 

Definition at line 464 of file Util.java.

Referenced by com.quadcap.util.Util.stackTrace().

HashMap com.quadcap.util.Util.traces = new HashMap() [static, package]
 

Definition at line 463 of file Util.java.

Referenced by com.quadcap.util.Util.stackTrace().