databionics.util
Class Utils

java.lang.Object
  extended by databionics.util.Utils

public class Utils
extends java.lang.Object

Some static utility functions


Field Summary
protected static org.apache.log4j.Logger log
          logging
 
Constructor Summary
Utils()
           
 
Method Summary
static void copyFile(java.io.File in, java.io.File out)
          Copy a file and display progress.
static java.io.Reader createReaderByFilename(java.io.File file)
          Create a possibly compressed reader based on the filename if the filename ends with ".zip" a ZipInputStream ist used if the filename ends with ".gz" a GZIPInputStream ist used if the filename ends with ".bz2" a CBZip2InputStream ist used otherwise a plain FileInputStream is used
static java.io.Reader createReaderByFilename(java.lang.String file)
          Create a possibly compressed reader based on the filename if the filename ends with ".zip" a ZipInputStream ist used if the filename ends with ".gz" a GZIPInputStream ist used if the filename ends with ".bz2" a CBZip2InputStream ist used otherwise a plain FileInputStream is used
static java.io.Writer createWriterByFilename(java.io.File file)
          Create a possibly compressed writer based on the filename if the filename ends with ".zip" a ZipOutputStream ist used if the filename ends with ".gz" a GZIPOutputStream ist used if the filename ends with ".bz2" a CBZip2OutputStream ist used otherwise a plain FileOutputStream is used
static java.io.Writer createWriterByFilename(java.lang.String file)
          Create a possibly compressed writer based on the filename if the filename ends with ".zip" a ZipOutputStream ist used if the filename ends with ".gz" a GZIPOutputStream ist used if the filename ends with ".bz2" a CBZip2OutputStream ist used otherwise a plain FileOutputStream is used
static java.util.List findClassesInJar(java.lang.String dir, java.lang.String jar, java.lang.String pkg, java.lang.String sclass, java.lang.String iface)
          Find all classes in *.jar files, optionally restrict to a package, direct subclasses of a given class or classes implementing a given interface.
static java.lang.String getEnvironmentVariable(java.lang.String name)
          Get value of an environment variable.
static void loadProperties(java.io.File file)
          Load properties from a file into System properties
static java.util.Locale stringToLocale(java.lang.String loc)
          Convert string to locale
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static org.apache.log4j.Logger log
logging

Constructor Detail

Utils

public Utils()
Method Detail

stringToLocale

public static java.util.Locale stringToLocale(java.lang.String loc)
Convert string to locale

Parameters:
loc - Local as string
Returns:
Locale

getEnvironmentVariable

public static java.lang.String getEnvironmentVariable(java.lang.String name)
Get value of an environment variable.

Parameters:
name - Name of variable
Returns:
value as string

loadProperties

public static void loadProperties(java.io.File file)
                           throws java.io.IOException,
                                  java.io.FileNotFoundException
Load properties from a file into System properties

Parameters:
file - Property file
Throws:
java.io.IOException
java.io.FileNotFoundException

copyFile

public static void copyFile(java.io.File in,
                            java.io.File out)
                     throws java.io.FileNotFoundException,
                            java.io.IOException
Copy a file and display progress.

Throws:
java.io.FileNotFoundException
java.io.IOException

createReaderByFilename

public static java.io.Reader createReaderByFilename(java.lang.String file)
                                             throws java.io.FileNotFoundException,
                                                    java.io.IOException
Create a possibly compressed reader based on the filename if the filename ends with ".zip" a ZipInputStream ist used if the filename ends with ".gz" a GZIPInputStream ist used if the filename ends with ".bz2" a CBZip2InputStream ist used otherwise a plain FileInputStream is used

Throws:
java.io.FileNotFoundException
java.io.IOException

createReaderByFilename

public static java.io.Reader createReaderByFilename(java.io.File file)
                                             throws java.io.FileNotFoundException,
                                                    java.io.IOException
Create a possibly compressed reader based on the filename if the filename ends with ".zip" a ZipInputStream ist used if the filename ends with ".gz" a GZIPInputStream ist used if the filename ends with ".bz2" a CBZip2InputStream ist used otherwise a plain FileInputStream is used

Throws:
java.io.FileNotFoundException
java.io.IOException

createWriterByFilename

public static java.io.Writer createWriterByFilename(java.lang.String file)
                                             throws java.io.FileNotFoundException,
                                                    java.io.IOException
Create a possibly compressed writer based on the filename if the filename ends with ".zip" a ZipOutputStream ist used if the filename ends with ".gz" a GZIPOutputStream ist used if the filename ends with ".bz2" a CBZip2OutputStream ist used otherwise a plain FileOutputStream is used

Throws:
java.io.FileNotFoundException
java.io.IOException

createWriterByFilename

public static java.io.Writer createWriterByFilename(java.io.File file)
                                             throws java.io.FileNotFoundException,
                                                    java.io.IOException
Create a possibly compressed writer based on the filename if the filename ends with ".zip" a ZipOutputStream ist used if the filename ends with ".gz" a GZIPOutputStream ist used if the filename ends with ".bz2" a CBZip2OutputStream ist used otherwise a plain FileOutputStream is used

Throws:
java.io.FileNotFoundException
java.io.IOException

findClassesInJar

public static java.util.List findClassesInJar(java.lang.String dir,
                                              java.lang.String jar,
                                              java.lang.String pkg,
                                              java.lang.String sclass,
                                              java.lang.String iface)
Find all classes in *.jar files, optionally restrict to a package, direct subclasses of a given class or classes implementing a given interface.

Parameters:
dir - Directory with *.jar file(s)
jar - Beginning of *.jar file name(s) to search, can be null to search all files
pkg - Restrict search to this package (with / not .)
sclass - Restrict search to direct subclasses of this superclass, can be null
iface - Restrict search to classes implementinf this interface, can be null
Returns:
list with one instance of each class found


Copyright © 2005-2006 Databionics Research Group. All Rights Reserved.