Class FileUtils


  • public class FileUtils
    extends Object
    • Constructor Detail

      • FileUtils

        public FileUtils()
    • Method Detail

      • copyFile

        public static boolean copyFile​(String source,
                                       String destination)
                                throws Exception
        Copies a file
        Parameters:
        source - file
        destination - 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 directory
        fileName - - 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 files
        desDir - - Destination directory to remove files
      • 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 property
        name - name of the property
        value - 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 file
        property - property name of the property for the list
        value - 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 number
        numLines - 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 a java.util.Properties object
        Parameters:
        configPath - path to the properties file
        Returns:
        prop a java.util.Properties object from the specified file or null in 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/folder
        level - 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
      • getParentDirPath

        public static String getParentDirPath​(String path)
        Returns the parent folder of the given file/folder
        Parameters:
        path - path to a file/folder
        Returns:
        path to the parent, it may be null, if there is no parent.