Package com.shaft.cli
Class FileActions
java.lang.Object
com.shaft.cli.FileActions
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncopyFile
(TerminalActions terminalSession, String sourceDirectory, String destinationDirectory, String fileName) Copies files from sourceDirectory to destinationDirectory using the provided terminalSession.void
Copies a file from sourceFilePath to destinationFilePath on the local storagevoid
copyFileFromJar
(String sourceFolderPath, String destinationFolderPath, String fileName) copyFileToLocalMachine
(TerminalActions terminalSession, String targetFileFolderPath, String targetFileName, String... pathToTempDirectoryOnRemoteMachine) This method is used to copy a certain file from a remote machine (dockerized or not) to the current execution machine.void
copyFolder
(String sourceFolderPath, String destinationFolderPath) void
copyFolderFromJar
(String sourceFolderPath, String destinationFolderPath) void
createFile
(String folderPath, String fileName) void
createFolder
(String folderPath) void
deleteFile
(String targetFilePath) Deletes a file from the local storagevoid
deleteFolder
(String folderPath) boolean
doesFileExist
(String targetFile) boolean
doesFileExist
(String fileFolderName, String fileName, int numberOfRetries) Tests whether the file or directory denoted by this abstract pathname exists.downloadFile
(String targetFileURL, String destinationFilePath) downloadFile
(String targetFileURL, String destinationFilePath, int connectionTimeout, int readTimeout) getAbsolutePath
(String relativePath) Returns the full (absolute) file/folder path using the project-relative relativePathgetAbsolutePath
(String fileFolderName, String fileName) Returns the full (absolute) file/folder path using the project-relative fileFolderName and the fileNamegetFileChecksum
(TerminalActions terminalSession, String targetFileFolderPath, String targetFileName, String... pathToTempDirectoryOnRemoteMachine) This method is used to compute the SHA256 checksum for any file.getFileList
(String targetDirectory) static FileActions
static FileActions
getInstance
(boolean internalInstance) listFilesInDirectory
(TerminalActions terminalSession, String targetDirectory) Lists all files inside the targetDirectorylistFilesInDirectory
(String targetDirectory) listFilesInDirectory
(String targetDirectory, org.apache.commons.io.filefilter.TrueFileFilter recursively) byte[]
readFileAsByteArray
(String pathToTargetImage) void
renameFile
(String filePath, String newFileName) unpackArchive
(URL url, String destinationFolderPath) void
writeToFile
(String filePath, byte[] content) void
writeToFile
(String filePath, String text) void
writeToFile
(String fileFolderName, String fileName, byte[] content) void
writeToFile
(String fileFolderName, String fileName, String text) void
writeToFile
(String fileFolderName, String fileName, List<String> text) boolean
-
Constructor Details
-
FileActions
public FileActions()
-
-
Method Details
-
getInstance
-
getInstance
-
copyFile
Copies a file from sourceFilePath to destinationFilePath on the local storage- Parameters:
sourceFilePath
- the full (absolute) path of the source file that will be copieddestinationFilePath
- the full (absolute) path of the desired location and file name for the newly created copied file
-
renameFile
-
copyFile
public String copyFile(TerminalActions terminalSession, String sourceDirectory, String destinationDirectory, String fileName) Copies files from sourceDirectory to destinationDirectory using the provided terminalSession. References: computer hope/unix/ucp.htm robocopy- Parameters:
terminalSession
- an object that determines the type of terminalSession which will be used to execute this File ActionsourceDirectory
- full path to the sourceDirectorydestinationDirectory
- full path to the destinationDirectoryfileName
- target fileName- Returns:
- a string value that holds the result of this terminal command
-
listFilesInDirectory
-
listFilesInDirectory
-
getFileList
-
listFilesInDirectory
Lists all files inside the targetDirectory- Parameters:
terminalSession
- an object that determines the type of terminalSession which will be used to execute this File ActiontargetDirectory
- full path to the targetDirectory- Returns:
- a string value that holds the result of this terminal command
-
getFileChecksum
public String getFileChecksum(TerminalActions terminalSession, String targetFileFolderPath, String targetFileName, String... pathToTempDirectoryOnRemoteMachine) This method is used to compute the SHA256 checksum for any file. This checksum can be used to compare two files and confirm that they are identical, regardless of the file type.- Parameters:
terminalSession
- provides information about the machine which contains the target filetargetFileFolderPath
- the full absolute path of the folder that contains the target file, must end with a slash "/"targetFileName
- the name and extension of the target filepathToTempDirectoryOnRemoteMachine
- [OPTIONAL] to be used in case of dockerized target machine. This is a temporary directory that will be created on the remote machine to extract a file from inside a docker, and will be deleted afterward- Returns:
- a string that holds the SHA256 checksum for the target file
-
copyFileToLocalMachine
public String copyFileToLocalMachine(TerminalActions terminalSession, String targetFileFolderPath, String targetFileName, String... pathToTempDirectoryOnRemoteMachine) This method is used to copy a certain file from a remote machine (dockerized or not) to the current execution machine.- Parameters:
terminalSession
- provides information about the machine which contains the target filetargetFileFolderPath
- the full absolute path of the folder that contains the target file, must end with a slash "/"targetFileName
- the name and extension of the target filepathToTempDirectoryOnRemoteMachine
- [OPTIONAL] to be used in case of dockerized target machine. This is a temporary directory that will be created on the remote machine to extract a file from inside a docker, and will be deleted afterward- Returns:
- a string that holds the full absolute path (inside a temporary folder) for the file that was copied to the local machine
-
deleteFile
Deletes a file from the local storage- Parameters:
targetFilePath
- the full (absolute) path of the source file that will be deleted
-
writeToFile
-
writeToFile
-
writeToFile
-
writeToFile
-
writeToFile
-
readPDF
-
readPDF
-
readFile
-
readFileAsByteArray
-
readFile
-
doesFileExist
Tests whether the file or directory denoted by this abstract pathname exists.- Parameters:
fileFolderName
- The location of the folder that contains the target file, relative to the project's root folder, ending with a /fileName
- The name of the target file (including its extension if any)numberOfRetries
- number of times to try to find the file, given that each retry is separated by a 500 millisecond wait time- Returns:
- true if the file exists, false if it doesn't
-
doesFileExist
-
getAbsolutePath
Returns the full (absolute) file/folder path using the project-relative fileFolderName and the fileName- Parameters:
fileFolderName
- The location of the folder that contains the target file, relative to the project's root directory, ending with a /fileName
- The name of the target file (including its extension if any)- Returns:
- a string value that represents the full/absolute file/folder path
-
getAbsolutePath
Returns the full (absolute) file/folder path using the project-relative relativePath- Parameters:
relativePath
- The location of the target file or folder, relative to the project's root directory, ending with a / if it's a folder- Returns:
- a string value that represents the full/absolute file/folder path
-
copyFolder
-
copyFolderFromJar
-
copyFileFromJar
-
deleteFolder
-
createFolder
-
createFile
-
zipFiles
-
unpackArchive
-
downloadFile
-
downloadFile
-