Package com.nt.udc.util
Class FileUtils
java.lang.Object
com.nt.udc.util.FileUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
Returns the filename portion of a specific file string.static String
Returns the filename portion of a specific file string.static void
copyDirectory
(File sourceDirectory, File destDirectory) Copy file from source directory to destination directory.static void
copyDirectory
(String sourceDirectory, String destDirectory) Copy file from source directory to destination directory.static void
Copy file from source to destination.static void
Copy file from source to destination.static void
copyFileToDirectory
(File sourceFile, File destDirectory) Copy file from source to destination.static void
copyFileToDirectory
(String sourceFile, String destDirectory) Copy file from source to destination.static boolean
deleteDirectory
(Path directory) static String
Returns the directory path portion of a specific file string.static String
Returns the extension portion of a specific file string.static String
Returns the filename portion of a specific file string.static Set
getAllFiles
(File dir) Given a directory, return the set of files in that directory.static String
getExtension
(String filename) Get extension from filename.static String
Get path from filename.static String
Get path from filename.static File
getRelativeFile
(File dir, File file) Returns a file whose path is the relative path to that of the given directory.static Set
getRelativeFiles
(Set files, File dir) static boolean
isValidDirectory
(String dirName) Validates directory name.static boolean
isValidFileAndPath
(String fileNameAndPath) Validates filename with wildcard and pathstatic boolean
isValidFileName
(String fileName) Validates file name.static String
removeExtension
(String filename) Remove extension from filename.static String
removePath
(String filepath) Remove path from filename.static String
removePath
(String filepath, char fileSeparatorChar) Remove path from filename.static boolean
unZipFiles
(String fileName, String destFolder, String osaHome) Extracts contents a compressed file into the specified folder.static void
uploadFile
(byte[] data, String uploadLocation, String fileName) Uploads the file with given file name to the given upload location.static boolean
Creates compressed archive of files passed to it and stores the archive into the specified folder.
-
Constructor Details
-
FileUtils
public FileUtils()
-
-
Method Details
-
getRelativeFile
Returns a file whose path is the relative path to that of the given directory.- Throws:
FileNotFoundException
-
getAllFiles
Given a directory, return the set of files in that directory. -
getRelativeFiles
-
dirname
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
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
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
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
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
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
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
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
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
Get path from filename. ie. a/b/c.txt --> a/b a.txt --> ""- Parameters:
filepath
- the filepath- Returns:
- the filename minus path
-
getPath
Get path from filename. ie. test.txt --> "" /tmp/dir1/test.txt --> /tmp/dir1- Parameters:
filepath
- the filepath- Returns:
- the filename minus path
-
copyFileToDirectory
Copy file from source to destination.- Parameters:
sourceFile
- - the source file to been copy.destDirectory
- - the destination directory to copy to.- Throws:
Exception
-
copyFileToDirectory
Copy file from source to destination.- Parameters:
sourceFile
- - the source file to been copy.destDirectory
- - the destination directory to copy to.- Throws:
Exception
-
copyDirectory
Copy file from source directory to destination directory.- Parameters:
sourceDirectory
- - source directory to copy from.destDirectory
- - destination directory to copy to.- Throws:
Exception
-
copyDirectory
Copy file from source directory to destination directory.- Parameters:
sourceDirectory
- - source directory to copy from.destDirectory
- - destination directory to copy to.- Throws:
Exception
-
copyFile
Copy file from source to destination.- Parameters:
sourceFile
- - the source file to copy.destFile
- - the destination file to copy to.- Throws:
Exception
-
copyFile
Copy file from source to destination.- Parameters:
sourceFile
- - the source file to copy.destFile
- - the destination file to copy to.- Throws:
Exception
-
isValidFileName
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
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
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
Extracts contents a compressed file into the specified folder.- Parameters:
fileName
- the compressed filedestFolder
- 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 datauploadLocation
- Location where file needs to be uploadedfileName
- File's name- Throws:
FileNotFoundException
- Exception thrown when file is not foundIOException
- Exception thrown while writing to the file
-
deleteDirectory
- Throws:
IOException
-