com.taleo.integration.client.customstep.util
Class FileUtils

java.lang.Object
  extended by com.taleo.integration.client.customstep.util.FileUtils

public final class FileUtils
extends java.lang.Object

Utility class that wraps some file functions.

Author:
Romain Guay, Taleo Corporation

Constructor Summary
FileUtils()
           
 
Method Summary
static java.io.File createTempFile(java.lang.String folder, java.lang.String prefix)
          Create a temporary file using the specified folder path and filename prefix.
static java.io.File createTempFile(java.lang.String folder, java.lang.String prefix, boolean deleteOnExit)
          Create a temporary file using the specified folder path and filename prefix and a flag to indicate delete on exit.
static int getLineCount(java.io.File file)
          Get the line count.
static java.io.File[] getMatchingFiles(java.io.File pattern)
          Get files matching a pattern.
static java.lang.String readFileToString(java.io.File file, java.lang.String encoding)
          Return the file content as a String.
static java.lang.String sanitizeFilename(java.lang.String filename)
          Limits the length of a filename to 180 characters.
static void sortFilesByNameAscending(java.io.File[] files, boolean asc)
          Sort an array of files by their name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileUtils

public FileUtils()
Method Detail

createTempFile

public static java.io.File createTempFile(java.lang.String folder,
                                          java.lang.String prefix)
                                   throws java.io.IOException
Create a temporary file using the specified folder path and filename prefix. If the folder specified is null or empty, the file is created in the default system temporary file folder. If the specified folder does not exists the folder will be created. File is not deleted on exit. The suffix is determined by the fact that temporary files are compressed or not, as defined by System property com.taleo.integration.compress.tempfile.

Parameters:
folder - The folder in which to create the file
prefix - The filename prefix.
Returns:
The newly created temporary file.
Throws:
java.io.IOException

createTempFile

public static java.io.File createTempFile(java.lang.String folder,
                                          java.lang.String prefix,
                                          boolean deleteOnExit)
                                   throws java.io.IOException
Create a temporary file using the specified folder path and filename prefix and a flag to indicate delete on exit. The suffix is determined by the fact that temporary files are compressed or not, as defined by System property com.taleo.integration.compress.tempfile.

Parameters:
folder - The folder in which to create the file
prefix - The filename prefix.
deleteOnExit - Delete file on exit.
Returns:
The newly created temporary file.
Throws:
java.io.IOException

sortFilesByNameAscending

public static void sortFilesByNameAscending(java.io.File[] files,
                                            boolean asc)
Sort an array of files by their name.

Parameters:
files - The array of files.
asc - Sort ascending.

sanitizeFilename

public static java.lang.String sanitizeFilename(java.lang.String filename)
Limits the length of a filename to 180 characters. Also replace illegal characters (: \ / * ? | < >) with "_" and all control characters (HEX 00 to 1F) with an empty string.

Parameters:
filename - The filename only, excluding path.
Returns:

getLineCount

public static int getLineCount(java.io.File file)
                        throws java.io.IOException
Get the line count.

Parameters:
filename -
Returns:
Throws:
java.io.IOException

readFileToString

public static java.lang.String readFileToString(java.io.File file,
                                                java.lang.String encoding)
                                         throws java.io.IOException
Return the file content as a String.

Parameters:
file - The file.
encoding - The encoding of the file.
Returns:
Throws:
java.io.IOException

getMatchingFiles

public static java.io.File[] getMatchingFiles(java.io.File pattern)
                                       throws java.io.IOException
Get files matching a pattern.

Parameters:
pattern - The file pattern. If file only, it is considered in the current directory.
Returns:
The list of files matching the pattern. If the parent directory does not exist, return an empty list.
Throws:
java.io.IOException
See Also:
WildcardFileFilter