Class ScriptfileUtils


  • public class ScriptfileUtils
    extends java.lang.Object
    Utility methods for writing temp files for scripts and setting file permissions.
    • Constructor Detail

      • ScriptfileUtils

        public ScriptfileUtils()
    • Method Detail

      • lineEndingStyleForNode

        public static ScriptfileUtils.LineEndingStyle lineEndingStyleForNode​(INodeEntry node)
        Parameters:
        node - node
        Returns:
        the line ending style for the node, based on the osFamily, or use LOCAL if undetermined
      • shouldAddBomForNode

        public static boolean shouldAddBomForNode​(INodeEntry node)
      • writeScriptTempfile

        public static java.io.File writeScriptTempfile​(Framework framework,
                                                       java.io.Reader source,
                                                       ScriptfileUtils.LineEndingStyle style)
                                                throws java.io.IOException
        Copy reader content to a tempfile for script execution
        Parameters:
        framework - framework
        source - string content
        style - style
        Returns:
        tempfile
        Throws:
        java.io.IOException - if an error occurs
      • writeScriptTempfile

        public static java.io.File writeScriptTempfile​(Framework framework,
                                                       java.io.InputStream stream,
                                                       java.lang.String source,
                                                       java.io.Reader reader,
                                                       ScriptfileUtils.LineEndingStyle style)
                                                throws java.io.IOException
        Copy a source stream or string content to a tempfile for script execution
        Parameters:
        framework - framework
        stream - source stream
        source - content
        style - file line ending style to use
        reader - reader
        Returns:
        tempfile
        Throws:
        java.io.IOException - if an error occurs
      • writeScriptFile

        public static void writeScriptFile​(java.io.InputStream stream,
                                           java.lang.String scriptString,
                                           java.io.Reader reader,
                                           ScriptfileUtils.LineEndingStyle style,
                                           java.io.File scriptfile,
                                           boolean addBom)
                                    throws java.io.IOException
        Write script content to a destination file from one of the sources
        Parameters:
        stream - stream source
        scriptString - script content
        reader - reader source
        style - line ending style
        scriptfile - destination file
        Throws:
        java.io.IOException - on io error
      • writeScriptFile

        public static void writeScriptFile​(java.io.InputStream stream,
                                           java.lang.String scriptString,
                                           java.io.Reader reader,
                                           ScriptfileUtils.LineEndingStyle style,
                                           java.io.File scriptfile)
                                    throws java.io.IOException
        Write script content to a destination file from one of the sources
        Parameters:
        stream - stream source
        scriptString - script content
        reader - reader source
        style - line ending style
        scriptfile - destination file
        Throws:
        java.io.IOException - on io error
      • createTempFile

        public static java.io.File createTempFile​(Framework framework)
                                           throws java.io.IOException
        Creates a temp file and marks it for deleteOnExit, to clean up proactively call releaseTempFile(java.io.File) with the result when complete
        Parameters:
        framework - fwk
        Returns:
        Create a temp file in the framework
        Throws:
        java.io.IOException - on io error
      • setExecutePermissions

        public static void setExecutePermissions​(java.io.File scriptfile)
                                          throws java.io.IOException
        Set the executable flag on a file if supported by the OS
        Parameters:
        scriptfile - target file
        Throws:
        java.io.IOException - if an error occurs