|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.sun.faban.harness.util.FileHelper
public class FileHelper
File utilities. A collection of static methods to deal with file operations.
Constructor Summary | |
---|---|
FileHelper()
|
Method Summary | |
---|---|
static boolean |
copyFile(String srcFile,
String destFile,
boolean append)
Copies a file. |
static boolean |
delete(File dir,
FileFilter filter)
Deletes all files matched by the filter in a certain directory. |
static boolean |
editPropFile(String fileName,
Properties prop,
String backupFileName)
This method opens, traverses through the file and finds the properties and replaces the values This updates only the first occurrence of the prop in the file to eliminate cases where it changes props defined like PROP=$PROP:MYPROP We expect only one prop per line in the file. |
static byte[] |
getContent(File file)
Obtains the whole content of a local file in a byte array. |
static byte[] |
getContent(String file)
Obtains the whole content of a local file in a byte array. |
static boolean |
hasString(File file,
String string)
Checks a file whether it contains the given string. |
static boolean |
isInFile(String fileName,
String token)
This method opens, traverses through the file and finds the token, it will avoid comments when searching. |
static void |
jar(String dir,
String[] fileNames,
String jarPath)
Jars up a directory to a given Jar file. |
static void |
main(String[] args)
Unit test the functionality. |
static String[] |
readArrayContentFromFile(File file)
Obtains the content of a file as a strin array. |
static String |
readContentFromFile(File file)
Reads a whole file and obtains the contents as a formatted string with "\n" seperated. |
static String |
readStringFromFile(File file)
Reads a whole file and obtains the contents as a string. |
static boolean |
recursiveCopy(File src,
File dest)
Copies a file from source to dest. |
static boolean |
recursiveDelete(File file)
This method is used to delete a directory and recursively delete files and subdirectories within it. |
static boolean |
recursiveDelete(File parentDir,
String name)
This method is used to delete a directory and recursively delete files and subdirectories within it. |
static boolean |
tokenReplace(String fileName,
String token,
String replacement,
String backupFileName)
This method opens, traverses through the file and finds the token and replaces it with new value This method updates only the first occurrence of the token in the file to eliminate cases where it changes props defined like PROP=$PROP:MYPROP. |
static void |
unjar(String jarPath,
String outputDir)
Unjars a jar file into an output directory. |
static File |
unjarTmp(File tmpJarFile)
Unjars a temporary jar file xxxx.jar under the directory xxxx in the same path. |
static void |
writeContentToFile(String string,
File file)
Writes the entire content to file. |
static void |
writeStringToFile(String string,
File file)
Writes a string to a file. |
static boolean |
xferFile(String inFile,
String outFile,
boolean move)
Deprecated. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public FileHelper()
Method Detail |
---|
public static boolean copyFile(String srcFile, String destFile, boolean append)
srcFile
- - the full pathname of the source filedestFile
- - the full pathname of the destination fileappend
- - should destination file be appended with source file
public static boolean editPropFile(String fileName, Properties prop, String backupFileName)
fileName
- The full pathname of the fileprop
- Property names and their new valuesbackupFileName
- The file to save a copy before edit, if any
public static boolean tokenReplace(String fileName, String token, String replacement, String backupFileName)
fileName
- The full pathname of the filetoken
- Token to findreplacement
- The replacement stringbackupFileName
- If needed pass a backup file name
public static boolean isInFile(String fileName, String token)
fileName
- The full pathname of the filetoken
- Token to search for
public static boolean recursiveDelete(File file)
file
- The file or directory to delete
public static boolean delete(File dir, FileFilter filter)
dir
- The directory to look for files to deletefilter
- The file name filter
public static boolean recursiveDelete(File parentDir, String name)
parentDir
- The file object corresponding to the parent directoryname
- Name of the directory to be deleted
public static boolean recursiveCopy(File src, File dest)
src
- The source filedest
- The dest file, must not exist before calling method
public static void jar(String dir, String[] fileNames, String jarPath) throws IOException
dir
- The base directory to jar (not included in output)fileNames
- The file names to jar, can be multiplejarPath
- The pathname of the jar file
IOException
- There is a problem jarring uppublic static void unjar(String jarPath, String outputDir) throws IOException
jarPath
- The path to the jar fileoutputDir
- The output directory
IOException
- If there is an error running unjarpublic static File unjarTmp(File tmpJarFile) throws IOException
tmpJarFile
- The temporary jar file
IOException
- If there is an error unjaringpublic static void writeStringToFile(String string, File file) throws IOException
string
- The string to be writtenfile
- The target file
IOException
- If the write failspublic static String readStringFromFile(File file) throws IOException
file
- The file to be read
IOException
- If the read failspublic static void writeContentToFile(String string, File file) throws IOException
string
- file
-
IOException
public static String readContentFromFile(File file) throws IOException
file
-
IOException
public static String[] readArrayContentFromFile(File file) throws IOException
file
-
IOException
@Deprecated public static boolean xferFile(String inFile, String outFile, boolean move)
inFile
- The input file name on the current hostoutFile
- The output file name on the Faban mastermove
- Whether to remove the original file or not
public static byte[] getContent(String file) throws IOException
file
- The file name
IOException
- If the file cannot be read.public static byte[] getContent(File file) throws IOException
file
- The file name
IOException
- If the file cannot be read.public static boolean hasString(File file, String string) throws IOException
file
- The filestring
- The string
IOException
- Problem reading the filepublic static void main(String[] args)
args
- The command line arguments
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |