inria.util
Class Utilities

java.lang.Object
  |
  +--inria.util.Utilities

public class Utilities
extends java.lang.Object

Static methods providing common utilities.


Field Summary
protected static java.net.InetAddress localhost
           
protected static java.lang.String localHostName
           
static long Modulo32
           
 
Constructor Summary
Utilities()
           
 
Method Summary
static java.lang.String basename(java.lang.String filename)
          Returns the base name from a file name.
static boolean bcomp(byte[] v1, byte[] v2)
          does a byte compare.
static int byteToInt(byte[] buff, int offset)
          Get integer value from a byte array.
static long byteToLong(byte[] buff, int offset)
          Get long value from a byte array.
static java.lang.String convertPathname(java.lang.String filename)
          converts a file path name appropriate to the platform.
static int diff32(int seq1, int seq2)
          does 32-bit diff of seqno (seq1 - seq2).
static java.lang.String dirname(java.lang.String filename)
          Returns the dir name from a file name.
static java.lang.String fileExtension(java.lang.String filename)
          gets extension string of a file name.
static java.lang.String getHttpRoot(java.lang.String url)
          gets root http url, something like http://a.b.c
static java.net.InetAddress getLocalHost()
          gets the local host address.
static java.lang.String getLocalHostName()
          gets the local host address.
static double getRandomDouble()
          returns a random integer using the default seed.
static int getRandomInteger()
          returns a random integer using the default seed.
static int getShort(byte[] buf, int offset)
          Get short value from a byte array.
static java.lang.String getURLRoot(java.lang.String url)
          gets the root of url, something like proto://a.b.c
static java.lang.String GMTDate(long t)
          returns a string representation of the time using GMT.
static void intToByte(int i, byte[] buff, int offset)
          Put an integer value into a byte array in the MSBF order.
static boolean isValidURL(java.lang.String url)
          Check if the url is valid.
static java.lang.String localDate(long t)
          returns a string representation of the time using the default locale.
static int pad32(byte[] buff, int offset)
          pad a byte buffer so that it contains an integer number of 32 bit word.
static long parseGenericDate(java.lang.String s)
          parses the date string in standard format, i.e., Sun, 06 Nov 1994 08:49:37 GMT --- RFC 822, updated by RFC 1123 Sunday, 06-Nov-94 08:49:37 GMT --- RFC 850, obsoleted by RFC 1036 Sun Nov 6 08:49:37 1994 --- ANSI C's asctime() format
static java.lang.String shortDate(long t)
          returns a string representation of the time using the default locale.
static java.lang.String shortDateWithWeekday(long t)
          returns a string representation of the time using the default locale.
static java.lang.String shortPathname(java.lang.String s)
          Remove ./ and ../ from pathname.
static java.util.Vector sortByString(java.util.Vector tab, boolean ignoreCase)
          sorts the given table by characters.
static java.lang.String toAddressString(int addr)
          converts int to INET address string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

Modulo32

public static final long Modulo32

localhost

protected static java.net.InetAddress localhost

localHostName

protected static java.lang.String localHostName
Constructor Detail

Utilities

public Utilities()
Method Detail

getLocalHostName

public static java.lang.String getLocalHostName()
gets the local host address.

getLocalHost

public static java.net.InetAddress getLocalHost()
gets the local host address.

fileExtension

public static java.lang.String fileExtension(java.lang.String filename)
gets extension string of a file name.
Parameters:
filename - the file pathname.

convertPathname

public static java.lang.String convertPathname(java.lang.String filename)
converts a file path name appropriate to the platform.
Parameters:
filename - the file pathname.
Returns:
a converted path name.

shortPathname

public static java.lang.String shortPathname(java.lang.String s)
Remove ./ and ../ from pathname.
Parameters:
s - the file pathname or http URL string.

dirname

public static java.lang.String dirname(java.lang.String filename)
Returns the dir name from a file name.
Parameters:
filename - the file pathname.

basename

public static java.lang.String basename(java.lang.String filename)
Returns the base name from a file name.
Parameters:
filename - the file pathname.

getURLRoot

public static java.lang.String getURLRoot(java.lang.String url)
gets the root of url, something like proto://a.b.c
Parameters:
url - the absolute url.

getHttpRoot

public static java.lang.String getHttpRoot(java.lang.String url)
gets root http url, something like http://a.b.c
Parameters:
url - absolute url.

intToByte

public static void intToByte(int i,
                             byte[] buff,
                             int offset)
Put an integer value into a byte array in the MSBF order.
Parameters:
i - the integer value.
buff - the byte array.
offset - the offset in the array to put the integer.

byteToInt

public static int byteToInt(byte[] buff,
                            int offset)
Get integer value from a byte array.
Parameters:
buff - the byte array.
offset - the offset in the array.

byteToLong

public static long byteToLong(byte[] buff,
                              int offset)
Get long value from a byte array.
Parameters:
buff - the byte array.
offset - the offset in the array.

getShort

public static int getShort(byte[] buf,
                           int offset)
Get short value from a byte array.
Parameters:
buff - the byte array.
offset - the offset in the array.

isValidURL

public static boolean isValidURL(java.lang.String url)
Check if the url is valid.
Parameters:
url - the URL string.

toAddressString

public static java.lang.String toAddressString(int addr)
converts int to INET address string.
Parameters:
addr - 32 bit address values.

pad32

public static int pad32(byte[] buff,
                        int offset)
pad a byte buffer so that it contains an integer number of 32 bit word. returns number of bytes pad.

diff32

public static int diff32(int seq1,
                         int seq2)
does 32-bit diff of seqno (seq1 - seq2). Handle overflow and underflow. The result will be correct provided that the absolute diff is less than Modulo32/2.
Parameters:
seq1 - first seqno.
seq2 - second seqno.

bcomp

public static boolean bcomp(byte[] v1,
                            byte[] v2)
does a byte compare.
Parameters:
v1 - the first byte array.
v1 - the second byte array.
Returns:
true if they match.

sortByString

public static java.util.Vector sortByString(java.util.Vector tab,
                                            boolean ignoreCase)
sorts the given table by characters. This method uses the string representation of the objects contained in the table which is obtained using the toString() method.
Parameters:
tab - the table to sort.
ignoreCase - if true, ingore case while comparing characters.
Returns:
the sorted table.

getRandomInteger

public static int getRandomInteger()
returns a random integer using the default seed.

getRandomDouble

public static double getRandomDouble()
returns a random integer using the default seed.

GMTDate

public static java.lang.String GMTDate(long t)
returns a string representation of the time using GMT. The date is in the form of Wed, 15 Nov 1995 04:58:08 GMT.

localDate

public static java.lang.String localDate(long t)
returns a string representation of the time using the default locale. The date is in the form of Wed, 15 Nov 1995 04:58:08 MET.

shortDateWithWeekday

public static java.lang.String shortDateWithWeekday(long t)
returns a string representation of the time using the default locale. The date is in the form of Wed, 15 Nov 04:58.

shortDate

public static java.lang.String shortDate(long t)
returns a string representation of the time using the default locale. The date is in the form of 15 Nov 04:58:08.

parseGenericDate

public static long parseGenericDate(java.lang.String s)
parses the date string in standard format, i.e.,
Parameters:
s - the date string.


JavaTM Reliable MulticastTM Service version 1.1
Copyright (c) 2001, Sun Microsystems Laboratories, All rights reserved.