Class AbstractBinary

  • Direct Known Subclasses:
    AbstractBinaryWithTimeout, SshKeyGen, SshPass

    public abstract class AbstractBinary
    extends java.lang.Object
    Ancestor of wrappers for binaries.
    Author:
    fracpete (fracpete at gmail dot com)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.logging.Logger logger
      for logging.
      protected boolean outputCommandline
      whether to output the commandline.
      protected boolean outputSingleCommandline
      whether to output the commandline arguments one per line or combined in a single line.
    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractBinary()
      Initializes the object.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.ProcessBuilder builder()
      Returns a configured ProcessBuilder to be used for executing the rsync process.
      java.lang.String commandLine()
      Assembles the full command-line.
      abstract java.util.List<java.lang.String> commandLineArgs()
      Assembles the full command-line arguments.
      protected abstract java.lang.String description()
      Returns a short description for the binary.
      com.github.fracpete.processoutput4j.output.CollectingProcessOutput execute()
      Executes the rsync binary for the platform and waits for its completion.
      boolean getOutputCommandline()
      Returns output commandline flag.
      boolean getOutputSingleCommandline()
      Returns whether to output the command-line as single line or each argument on a separate one.
      protected net.sourceforge.argparse4j.inf.ArgumentParser getParser()
      Configures and returns the commandline parser.
      abstract java.util.List<java.lang.String> options()
      Assembles the arguments for the rsync binary.
      AbstractBinary outputCommandline​(boolean value)
      Sets output commandline flag.
      AbstractBinary outputSingleCommandline​(boolean value)
      Sets whether to output the command-line as single line or each argument on a separate one.
      void reset()
      Resets the members.
      static void run​(AbstractBinary binary, java.lang.String[] args)
      Runs the binary with the arguments.
      boolean setOptions​(java.lang.String[] options)
      Sets the commandline options.
      protected boolean setOptions​(net.sourceforge.argparse4j.inf.Namespace ns)
      Sets the parsed options.
      java.lang.Process start()
      Starts the rsync process for the platform.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • logger

        protected java.util.logging.Logger logger
        for logging.
      • outputCommandline

        protected boolean outputCommandline
        whether to output the commandline.
      • outputSingleCommandline

        protected boolean outputSingleCommandline
        whether to output the commandline arguments one per line or combined in a single line.
    • Constructor Detail

      • AbstractBinary

        public AbstractBinary()
        Initializes the object.
    • Method Detail

      • reset

        public void reset()
        Resets the members.
      • outputCommandline

        public AbstractBinary outputCommandline​(boolean value)
        Sets output commandline flag.
        Parameters:
        value - true if to output commandline
        Returns:
        itself
      • getOutputCommandline

        public boolean getOutputCommandline()
        Returns output commandline flag.
        Returns:
        true if to output commandline
      • outputSingleCommandline

        public AbstractBinary outputSingleCommandline​(boolean value)
        Sets whether to output the command-line as single line or each argument on a separate one.
        Parameters:
        value - true for single line
        Returns:
        itself
      • getOutputSingleCommandline

        public boolean getOutputSingleCommandline()
        Returns whether to output the command-line as single line or each argument on a separate one.
        Returns:
        true if single line
      • options

        public abstract java.util.List<java.lang.String> options()
                                                          throws java.lang.Exception
        Assembles the arguments for the rsync binary.
        Returns:
        the options
        Throws:
        java.lang.Exception - if failed to determine binary
      • commandLineArgs

        public abstract java.util.List<java.lang.String> commandLineArgs()
                                                                  throws java.lang.Exception
        Assembles the full command-line arguments.
        Returns:
        the command-line arguments
        Throws:
        java.lang.Exception - if failed to determine binary
        See Also:
        options()
      • commandLine

        public java.lang.String commandLine()
                                     throws java.lang.Exception
        Assembles the full command-line.
        Returns:
        the command-line arguments
        Throws:
        java.lang.Exception - if failed to determine binary
        See Also:
        commandLineArgs()
      • builder

        public java.lang.ProcessBuilder builder()
                                         throws java.lang.Exception
        Returns a configured ProcessBuilder to be used for executing the rsync process.
        Returns:
        the configured process builder
        Throws:
        java.lang.Exception - if execution fails or failed to determine binary
        See Also:
        commandLineArgs()
      • start

        public java.lang.Process start()
                                throws java.lang.Exception
        Starts the rsync process for the platform.
        If you are not interested in an incremental progress output, then you can also use execute(), which waits for the process to finish while collecting stdout and stderr output.
        Returns:
        the process object
        Throws:
        java.lang.Exception - if execution fails or failed to determine binary
        See Also:
        builder()
      • execute

        public com.github.fracpete.processoutput4j.output.CollectingProcessOutput execute()
                                                                                   throws java.lang.Exception
        Executes the rsync binary for the platform and waits for its completion. Collects stdout and stderr output in the result.
        If you want an incremental output, you can use start() and monitor the output yourself.
        Returns:
        the process result object
        Throws:
        java.lang.Exception - if execution fails or failed to determine binary
        See Also:
        commandLineArgs()
      • description

        protected abstract java.lang.String description()
        Returns a short description for the binary.
        Returns:
        the description
      • getParser

        protected net.sourceforge.argparse4j.inf.ArgumentParser getParser()
        Configures and returns the commandline parser.
        Returns:
        the parser
      • setOptions

        protected boolean setOptions​(net.sourceforge.argparse4j.inf.Namespace ns)
        Sets the parsed options.
        Parameters:
        ns - the parsed options
        Returns:
        if successfully set
      • setOptions

        public boolean setOptions​(java.lang.String[] options)
                           throws java.lang.Exception
        Sets the commandline options.
        Parameters:
        options - the options to use
        Returns:
        true if successful
        Throws:
        java.lang.Exception - in case of an invalid option
      • run

        public static void run​(AbstractBinary binary,
                               java.lang.String[] args)
                        throws java.lang.Exception
        Runs the binary with the arguments.
        Parameters:
        args - the arguments
        Throws:
        java.lang.Exception