Class DeadlockPrintStream

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.Appendable, java.lang.AutoCloseable

    public class DeadlockPrintStream
    extends java.io.PrintStream
    A print stream which can be put into a state in which all calls to write to it will result in the calling threads deadlocking in the call. Obviously, this class will not be useful to many as it is for tests.
    • Field Summary

      • Fields inherited from class java.io.FilterOutputStream

        out
    • Constructor Summary

      Constructors 
      Constructor Description
      DeadlockPrintStream​(java.io.PrintStream out)
      Creates a new DeadlockPrintStream wrapped around another PrintStream.
      DeadlockPrintStream​(java.io.PrintStream out, boolean autoFlush, java.lang.String encoding)
      Creates a new DeadlockPrintStream wrapped around another PrintStream.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      void flush()  
      void setDeadlock​(boolean deadlock)
      Sets or clears the deadlock flag.
      void write​(byte[] b)  
      void write​(byte[] b, int off, int len)  
      void write​(int b)  
      • Methods inherited from class java.io.PrintStream

        append, append, append, checkError, clearError, format, format, print, print, print, print, print, print, print, print, print, printf, printf, println, println, println, println, println, println, println, println, println, println, setError
      • Methods inherited from class java.io.OutputStream

        nullOutputStream
      • Methods inherited from class java.lang.Object

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

      • DeadlockPrintStream

        public DeadlockPrintStream​(java.io.PrintStream out)
        Creates a new DeadlockPrintStream wrapped around another PrintStream.
        Parameters:
        out - The PrintStream which will be wrapped by this new stream.
      • DeadlockPrintStream

        public DeadlockPrintStream​(java.io.PrintStream out,
                                   boolean autoFlush,
                                   java.lang.String encoding)
                            throws java.io.UnsupportedEncodingException
        Creates a new DeadlockPrintStream wrapped around another PrintStream.
        Parameters:
        out - The PrintStream which will be wrapped by this new stream.
        autoFlush - Whether the output buffer should be automatically flushed or not. ill be passed to the parent stream.
        encoding - The name of a supported character encoding. Will be passed to the parent stream.
        Throws:
        java.io.UnsupportedEncodingException - If the named encoding is not supported.
    • Method Detail

      • write

        public void write​(int b)
        Overrides:
        write in class java.io.PrintStream
      • write

        public void write​(byte[] b)
                   throws java.io.IOException
        Overrides:
        write in class java.io.FilterOutputStream
        Throws:
        java.io.IOException
      • write

        public void write​(byte[] b,
                          int off,
                          int len)
        Overrides:
        write in class java.io.PrintStream
      • flush

        public void flush()
        Specified by:
        flush in interface java.io.Flushable
        Overrides:
        flush in class java.io.PrintStream
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.PrintStream
      • setDeadlock

        public void setDeadlock​(boolean deadlock)
        Sets or clears the deadlock flag. If set, calls to any other method of this class will result in the calling thread being deadlocked. They will be released if the flag is cleared with this method.
        Parameters:
        deadlock - True to set the flag, false to clear it.