Class FileUtils

java.lang.Object
com.nt.udc.util.FileUtils

public class FileUtils extends Object
  • Constructor Details

    • FileUtils

      public FileUtils()
  • Method Details

    • getRelativeFile

      public static File getRelativeFile(File dir, File file) throws FileNotFoundException
      Returns a file whose path is the relative path to that of the given directory.
      Throws:
      FileNotFoundException
    • getAllFiles

      public static Set getAllFiles(File dir)
      Given a directory, return the set of files in that directory.
    • getRelativeFiles

      public static Set getRelativeFiles(Set files, File dir)
    • dirname

      public static String dirname(String filename)
      Returns the directory path portion of a specific file string. e.g. test.txt --> "" /tmp/dir1/test.txt --> /tmp/dir1
      Parameters:
      filename -
      Returns:
      the directory portion excluding the ending file separator.
    • filename

      public static String filename(String filename)
      Returns the filename portion of a specific file string. e.g. test.txt, .txt --> test.txt /tmp/dir1/test.txt, .txt --> test.txt
      Parameters:
      filename -
      Returns:
      the filename string with extension.
    • basename

      public static String basename(String filename)
      Returns the filename portion of a specific file string. e.g. test.txt, .txt --> test. /tmp/dir1/test.txt --> test.
      Parameters:
      filename -
      Returns:
      The filename string without extension
    • basename

      public static String basename(String filename, String suffix)
      Returns the filename portion of a specific file string. e.g. test.txt, .txt --> test /tmp/dir1/test.txt --> test
      Parameters:
      filename -
      suffix -
      Returns:
      the filename portion (no path and no extension) of a specific file string .
    • extension

      public static String extension(String filename)
      Returns the extension portion of a specific file string. e.g. test.txt --> txt /tmp/dir1/test.txt --> txt
      Parameters:
      filename -
      Returns:
      the extension portion of a specific file string.
    • removeExtension

      public static String removeExtension(String filename)
      Remove extension from filename. e.g. test.txt --> test /tmp/test.txt --> /tmp/test /tmp/dir1/dir2 --> /tmp/dir1/dir2 /tmp/dir1/dir2/ --> /tmp/dir1/dir2/
      Parameters:
      filename - the filename
      Returns:
      the filename minus extension
    • getExtension

      public static String getExtension(String filename)
      Get extension from filename. e.g. test.txt --> txt /tmp/test.txt --> txt /tmp/dir1/dir2 --> ""
      Parameters:
      filename - the filename
      Returns:
      the extension of filename or "" if none
    • removePath

      public static String removePath(String filepath)
      Remove path from filename. e.g. test.txt --> test.txt /tmp/dir1/test.txt --> test.txt
      Parameters:
      filepath - the filepath
      Returns:
      the filename minus path
    • removePath

      public static String removePath(String filepath, char fileSeparatorChar)
      Remove path from filename. e.g. test.txt --> test.txt /tmp/dir1/test.txt --> test.txt
      Parameters:
      filepath - - the file path
      Returns:
      the filename minus path
    • getPath

      public static String getPath(String filepath)
      Get path from filename. ie. a/b/c.txt --> a/b a.txt --> ""
      Parameters:
      filepath - the filepath
      Returns:
      the filename minus path
    • getPath

      public static String getPath(String filepath, char fileSeparatorChar)
      Get path from filename. ie. test.txt --> "" /tmp/dir1/test.txt --> /tmp/dir1
      Parameters:
      filepath - the filepath
      Returns:
      the filename minus path
    • copyFileToDirectory

      public static void copyFileToDirectory(String sourceFile, String destDirectory) throws Exception
      Copy file from source to destination.
      Parameters:
      sourceFile - - the source file to been copy.
      destDirectory - - the destination directory to copy to.
      Throws:
      Exception
    • copyFileToDirectory

      public static void copyFileToDirectory(File sourceFile, File destDirectory) throws Exception
      Copy file from source to destination.
      Parameters:
      sourceFile - - the source file to been copy.
      destDirectory - - the destination directory to copy to.
      Throws:
      Exception
    • copyDirectory

      public static void copyDirectory(File sourceDirectory, File destDirectory) throws Exception
      Copy file from source directory to destination directory.
      Parameters:
      sourceDirectory - - source directory to copy from.
      destDirectory - - destination directory to copy to.
      Throws:
      Exception
    • copyDirectory

      public static void copyDirectory(String sourceDirectory, String destDirectory) throws Exception
      Copy file from source directory to destination directory.
      Parameters:
      sourceDirectory - - source directory to copy from.
      destDirectory - - destination directory to copy to.
      Throws:
      Exception
    • copyFile

      public static void copyFile(File sourceFile, File destFile) throws Exception
      Copy file from source to destination.
      Parameters:
      sourceFile - - the source file to copy.
      destFile - - the destination file to copy to.
      Throws:
      Exception
    • copyFile

      public static void copyFile(String sourceFile, String destFile) throws Exception
      Copy file from source to destination.
      Parameters:
      sourceFile - - the source file to copy.
      destFile - - the destination file to copy to.
      Throws:
      Exception
    • isValidFileName

      public static boolean isValidFileName(String fileName)
      Validates file name.
      Parameters:
      fileName - - the file name to be validated
      Returns:
      result of file name validation - true if valid filename otherwise false will be returned
    • isValidDirectory

      public static boolean isValidDirectory(String dirName)
      Validates directory name.
      Parameters:
      dirName - - the directory name to be validated
      Returns:
      result of directory name validation - true if valid directory otherwise false will be returned
    • isValidFileAndPath

      public static boolean isValidFileAndPath(String fileNameAndPath)
      Validates filename with wildcard and path
      Parameters:
      fileNameAndPath - - the filename with wildcard and path to be validated
      Returns:
      result of filename with path validation - true if valid otherwise false will be returned
    • zipFiles

      public static boolean zipFiles(String[] fileNames, String zipFile, String destFolder, boolean storePath, String osaHome)
      Creates compressed archive of files passed to it and stores the archive into the specified folder.
      Parameters:
      fileNames - array of filenames or folder names which need to compressed.
      zipFile - the name of file in which the compressed archive will be stored.
      destFolder - the folder name where the compressed archive will be stored.
      storePath - true if file path should be stored in the archive otherwise false.
      osaHome - the path where Network Mediation is installed.
      Returns:
      boolean returns true if all files are compressed and archived successfully otherwise returns false
    • unZipFiles

      public static boolean unZipFiles(String fileName, String destFolder, String osaHome)
      Extracts contents a compressed file into the specified folder.
      Parameters:
      fileName - the compressed file
      destFolder - the folder where the compressed file should be extracted.
      Returns:
      boolean true if all contents are extracted successfully. otherwise false.
    • uploadFile

      public static void uploadFile(byte[] data, String uploadLocation, String fileName) throws FileNotFoundException, IOException
      Uploads the file with given file name to the given upload location.
      Parameters:
      data - File's data
      uploadLocation - Location where file needs to be uploaded
      fileName - File's name
      Throws:
      FileNotFoundException - Exception thrown when file is not found
      IOException - Exception thrown while writing to the file
    • deleteDirectory

      public static boolean deleteDirectory(Path directory) throws IOException
      Throws:
      IOException