qat.common
Class Utils

java.lang.Object
  extended byqat.common.Utils

public abstract class Utils
extends java.lang.Object


Constructor Summary
Utils()
           
 
Method Summary
static void cat(java.lang.String fileName)
          This writes the file specified by fileName to the stdout.
static void checkSubDirsExist(java.lang.String path)
          Creates all neccesary parent directories contained in this path.
static void cleanUnzippedFiles(java.lang.String zipFileName, java.lang.String outputDirectory)
          This method deletes all the files and subdirectories as created when the zipFileName was unzipped in the outputDirectory.
static void copy(java.lang.String sourceName, java.lang.String destName)
          This method copies sourceName to destName.
static java.io.File createTempFile(java.lang.String prefix, java.lang.String suffix)
           
static void delete(java.io.File node)
          This method deletes the file specified by fileName.
static void delete(java.lang.String fileName)
          This method deletes the file specified by fileName.
static java.lang.String ensureSuffix(java.lang.String fileName, java.lang.String suffix)
          This method appends the specified suffix to the fileName if it doesn't already have it.
static java.lang.String extractFileName(java.lang.String path)
          This method extracts the fileName portion from the specified path.
static java.lang.String extractPath(java.lang.String path)
          This method extracts the path portion from the given parameter.
static int getUniqueID()
          This method is used to allocate unique identifiers.
static java.util.Properties mergeProperties(java.util.Properties propertiesDest, java.util.Properties propertiesSource)
          Merge the properties of propertiesSource with those of propertiesDest.
static void microSleep(int milliseconds)
          This method will block until the specified number of seconds elapsed, as measured by the system clock.
static java.lang.String pad(java.lang.String str, int length)
          This method will pad the string to the specified length with spaces.
static java.io.File parent(java.io.File f)
          This method returns the absolute path of the parent of the file specified by f.
static java.lang.String removeSuffix(java.lang.String fileName)
          This method removes the file suffix, if it exists, from the parameter fileName.
static void safeSleep(long seconds)
          This method will block until the specified number of seconds elapsed, as measured by the system clock.
static java.lang.String[] toStringArray(java.lang.String s)
          This breaks up a list of strings into a string array.
static void touch(java.lang.String fileName)
          This method creates a file specified by fileName, if it doesn't already exist.
static void touchDir(java.lang.String dirName)
          This method creates a dir specified by dirName, if it doesn't already exist.
static java.lang.String trimFileName(java.lang.String path, int max)
          This method ensures the path is never longer than max characters.
static void unzipFiles(java.lang.String zipFileName, java.lang.String outputDirectory)
          This methods will unzip all the files contained in zipFileName, placing them in a position offset with directory outputDirectory.
static void zipFiles(java.lang.String zipFileName, java.lang.String[] fileList)
          This method will create a new zip file zipFileName, or overwrite an existing one, and place in it all the files specified in fileList.
static void zipFiles(java.lang.String zipFileName, java.lang.String[] fileList, java.lang.String[] fileNameInZip)
          This method will create a new zip file zipFileName, or overwrite an existing one, and place in it all the files specified in fileList.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Utils

public Utils()
Method Detail

zipFiles

public static void zipFiles(java.lang.String zipFileName,
                            java.lang.String[] fileList)
                     throws java.io.IOException
This method will create a new zip file zipFileName, or overwrite an existing one, and place in it all the files specified in fileList. Their offset within the zip file will be exactly the same as the offset given in the fileList argument for each item. The fileList may contain directories, but they will not be explicitly followed. Each zip file must contain at least one non-directory entry.

Parameters:
zipFileName - the name of the zip file we want to create.
fileList - an array containing the absolute path names of the files or directories to store in this zip file.
Throws:
java.io.IOException - thrown if the file could not be created, or we cannot read some of the input files.

zipFiles

public static void zipFiles(java.lang.String zipFileName,
                            java.lang.String[] fileList,
                            java.lang.String[] fileNameInZip)
                     throws java.io.IOException
This method will create a new zip file zipFileName, or overwrite an existing one, and place in it all the files specified in fileList. The name and offset of the file entries in the zip file will not match that of the original source file, but will match the name and offset given in the zipFileName. The fileList may contain directories, but they will not be explicitly followed. Each zip file must contain at least one non-directory entry.

Parameters:
zipFileName - the name of the zip file we want to create.
fileList - an array containing the absolute path names of the files or directories to store in this zip file.
fileNameInZip - the exact name to call the entry in the zip file, if it is different to the name in fileList.
Throws:
java.io.IOException - thrown if the file could not be created, or we cannot read some of the input files.

unzipFiles

public static void unzipFiles(java.lang.String zipFileName,
                              java.lang.String outputDirectory)
                       throws java.io.IOException
This methods will unzip all the files contained in zipFileName, placing them in a position offset with directory outputDirectory.

Parameters:
zipFileName - the name of the zip file we want to extract.
outputDirectory - the name of the directory in which to extract the files.
Throws:
java.io.IOException - thrown if the file could not be unzipped, or we cannot write in the output directory.

cleanUnzippedFiles

public static void cleanUnzippedFiles(java.lang.String zipFileName,
                                      java.lang.String outputDirectory)
                               throws java.io.IOException
This method deletes all the files and subdirectories as created when the zipFileName was unzipped in the outputDirectory.

Throws:
java.io.IOException

touch

public static void touch(java.lang.String fileName)
                  throws java.io.IOException
This method creates a file specified by fileName, if it doesn't already exist. If the parent directories don't exist, they will be created automatically.

Parameters:
fileName - the name of the file to create.
Throws:
java.io.IOException - thrown if any IOException occur due to permission problems etc.

touchDir

public static void touchDir(java.lang.String dirName)
                     throws java.io.IOException
This method creates a dir specified by dirName, if it doesn't already exist. If the parent directories don't exist, they will be created automatically.

Parameters:
dirName - the name of the dir to create.
Throws:
java.io.IOException - thrown if any IOException occur due to permission problems etc.

cat

public static void cat(java.lang.String fileName)
                throws java.io.IOException
This writes the file specified by fileName to the stdout.

Parameters:
fileName - the name of the file to be written to stdout.
Throws:
java.io.IOException - thrown if the file does not exist, or cannot be read.

copy

public static void copy(java.lang.String sourceName,
                        java.lang.String destName)
                 throws java.io.IOException
This method copies sourceName to destName. If sourceName is a directory, a recursive copy of all sub-directories is done.

Parameters:
sourceName - the name of the source file/directory to be copied.
destName - the name of the destination file/directory.
Throws:
java.io.IOException - thrown if any of the files cannot be read or written.

delete

public static void delete(java.lang.String fileName)
                   throws java.io.IOException
This method deletes the file specified by fileName. If it is a directory, all subdirectories are also deleted.

Parameters:
fileName - the name of the file or directory to be deleted.
Throws:
java.io.IOException - thrown if the file or directory could not be deleted.

delete

public static void delete(java.io.File node)
                   throws java.io.IOException
This method deletes the file specified by fileName. If it is a directory, all subdirectories are also deleted.

Parameters:
node - the File identifier of the file or directory to be deleted.
Throws:
java.io.IOException - thrown if the file or directory could not be deleted.

toStringArray

public static java.lang.String[] toStringArray(java.lang.String s)
This breaks up a list of strings into a string array. eg "s1" + "s2" + "s3" would give {"s1,"s2,"s3"}


safeSleep

public static void safeSleep(long seconds)
This method will block until the specified number of seconds elapsed, as measured by the system clock. May have differing behaviour on various JVM implementations (blocking etc)

Parameters:
seconds - the number of seconds to sleep for.

microSleep

public static void microSleep(int milliseconds)
This method will block until the specified number of seconds elapsed, as measured by the system clock.


pad

public static java.lang.String pad(java.lang.String str,
                                   int length)
This method will pad the string to the specified length with spaces. If the string is longer than the length specified, no changes are effected

Parameters:
str - the String to pad.
length - the desired length of the string.

parent

public static java.io.File parent(java.io.File f)
This method returns the absolute path of the parent of the file specified by f. For use internally by the copy method.

Parameters:
f - the name of the file whose parent we seek.

checkSubDirsExist

public static void checkSubDirsExist(java.lang.String path)
Creates all neccesary parent directories contained in this path. Not to be confused with checkSubDirsExist(String rootPath, String path) which is used exclusively by the unzip routines, since java zip files always store directories separated by the '/' instead of File.separator char.


extractFileName

public static java.lang.String extractFileName(java.lang.String path)
This method extracts the fileName portion from the specified path.


trimFileName

public static java.lang.String trimFileName(java.lang.String path,
                                            int max)
This method ensures the path is never longer than max characters.


extractPath

public static java.lang.String extractPath(java.lang.String path)
This method extracts the path portion from the given parameter.


ensureSuffix

public static java.lang.String ensureSuffix(java.lang.String fileName,
                                            java.lang.String suffix)
This method appends the specified suffix to the fileName if it doesn't already have it. If the original suffix is different, it is removed. It works whether suffix includes the "." or not.


removeSuffix

public static java.lang.String removeSuffix(java.lang.String fileName)
This method removes the file suffix, if it exists, from the parameter fileName. The preceding path information is not changed.


getUniqueID

public static int getUniqueID()
This method is used to allocate unique identifiers.


mergeProperties

public static java.util.Properties mergeProperties(java.util.Properties propertiesDest,
                                                   java.util.Properties propertiesSource)
Merge the properties of propertiesSource with those of propertiesDest.


createTempFile

public static java.io.File createTempFile(java.lang.String prefix,
                                          java.lang.String suffix)


See QAT project for licensing details