Class ISPT

  • All Implemented Interfaces:
    java.lang.Runnable

    public class ISPT
    extends java.lang.Thread
    A helper class performing Thread management for class OSResponse.

    ISPT: InputStream Printing Thread

    Helper Class for Torello.Java.OSCommands

    This class functions in a support role to both OSCommands and OSResponse. These, in turn, are the abstract parent-class and also a helper-support class for Operating-System Process-Invocation classes: Shell, MSDOS and GSUTIL).

    If the methods in this class do not appear to be 'generally applicable utilities' that is because they are specifically tailored to reading Process-Output (Standard-Out & Standard-Error) from Operating System calls.

    The two helpers used by the OSCommands Suite of Tools are: Completed and ISPT. These two classes do nothing more than streamline the multi-threaded reader code for reading from a java.lang.Process Object as it executes an Operating-System call.

    This class is used to asynchronously print String data from both Terminal Standard-Output and also Terminal Standard-Error to an output java.lang.Appendable. All it is is an extension of Java class Thread that receives an instance of InputStream to its constructor, and, when started as a Thread, prints the contents of the InputStream to a user provided Appendable.

    Internally, this class simply builds a java.lang.Runnable that will execute when the 'this' Thread's Thread.start() method is invoked. This class was designed for use with the 'Completed' thread-monitor system for printing output from one InputStream to a user provided output Appendable mechanism - asynchronously. The need for 'asynchronous' printing arose out of using the class java.lang.Process which has the behaviour of sending output to two different text-streams (Standard-Out and Standard-Error) at the same time. Though is usually not a problem, depending upon which O/S the JVM is running, thread-freezing may occur where the entire JVM halts because one of the streams isn't being serviced. The only way to prevent such problems is to use asynchronously print monitoring.


    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.lang.Thread

        java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
    • Field Summary

      • Fields inherited from class java.lang.Thread

        MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
    • Constructor Summary

      Constructors 
      Constructor
      ISPT​(InputStream inputStream, Appendable appendable, Completed completed, String name)
    • Method Summary

       
      Retrieve the Number of chars that Were Read
      Modifier and Type Method
      int numCharsRead()
      • Methods inherited from class java.lang.Thread

        activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, run, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • ISPT

        🡇    
        public ISPT​(java.io.InputStream inputStream,
                    java.lang.Appendable appendable,
                    Completed completed,
                    java.lang.String name)
        This shall build a Thread that asynchronously prints text read from an InputStream directly to the provided 'Appendable'.
        Parameters:
        inputStream - The InputStream to be read.
        appendable - Where the read text shall be sent
        completed - This class only works in coordination with the class 'Completed'. This class is used to allow the user to 'wait' until this independent Thread has run to completion.
        name - Since this class (ISPT) inherits from class Thread), it has a 'name' field. All Thread's have names. The name of the this Thread will be set to the value provided to this parameter.
    • Method Detail

      • numCharsRead

        🡅    
        public int numCharsRead()
        This returns a count on the number of characters that have been read from the InputStream
        Returns:
        Number of characters that have been read from the InputStream
        Code:
        Exact Method Body:
         return this.ispr.numCharsRead();