Class FileUtils
- java.lang.Object
-
- com.sun.identity.install.tools.util.FileUtils
-
public class FileUtils extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static StringEQUAL_TOField HASH *static StringEXAMPLE_FIELDField EXAMPLE_FIELD *static StringHASHField HASH *static StringSPACEField HASH *static StringSQRBRACKET_CLOSEField SQRBRACKET_CLOSE *static StringSQRBRACKET_OPENField SQRBRACKET_OPEN *
-
Constructor Summary
Constructors Constructor Description FileUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanaddListProperty(String fileName, String property, String value)Adds an entry to a list property in Product Config propertiesstatic booleanaddMapProperty(String configPath, String key, String name, String value)Method addMapProperty Adds a map property like key[name]=value in PRODUCT Config.propertiesstatic voidappendDataToFile(String fileName, String data)static booleanappendLinesToFile(String filePath, String[] linesToAppend)Appends the given set of lines to the specified file.static booleanappendLinesToFile(String filePath, String[] linesToAppend, boolean create)Appends the given set of lines to the specified file.static voidbackupFile(String fileName, String suffix)static voidcopyDirContents(File srcDir, File destDir)Method copyDirContentsstatic booleancopyFile(String source, String destination)Copies a filestatic voidcopyJarFile(String srcDir, String destDir, String filename)Method copyJarFile to destination directorystatic intgetFirstOccurence(String filePath, String pattern, boolean matchBegin, boolean matchEnd, boolean ignoreCase)Method getFirstOccurencestatic intgetFirstOccurence(String filePath, String pattern, boolean matchBegin, boolean matchEnd, boolean ignoreCase, int beginAtLine)Method getFirstOccurencestatic intgetLastOccurence(String filePath, String pattern, boolean matchBegin, boolean matchEnd, boolean ignoreCase)Method getLastOccurencestatic StringgetLineByNumber(String filePath, int lineNum)Method getLineByNumberstatic StringgetLineWithPattern(String filePath, String pattern, boolean matchBegin, boolean matchEnd, boolean ignoreCase, int beginAtLine)Method getLineWithPatternstatic StringgetParentDirPath(String path)Returns the parent folder of the given file/folderstatic StringgetParentDirPath(String path, int level)Returns the parent folder upper level count to the current pathstatic PropertiesgetProperties(String configPath)Method getProperties Loads a properties file into memory and creates ajava.util.Propertiesobjectstatic intgetTotalLineNums(String fileName)Method declarationstatic booleaninsertLineByNumber(String filePath, int lineNum, String line)Method insertLineByNumberstatic booleanisDirValid(String directory)static booleanisFileValid(String filename)static booleanmatchPattern(String line, String pattern, boolean matchBegin, boolean matchEnd, boolean ignoreCase)Method matchPatternstatic booleanremoveDir(File dir)Method removeDir.static voidremoveFiles(String srcDir, String desDir)Method removeFiles.static voidremoveJarFiles(String srcDir, String fileName)Method removeJarFiles. jar files will be removed from source directorystatic voidremoveLines(String fileName, String value)static booleanremoveLinesByNum(String filePath, int lineNum, int numLines)Method removeLinesByNumstatic StringremoveLinesByNumber(String filePath, int lineNum, int numLines)Method removeLinesByNumberstatic StringreplaceBackWithForward(String str)Method replaceBackWithForward
-
-
-
Field Detail
-
SQRBRACKET_OPEN
public static final String SQRBRACKET_OPEN
Field SQRBRACKET_OPEN *- See Also:
- Constant Field Values
-
SQRBRACKET_CLOSE
public static final String SQRBRACKET_CLOSE
Field SQRBRACKET_CLOSE *- See Also:
- Constant Field Values
-
EXAMPLE_FIELD
public static final String EXAMPLE_FIELD
Field EXAMPLE_FIELD *- See Also:
- Constant Field Values
-
HASH
public static final String HASH
Field HASH *- See Also:
- Constant Field Values
-
EQUAL_TO
public static final String EQUAL_TO
Field HASH *- See Also:
- Constant Field Values
-
SPACE
public static final String SPACE
Field HASH *- See Also:
- Constant Field Values
-
-
Method Detail
-
copyFile
public static boolean copyFile(String source, String destination) throws Exception
Copies a file- Parameters:
source- filedestination- file- Returns:
- true if copy operation succeed
- Throws:
Exception
-
copyJarFile
public static void copyJarFile(String srcDir, String destDir, String filename) throws Exception
Method copyJarFile to destination directory- Parameters:
srcDir-destDir-filename-- Throws:
Exception
-
copyDirContents
public static void copyDirContents(File srcDir, File destDir) throws Exception
Method copyDirContents- Parameters:
srcDir-destDir-- Throws:
Exception
-
removeDir
public static boolean removeDir(File dir)
Method removeDir. All the files in the directory will be removed- Parameters:
dir- to be removed. @ return true if the directory is deleted. False other wise
-
removeJarFiles
public static void removeJarFiles(String srcDir, String fileName)
Method removeJarFiles. jar files will be removed from source directory- Parameters:
srcDir- - Source directoryfileName- - file to be deleted
-
removeFiles
public static void removeFiles(String srcDir, String desDir)
Method removeFiles. All the files existing in source directory will be removed from Destination Directory- Parameters:
srcDir- - Source directory to compare filesdesDir- - Destination directory to remove files
-
removeLines
public static void removeLines(String fileName, String value) throws Exception
- Throws:
Exception
-
appendDataToFile
public static void appendDataToFile(String fileName, String data) throws Exception
- Throws:
Exception
-
backupFile
public static void backupFile(String fileName, String suffix) throws Exception
- Throws:
Exception
-
isFileValid
public static boolean isFileValid(String filename)
-
replaceBackWithForward
public static String replaceBackWithForward(String str)
Method replaceBackWithForward- Parameters:
str-- Returns:
-
isDirValid
public static boolean isDirValid(String directory)
-
getLineByNumber
public static String getLineByNumber(String filePath, int lineNum)
Method getLineByNumber- Parameters:
filePath-lineNum-- Returns:
-
matchPattern
public static boolean matchPattern(String line, String pattern, boolean matchBegin, boolean matchEnd, boolean ignoreCase)
Method matchPattern- Parameters:
line-pattern-matchBegin-matchEnd-ignoreCase-- Returns:
-
getLineWithPattern
public static String getLineWithPattern(String filePath, String pattern, boolean matchBegin, boolean matchEnd, boolean ignoreCase, int beginAtLine)
Method getLineWithPattern- Parameters:
filePath-pattern-matchBegin-matchEnd-ignoreCase-beginAtLine-- Returns:
-
getFirstOccurence
public static int getFirstOccurence(String filePath, String pattern, boolean matchBegin, boolean matchEnd, boolean ignoreCase, int beginAtLine)
Method getFirstOccurence- Parameters:
filePath-pattern-matchBegin-matchEnd-ignoreCase-beginAtLine-- Returns:
-
getFirstOccurence
public static int getFirstOccurence(String filePath, String pattern, boolean matchBegin, boolean matchEnd, boolean ignoreCase)
Method getFirstOccurence- Parameters:
filePath-pattern-matchBegin-matchEnd-ignoreCase-- Returns:
-
getLastOccurence
public static int getLastOccurence(String filePath, String pattern, boolean matchBegin, boolean matchEnd, boolean ignoreCase)
Method getLastOccurence- Parameters:
filePath-pattern-matchBegin-matchEnd-ignoreCase-- Returns:
-
addMapProperty
public static boolean addMapProperty(String configPath, String key, String name, String value)
Method addMapProperty Adds a map property like key[name]=value in PRODUCT Config.properties- Parameters:
key- key name of the propertyname- name of the propertyvalue- value of the property
-
addListProperty
public static boolean addListProperty(String fileName, String property, String value)
Adds an entry to a list property in Product Config properties- Parameters:
fileName- name of the config fileproperty- property name of the property for the listvalue- name of the list property to be added Ex: Adds a property like property[index] = value in Product Config properties- Returns:
- boolean true or false
-
getTotalLineNums
public static int getTotalLineNums(String fileName)
Method declaration- Parameters:
fileName-- Returns:
-
insertLineByNumber
public static boolean insertLineByNumber(String filePath, int lineNum, String line)
Method insertLineByNumber- Parameters:
filePath-lineNum-line-- Returns:
-
removeLinesByNum
public static boolean removeLinesByNum(String filePath, int lineNum, int numLines)
Method removeLinesByNum- Parameters:
filePath-lineNum- begining line numbernumLines- total number of lines to remove- Returns:
- true if removal is successful
-
removeLinesByNumber
public static String removeLinesByNumber(String filePath, int lineNum, int numLines)
Method removeLinesByNumber- Parameters:
filePath-lineNum-numLines-- Returns:
-
appendLinesToFile
public static boolean appendLinesToFile(String filePath, String[] linesToAppend)
Appends the given set of lines to the specified file.- Parameters:
filePath-linesToAppend-- Returns:
- true for success, false otherwise
-
appendLinesToFile
public static boolean appendLinesToFile(String filePath, String[] linesToAppend, boolean create)
Appends the given set of lines to the specified file.- Parameters:
filePath-linesToAppend-create- should the file be created if it does not exist- Returns:
- true for success, false otherwise
-
getProperties
public static Properties getProperties(String configPath)
Method getProperties Loads a properties file into memory and creates ajava.util.Propertiesobject- Parameters:
configPath- path to the properties file- Returns:
- prop a
java.util.Propertiesobject from the specified file ornullin case of an error in processing
-
getParentDirPath
public static String getParentDirPath(String path, int level)
Returns the parent folder upper level count to the current path- Parameters:
path- path to a file/folderlevel- how much should we go upper in the path- Returns:
- path to the parent upper the given level, for example: (/a/b/c/d, 3) will result in /a
-
-