Buju 0.4

biz.bbeans.util
Class BUtil

java.lang.Object
  extended bybiz.bbeans.util.BUtil

public class BUtil
extends Object

A collection of static utility methods.


Field Summary
static String SPACE
          A single space
 
Method Summary
static void debug(Object o, String s)
          Prints the object name and specified string to System.out.
static Properties getBundleAsProperties(String fileName, Locale locale, Properties defaults)
           
static String getCopyrightMsg()
          Returns copyright message.
static DateFormat getDateFormat(String pattern)
          Get a localized date format object, using the given pattern, if possible.
static FileInputStream getFileInputStream(String fileName)
          Get a FileInputStream for given file name.
static FileOutputStream getFileOutputStream(String fileName)
          Get a FileOutputStream for given file name.
static String getFirstClassPath()
          Return the first directory name in the classpath.
static NumberFormat getNumberFormat(String pattern)
          Get a localized number format object, using the given pattern, if possible.
static Properties getProperties(String resourceName)
          Convenience method to retrieve Properties from a system resource with the given name.
static void handleException(Throwable exc)
          General exception handling method, which prints the exception message to System.err and the stack trace.
static Object loadObject(String fileName)
          Loads serializable object from the specified file name.
static String pad(String s, int length)
          Forces string to be the given length by padding with spaces or truncating.
static void print(InputStream in, OutputStream out)
          Print the input stream to the output stream using a BufferedReader and BufferedWriter.
static void run(String className, String[] args)
          Load the given class and call its main method in a new thread, passing the given arguments.
static void storeObject(String fileName, Serializable s)
          Saves serializable object to the specified file name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SPACE

public static final String SPACE
A single space

See Also:
Constant Field Values
Method Detail

debug

public static final void debug(Object o,
                               String s)
Prints the object name and specified string to System.out.

Parameters:
o - should usually be the object calling this method.
s - string to print following the name of the object.

getBundleAsProperties

public static final Properties getBundleAsProperties(String fileName,
                                                     Locale locale,
                                                     Properties defaults)
                                              throws MissingResourceException
Throws:
MissingResourceException

getFirstClassPath

public static final String getFirstClassPath()
Return the first directory name in the classpath. By making the first classpath directory be the codebase for application resource files such as icons and html, the resource files can be easily located relative to this directory.


getCopyrightMsg

public static final String getCopyrightMsg()
Returns copyright message.


getDateFormat

public static final DateFormat getDateFormat(String pattern)
Get a localized date format object, using the given pattern, if possible. If the pattern is null, get a default date format.

Parameters:
pattern - The template to use for formatting date strings and parsing Date objects.
Returns:
The date format.

getFileInputStream

public static final FileInputStream getFileInputStream(String fileName)
Get a FileInputStream for given file name.

Returns:
The FileInputStream, or null if the file doesn't exist.

getFileOutputStream

public static final FileOutputStream getFileOutputStream(String fileName)
Get a FileOutputStream for given file name.

Returns:
The FileOutputStream.

getNumberFormat

public static final NumberFormat getNumberFormat(String pattern)
Get a localized number format object, using the given pattern, if possible. If the pattern is null, get a default number format. If the pattern equals "$", get a default currency format.

Parameters:
pattern - The template to use for parsing number strings and formatting Number objects.
Returns:
The number format.

getProperties

public static final Properties getProperties(String resourceName)
                                      throws IOException
Convenience method to retrieve Properties from a system resource with the given name. Can be used in conjunction with the BMail(Properties) constructor. try { Properties props = BUtil.getProperties("mail.properties"); BMail myMailMessage = new BMail(props); } catch (java.io.IOException exc) { //handle exception }

Parameters:
resourceName - The name of the system resource. Must be visible and resolvable within the ClassLoader's classpath.
Returns:
A Properties object for the given system resource name.
Throws:
IOException - If the properties cannot be loaded from the input stream associated with the system resource.

handleException

public static final void handleException(Throwable exc)
General exception handling method, which prints the exception message to System.err and the stack trace.

Parameters:
exc - exception.

loadObject

public static final Object loadObject(String fileName)
                               throws IOException,
                                      ClassNotFoundException,
                                      Throwable
Loads serializable object from the specified file name.

Parameters:
fileName - name of file containing serialized object.
Throws:
IOException.
IOException
ClassNotFoundException
Throwable

pad

public static final String pad(String s,
                               int length)
Forces string to be the given length by padding with spaces or truncating.

Parameters:
s - string to pad or truncate.
length - length of returned string

print

public static void print(InputStream in,
                         OutputStream out)
Print the input stream to the output stream using a BufferedReader and BufferedWriter. The streams are assumed to be character lines. The streams are finally closed.


run

public static final void run(String className,
                             String[] args)
                      throws ClassNotFoundException,
                             IllegalArgumentException,
                             NoSuchMethodException
Load the given class and call its main method in a new thread, passing the given arguments.

Throws:
ClassNotFoundException
IllegalArgumentException
NoSuchMethodException

storeObject

public static final void storeObject(String fileName,
                                     Serializable s)
                              throws IOException
Saves serializable object to the specified file name.

Parameters:
s - serializable object.
fileName - name of file to serialize object to.
Throws:
IOException.
IOException

Buju 0.4