

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

//-----------------------------------------------------------------------//
// Files class (has static methods for File operations):
//-----------------------------------------------------------------------//

public class Files {

    public static void setProgram( String newProgram ) {
        program = newProgram ;
    }

    public static void setVersion( String newVersion ) {
        version = newVersion ;
    }

    public static void toFile( String contents, File outputFile ) {

        try {

            BufferedWriter writer = new BufferedWriter( new OutputStreamWriter( new FileOutputStream( outputFile ),
                                    "ISO-8859-1" ) ) ;

            writer.write( headerBlock() ) ;
            writer.newLine() ;
            writer.write( contents ) ;
            writer.newLine() ;
            writer.close() ;

        }
        catch ( IOException thrown ) {
            System.err.println( "error writing \""
                            + outputFile
                            + "\"; exception is \""
                            + thrown
                            + '"' ) ;
        }
    }

    private static String headerBlock() {
        return
                "// Automatically generated code.  Edit at your own risk!"
                + Main.LINE_SEPARATOR
                + "// Generated by " + program + ' ' + version + '.'
                + Main.LINE_SEPARATOR ;
    }

    private static String program = null ;
    private static String version = null ;

}
