donaldp 02/04/05 17:33:23 Modified: src/main/org/apache/tools/ant/taskdefs/cvslib RedirectingStreamHandler.java Log: Seems I forgot to commit this... Revision Changes Path 1.7 +20 -87 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/cvslib/RedirectingStreamHandler.java Index: RedirectingStreamHandler.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/cvslib/RedirectingStreamHandler.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- RedirectingStreamHandler.java 4 Apr 2002 10:17:48 -0000 1.6 +++ RedirectingStreamHandler.java 6 Apr 2002 01:33:23 -0000 1.7 @@ -58,119 +58,52 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; +import java.io.ByteArrayOutputStream; import org.apache.tools.ant.taskdefs.ExecuteStreamHandler; +import org.apache.tools.ant.taskdefs.PumpStreamHandler; +import org.apache.tools.ant.BuildException; /** * A dummy stream handler that just passes stuff to the parser. * * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a> - * @version $Revision: 1.6 $ $Date: 2002/04/04 10:17:48 $ + * @version $Revision: 1.7 $ $Date: 2002/04/06 01:33:23 $ */ class RedirectingStreamHandler - implements ExecuteStreamHandler, Runnable + extends PumpStreamHandler { - private final ChangeLogParser m_parser; - private BufferedReader m_reader; - private InputStreamReader m_error; - private final StringBuffer m_errors = new StringBuffer(); - RedirectingStreamHandler( final ChangeLogParser parser ) { - m_parser = parser; + super( new RedirectingOutputStream( parser ), + new ByteArrayOutputStream() ); } String getErrors() { - if( 0 == m_errors.length() ) + try { - return null; + final ByteArrayOutputStream error = (ByteArrayOutputStream)getErr(); + return error.toString( "ASCII" ); } - else + catch( final Exception e ) { - return m_errors.toString(); + return null; } } - /** - * Install a handler for the input stream of the subprocess. - * - * @param os output stream to write to the standard input stream of the - * subprocess - */ - public void setProcessInputStream( OutputStream os ) throws IOException - { - //ignore - } - - /** - * Install a handler for the error stream of the subprocess. - * - * @param is input stream to read from the error stream from the subprocess - */ - public void setProcessErrorStream( InputStream is ) throws IOException - { - m_error = new InputStreamReader( is ); - } - - /** - * Install a handler for the output stream of the subprocess. - * - * @param is input stream to read from the error stream from the subprocess - */ - public void setProcessOutputStream( InputStream is ) throws IOException - { - m_reader = new BufferedReader( new InputStreamReader( is ) ); - } - - /** - * Start handling of the streams. - */ - public void start() throws IOException - { - //Start up a separate thread to consume error - //stream. Hopefully to avoid blocking of task - final Thread thread = new Thread( this, "ErrorConsumer" ); - thread.start(); - String line = m_reader.readLine(); - while( null != line ) - { - m_parser.stdout( line ); - line = m_reader.readLine(); - } - } - - /** - * Process the standard error in a different - * thread to avoid blocking in some situaitons. - */ - public void run() + public void stop() { - // Read the error stream so that it does not block ! - // We cannot use a BufferedReader as the ready() method is bugged! - // (see Bug 4329985, which is supposed to be fixed in JDK1.4 : - //http://developer.java.sun.com/developer/bugParade/bugs/4329985.html) + super.stop(); try { - while( m_error.ready() ) - { - final int value = m_error.read(); - if( -1 != value ) - { - m_errors.append( (char)value ); - } - } - } - catch( final IOException ioe ) + getErr().close(); + getOut().close(); + } + catch( final IOException e ) { - //ignore --> Means stderror has been shutdown + // plain impossible + throw new BuildException( e ); } - } - - /** - * Stop handling of the streams - will not be restarted. - */ - public void stop() - { } }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>