[Webfunds-commits] java/webfunds/utils MultiPrintStream.java

Jeroen C. van Gelderen gelderen@cypherpunks.ai
Sun, 4 Jun 2000 15:44:59 -0400 (AST)


gelderen    00/06/04 15:44:58

  Added:       webfunds/utils MultiPrintStream.java
  Log:
  Initial version of MultiPrintStream which multiplexes it's output over
  an array of PrintStreams.

Revision  Changes    Path
1.1                  java/webfunds/utils/MultiPrintStream.java

Index: MultiPrintStream.java
===================================================================
/* $Id: MultiPrintStream.java,v 1.1 2000/06/04 19:44:58 gelderen Exp $
 *
 * Copyright (c) 2000 Systemics Inc. on behalf of
 * The WebFunds Development Team. All rights reserved.
 */
package webfunds.utils;


import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;


/**
 * MultiPrintStream is a PrintStream that multiplexes it's output over
 * multiple PrintStreams.
 *
 * @version $Revision: 1.1 $
 * @author  Jeroen C. van Gelderen (gelderen@webfunds.org)
 */
public final class MultiPrintStream extends PrintStream
{
    /**
     * Construct a MultiPrintStream that multiplexes over the given
     * PrintStreams. The array <em>may</em> contains nulls.
     *
     * @throws NullPointerException
     *         When streams is null.
     */
    public MultiPrintStream(PrintStream[] streams)
    {
        super( new MultiOutputStream(streams) );
    }
}


/**
 * Helper class for MultiPrintStream.
 */
/*package*/ final class MultiOutputStream extends OutputStream
{
    private PrintStream[] streams;


    public MultiOutputStream(PrintStream[] streams)
    {
        super();

        //ASSERT( streams != null );
        this.streams = (PrintStream[])(streams.clone());
    }


    public void write(int b) throws IOException
    {
        for( int i=0; i<this.streams.length; i++ )
        {
            PrintStream ps = this.streams[i];
            if( ps != null )
                ps.write(b);
        }
    }
}