Package gov.usgs.util

Class TimeoutProcessBuilder


  • public class TimeoutProcessBuilder
    extends java.lang.Object
    The TimeoutProcessBuilder wraps a ProcessBuilder, adding support for a command time out. This class does not support a full command String complete with arguments. You can use the StringUtils.split method to get around this.
    See Also:
    ProcessBuilder, TimeoutProcess
    • Constructor Detail

      • TimeoutProcessBuilder

        public TimeoutProcessBuilder​(long timeout,
                                     java.lang.String... command)
        Create a new TimeoutProcessBuilder with a timeout and an array of strings.
        Parameters:
        timeout - timeout in milliseconds for process, or <= 0 for no timeout.
        command - array of strings that represent command. The first element must be the full path to the executable, without arguments.
      • TimeoutProcessBuilder

        public TimeoutProcessBuilder​(long timeout,
                                     java.util.List<java.lang.String> command)
        Create a new TimeoutProcessBuilder with a timeout and an array of strings.
        Parameters:
        timeout - timeout in milliseconds for process, or <= 0 for no timeout.
        command - list of strings that represent command.
      • TimeoutProcessBuilder

        @Deprecated
        public TimeoutProcessBuilder​(java.util.List<java.lang.String> command,
                                     long timeout)
        Deprecated.
        This signature is preserved, but calls the alternate constructor with argument order swapped.
        Parameters:
        command - list of strings that represent command.
        timeout - timeout in milliseconds for process, or <= 0 for no timeout.
    • Method Detail

      • command

        public java.util.List<java.lang.String> command()
        Returns:
        list of builder commands
      • command

        public TimeoutProcessBuilder command​(java.util.List<java.lang.String> command)
        Parameters:
        command - give builder a list of commands
        Returns:
        TimeoutProcessBuilder
      • command

        public TimeoutProcessBuilder command​(java.lang.String command)
        Parameters:
        command - give builder a single command
        Returns:
        TimeoutProcessBuilder
      • directory

        public java.io.File directory()
        Returns:
        builder directory
      • directory

        public TimeoutProcessBuilder directory​(java.io.File directory)
        Parameters:
        directory - to set
        Returns:
        TimeoutProcessBuilder
      • environment

        public java.util.Map<java.lang.String,​java.lang.String> environment()
        Returns:
        builder environment
      • redirectErrorStream

        public boolean redirectErrorStream()
        Returns:
        boolean redirectErrorStream
      • redirectErrorStream

        public TimeoutProcessBuilder redirectErrorStream​(boolean redirectErrorStream)
        Parameters:
        redirectErrorStream - to set
        Returns:
        TimeoutProcessBuilder
      • start

        public TimeoutProcess start()
                             throws java.io.IOException
        Returns:
        a TimeoutProcess
        Throws:
        java.io.IOException - if IO error occurs
      • getTimeout

        public long getTimeout()
        Returns:
        timeout
      • setTimeout

        public void setTimeout​(long timeout)
        Parameters:
        timeout - to set