import java.io.*;
import sun.io.CharToByteConverter;

/**
 * @version  21 sep 1998
 * @author   Philippe Chassignet, Ecole Polytechnique
 * @see      Input
 * @see      TD
 */
public class Output extends PrintWriter {

  private boolean file;
  private boolean closed = false;
  String name = null;

  public Output(OutputStream stream) {
    super(new OutputStreamWriter(stream), true);
    file = false;
  }
  
  public Output(String fileName) throws IOException {
    super(new FileWriter(fileName), true);
    file = true;
    name = fileName;
  }
  
  public void close() {
    if (file)
      {
      super.close();
      closed = true;
      }
  }

  public void write(int c) {
	char cbuf[] = new char[1];
	cbuf[0] = (char) c;
	write(cbuf, 0, 1);
  }
  
  public void write(char buf[], int off, int len) {
    if( closed )
      System.out.println("Output file " + name + " is closed !");
    else {
      super.write(buf, off, len);
//      super.flush();
    }
  }

  public void write(String str, int off, int len) {
	char cbuf[] = new char[len];
	str.getChars(off, len, cbuf, 0);
	write(cbuf, 0, len);
  }

}

