1 package org.tanukisoftware.wrapper.test; 2 3 27 28 import java.io.IOException ; 29 import java.io.PrintStream ; 30 31 38 public class DeadlockPrintStream extends PrintStream { 39 40 private PrintStream m_out; 41 42 43 private boolean m_deadlock; 44 45 48 53 public DeadlockPrintStream( PrintStream out ) 54 { 55 super( out ); 56 57 m_out = out; 58 } 59 60 63 public void write( int b ) 64 { 65 deadlock(); 66 m_out.write( b ); 67 } 68 69 public void write( byte[] b ) 70 throws IOException 71 { 72 deadlock(); 73 m_out.write( b ); 74 } 75 76 public void write( byte[] b, int off, int len ) 77 { 78 deadlock(); 79 m_out.write( b, off, len ); 80 } 81 82 public void flush() 83 { 84 deadlock(); 85 m_out.flush(); 86 } 87 88 public void close() 89 { 90 deadlock(); 91 m_out.close(); 92 } 93 94 97 102 private void deadlock() 103 { 104 if ( m_deadlock ) 105 { 106 synchronized( this ) 107 { 108 while( m_deadlock ) 109 { 110 try 111 { 112 this.wait(); 113 } 114 catch ( InterruptedException e ) 115 { 116 } 118 } 119 } 120 } 121 } 122 123 130 public void setDeadlock( boolean deadlock ) 131 { 132 m_deadlock = deadlock; 133 if ( !m_deadlock ) 134 { 135 synchronized( this ) 136 { 137 this.notifyAll(); 139 } 140 } 141 } 142 } 143 144 | Popular Tags |