import java.io.* ; /** * A simple output class to write values to a file. * Based on FileOutput from Graham Roberts * @version 1.0 21.1.2000 * @author Anthony Steed */ public class SceneWriter { /* * Private variables */ private BufferedWriter writer = null ; /** * Construct SceneWriter object given a file. * @param f the file to read from * @throw java.lang.Exception * on various file access errors */ public SceneWriter(File f) throws Exception { writer = new BufferedWriter(new FileWriter(f)) ; } /** * Create a SceneWriter from a stream * @param os the stream specifying the file location * @throw java.lang.Exception * on various stream access errors */ public SceneWriter(OutputStream os) throws Exception { writer = new BufferedWriter(new OutputStreamWriter(os)) ; } /** * Close the file when finished * @throw java.io.IOException * on various access errors */ public void close() throws IOException { writer.close() ; } /** * Flush the writer * @throw java.io.IOException * on various access errors */ public void flush() throws IOException { writer.flush() ; } /** * Write an int value to a file. * @param i the int to write * @throw java.io.IOException * on various access errors */ public final synchronized void writeInt(int i) throws IOException { writer.write(Integer.toString(i)) ; } /** * Write a long value. * @param l the long to write * @throw java.io.IOException * on various access errors */ public final synchronized void writeLong(long l) throws IOException { writer.write(Long.toString(l)) ; } /** * Write a double value. * @param d the double to write * @throw java.io.IOException * on various access errors */ public final synchronized void writeDouble(double d) throws IOException { writer.write(Double.toString(d)) ; } /** * Write a float value. * @param f the float to write * @throw java.io.IOException * on various access errors */ public final synchronized void writeFloat(float f) throws IOException { writer.write(Float.toString(f)) ; } /** * Write a char value to a file. * @param c the char to write * @throw java.io.IOException * on various access errors */ public final synchronized void writeChar(char c) throws IOException { writer.write(c) ; } /** * Write a String value to a file. * @param s the string to write * @throw java.io.IOException * on various access errors */ public final synchronized void writeString(String s) throws IOException { writer.write(s) ; } /** * Write a newline to a file. * @throw java.io.IOException * on various access errors */ public final synchronized void writeNewline() throws IOException { writer.write("\n") ; } }