Package com.shaft.cli

Class FileActions

java.lang.Object
com.shaft.cli.FileActions

public class FileActions extends Object
  • Constructor Details

    • FileActions

      public FileActions()
  • Method Details

    • getInstance

      public static FileActions getInstance()
    • getInstance

      public static FileActions getInstance(boolean internalInstance)
    • copyFile

      public void copyFile(String sourceFilePath, String destinationFilePath)
      Copies a file from sourceFilePath to destinationFilePath on the local storage
      Parameters:
      sourceFilePath - the full (absolute) path of the source file that will be copied
      destinationFilePath - the full (absolute) path of the desired location and file name for the newly created copied file
    • renameFile

      public void renameFile(String filePath, String newFileName)
    • 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 Action
      sourceDirectory - full path to the sourceDirectory
      destinationDirectory - full path to the destinationDirectory
      fileName - target fileName
      Returns:
      a string value that holds the result of this terminal command
    • listFilesInDirectory

      public String listFilesInDirectory(String targetDirectory)
    • listFilesInDirectory

      public String listFilesInDirectory(String targetDirectory, org.apache.commons.io.filefilter.TrueFileFilter recursively)
    • getFileList

      public Collection<File> getFileList(String targetDirectory)
    • listFilesInDirectory

      public String listFilesInDirectory(TerminalActions terminalSession, String targetDirectory)
      Lists all files inside the targetDirectory
      Parameters:
      terminalSession - an object that determines the type of terminalSession which will be used to execute this File Action
      targetDirectory - 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 file
      targetFileFolderPath - 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 file
      pathToTempDirectoryOnRemoteMachine - [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 file
      targetFileFolderPath - 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 file
      pathToTempDirectoryOnRemoteMachine - [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

      public void deleteFile(String targetFilePath)
      Deletes a file from the local storage
      Parameters:
      targetFilePath - the full (absolute) path of the source file that will be deleted
    • writeToFile

      public void writeToFile(String fileFolderName, String fileName, List<String> text)
    • writeToFile

      public void writeToFile(String filePath, byte[] content)
    • writeToFile

      public void writeToFile(String filePath, String text)
    • writeToFile

      public void writeToFile(String fileFolderName, String fileName, byte[] content)
    • writeToFile

      public void writeToFile(String fileFolderName, String fileName, String text)
    • readPDF

      public String readPDF(String fileFolderName, String fileName)
    • readPDF

      public String readPDF(String relativeFilePath)
    • readFile

      public String readFile(String fileFolderName, String fileName)
    • readFileAsByteArray

      public byte[] readFileAsByteArray(String pathToTargetImage)
    • readFile

      public String readFile(String pathToTargetFile)
    • doesFileExist

      public boolean doesFileExist(String fileFolderName, String fileName, int numberOfRetries)
      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

      public boolean doesFileExist(String targetFile)
    • getAbsolutePath

      public String getAbsolutePath(String fileFolderName, String fileName)
      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

      public String getAbsolutePath(String relativePath)
      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

      public void copyFolder(String sourceFolderPath, String destinationFolderPath)
    • copyFolderFromJar

      public void copyFolderFromJar(String sourceFolderPath, String destinationFolderPath)
    • copyFileFromJar

      public void copyFileFromJar(String sourceFolderPath, String destinationFolderPath, String fileName)
    • deleteFolder

      public void deleteFolder(String folderPath)
    • createFolder

      public void createFolder(String folderPath)
    • createFile

      public void createFile(String folderPath, String fileName)
    • zipFiles

      public boolean zipFiles(String srcFolder, String destZipFile)
    • unpackArchive

      public File unpackArchive(URL url, String destinationFolderPath)
    • downloadFile

      public URL downloadFile(String targetFileURL, String destinationFilePath)
    • downloadFile

      public URL downloadFile(String targetFileURL, String destinationFilePath, int connectionTimeout, int readTimeout)