/*
 * $Id$
 * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
 * For details on use and redistribution please refer to the
 * LICENSE file included with these sources.
 */

package org.apache.fop.apps;

// SAX
import org.xml.sax.XMLReader;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

import org.apache.log.*;

// Java
import java.io.*;
import java.net.URL;


// FOP
import org.apache.fop.configuration.Configuration;

/**
 * super class for all classes which start Fop from the commandline
 *
 * Modified to use new streaming API by Mark Lillywhite, mark-fop@inomial.com
 */

public class CommandLineStarter extends Starter {

    CommandLineOptions commandLineOptions;
    boolean errorDump;

    public CommandLineStarter(CommandLineOptions commandLineOptions)
    throws FOPException {
        this.commandLineOptions = commandLineOptions;
        options.setCommandLineOptions(commandLineOptions);
        errorDump =
          Configuration.getBooleanValue("debugMode").booleanValue();
        super.setInputHandler(commandLineOptions.getInputHandler());
    }

    /**
     * Run the format.
     * @exception FOPException if there is an error during processing
     */
    public void run() throws FOPException {
        String version = Version.getVersion();

        log.info(version);

        XMLReader parser = inputHandler.getParser();
        setParserFeatures(parser);

        Driver driver = new Driver();
        driver.setLogger(log);
        driver.setBufferFile(commandLineOptions.getBufferFile());

        if (errorDump) {
            driver.setErrorDump(true);
        }

        try {
            driver.setRenderer(commandLineOptions.getRenderer());
            driver.setOutputStream( new FileOutputStream(
                                      commandLineOptions.getOutputFile()));
            driver.getRenderer().setOptions(
              commandLineOptions.getRendererOptions());
            driver.render(parser, inputHandler.getInputSource());
            System.exit(0);
        } catch (Exception e) {
            if (e instanceof FOPException) {
                throw (FOPException) e;
            }
            throw new FOPException(e);
        }
    }

}


@@ -1765,26 +1765,55 @@
         
-driver.set
+BufferedOutputStream bos = new Buffered
 OutputSt
@@ -1817,17 +1817,16 @@
 tStream(
- 
 new File
@@ -1911,24 +1911,65 @@
 utFile()));%0A
+            driver.setOutputStream(bos);%0A
             
@@ -2053,24 +2053,24 @@
 Options());%0A
-
             
@@ -2119,24 +2119,49 @@
 tSource());%0A
+            bos.close();%0A
             

use buffered stream and close at the end