Interface FileCopierUtil

  • All Known Implementing Classes:
    DefaultFileCopierUtil

    public interface FileCopierUtil
    Created by greg on 7/15/16.
    • Method Detail

      • writeScriptTempFile

        java.io.File writeScriptTempFile​(ExecutionContext context,
                                         java.io.File original,
                                         java.io.InputStream input,
                                         java.lang.String script,
                                         INodeEntry node,
                                         boolean expandTokens)
                                  throws FileCopierException
        Copy a script file, script source stream, or script string into a temp file, and replace \ embedded tokens with values from the dataContext for the latter two. Marks the file as executable and delete-on-exit. This will not rewrite any content if the input is originally a file.
        Parameters:
        context - execution context
        original - local system file, or null
        input - input stream to write, or null
        script - file content string, or null
        node - destination node entry, to provide node data context
        expandTokens - if true, expand tokens in the stream or string
        Returns:
        file where the script was stored, this file should later be cleaned up by calling ScriptfileUtils.releaseTempFile(java.io.File)
        Throws:
        FileCopierException - if an IO problem occurs
      • writeScriptTempFile

        java.io.File writeScriptTempFile​(ExecutionContext context,
                                         java.io.File original,
                                         java.io.InputStream input,
                                         java.lang.String script,
                                         INodeEntry node,
                                         java.io.File destination,
                                         boolean expandTokens)
                                  throws FileCopierException
        Copy a script file, script source stream, or script string into a temp file, and replace \ embedded tokens with values from the dataContext for the latter two. Marks the file as executable and delete-on-exit. This will not rewrite any content if the input is originally a file.
        Parameters:
        context - execution context
        original - local system file, or null
        input - input stream to write, or null
        script - file content string, or null
        node - destination node entry, to provide node data context
        destination - destination file, or null to generate a new temp file
        expandTokens - if true, expand tokens in the stream or string
        Returns:
        file where the script was stored
        Throws:
        FileCopierException - if an IO problem occurs
      • defaultRemoteFileExtensionForNode

        java.lang.String defaultRemoteFileExtensionForNode​(INodeEntry node)
        Parameters:
        node - node
        Returns:
        the default file extension for a temp file based on the type of node
      • appendRemoteFileExtension

        java.lang.String appendRemoteFileExtension​(java.lang.String filepath,
                                                   java.lang.String fileext)
        Parameters:
        filepath - the file path string
        fileext - the file extension, if it does not start with a "." one will be prepended first. If null, the unmodified filepath will be returned.
        Returns:
        a string with a file extension appended if it is not already on the file path provided.
      • getRemoteDirForNode

        java.lang.String getRemoteDirForNode​(INodeEntry node)
        Return a remote destination temp dir path for the given node. If specified, the node attribute named is used, otherwise a temp directory appropriate for the os-family of the node is returned.
        Parameters:
        node - the node entry
        Returns:
        a path to destination dir for the node
      • getRemoteDirForNode

        java.lang.String getRemoteDirForNode​(INodeEntry node,
                                             IRundeckProject project,
                                             IFramework framework)
        Return a remote destination temp dir path for the given node. If specified, the node attribute named is used, otherwise a temp directory appropriate for the os-family of the node is returned.
        Parameters:
        node - the node entry
        project - project
        framework - framework
        Returns:
        a path to destination dir for the node
      • generateRemoteFilepathForNode

        java.lang.String generateRemoteFilepathForNode​(INodeEntry node,
                                                       java.lang.String scriptfileName)
        Return a temporary filepath for a file to be copied to the node, given the input filename (without directory path)
        Parameters:
        node - the destination node
        scriptfileName - the name of the file to copy
        Returns:
        a filepath specifying destination of the file to copy that should be unique for the node and current date.
      • generateRemoteFilepathForNode

        java.lang.String generateRemoteFilepathForNode​(INodeEntry node,
                                                       java.lang.String scriptfileName,
                                                       java.lang.String fileExtension)
        Return a temporary filepath for a file to be copied to the node, given the input filename (without directory path)
        Parameters:
        node - the destination node
        scriptfileName - the name of the file to copy
        fileExtension - optional extension to use for the temp file, or null for default
        Returns:
        a filepath specifying destination of the file to copy that should be unique
      • generateRemoteFilepathForNode

        java.lang.String generateRemoteFilepathForNode​(INodeEntry node,
                                                       java.lang.String scriptfileName,
                                                       java.lang.String fileExtension,
                                                       java.lang.String identity)
        Return a temporary filepath for a file to be copied to the node, given the input filename (without directory path)
        Parameters:
        node - the destination node
        scriptfileName - the name of the file to copy
        fileExtension - optional extension to use for the temp file, or null for default
        identity - unique identifier, or null to include a random string
        Returns:
        a filepath specifying destination of the file to copy that should be unique
      • generateRemoteFilepathForNode

        java.lang.String generateRemoteFilepathForNode​(INodeEntry node,
                                                       IRundeckProject project,
                                                       IFramework framework,
                                                       java.lang.String scriptfileName,
                                                       java.lang.String fileExtension,
                                                       java.lang.String identity)
        Return a temporary filepath for a file to be copied to the node, given the input filename (without directory path)
        Parameters:
        node - the destination node
        project - project
        framework - framework
        scriptfileName - the name of the file to copy
        fileExtension - optional extension to use for the temp file, or null for default
        identity - unique identifier, or null to include a random string
        Returns:
        a filepath specifying destination of the file to copy that should be unique
      • writeTempFile

        java.io.File writeTempFile​(ExecutionContext context,
                                   java.io.File original,
                                   java.io.InputStream input,
                                   java.lang.String script)
                            throws FileCopierException
        Write the file, stream, or text to a local temp file and return the file
        Parameters:
        context - context
        original - source file, or null
        input - source inputstream or null
        script - source text, or null
        Returns:
        temp file, this file should later be cleaned up by calling ScriptfileUtils.releaseTempFile(File)
        Throws:
        FileCopierException - if IOException occurs
      • writeLocalFile

        java.io.File writeLocalFile​(java.io.File original,
                                    java.io.InputStream input,
                                    java.lang.String script,
                                    java.io.File destinationFile)
                             throws FileCopierException
        Parameters:
        original - source file
        input - source stream
        script - source string
        destinationFile - destination
        Returns:
        local file
        Throws:
        FileCopierException - on error