package name.panitz.gm;

import java.io.*;
import java.util.*;

public class GmWriter {
  DataOutputStream out=null;
  private GmWriter(){};

  public static GmWriter getInstance(String fileName)
                                       throws Exception{
    GmWriter result = new GmWriter();
    result.out
     =new DataOutputStream(new FileOutputStream(fileName));
    return result;
  }

  public GmWriter write(Integer i)throws Exception{
    out.write((byte)i.intValue());return this;}

  public GmWriter write(Character i)throws Exception{
    out.writeChars(""+i.charValue());return this;}

  public GmWriter writeInt(Integer i)throws Exception{
    out.writeInt(i);return this;}

  public GmWriter writeChars(String i)throws Exception{
    out.writeChars(i);return this;}

  public static String error(String message)throws Exception{
    throw new Exception(message);}

  public static Boolean print(String message)throws Exception{
    System.out.println(message);
    return true;
  }

  public static Object trace(String message,Object o)throws Exception{
    System.out.println(message+o);
    return o;
  }
  public static Object trace(String message,String o)throws Exception{
    System.out.println(message+o);
    return o;
  }

  public static String writeFile(String fileName,String content)
                        throws Exception{
    FileWriter f= new FileWriter(fileName);
    f.write(content);
    f.close();
    return fileName;
  }

  public static String appendFile(String fileName,String content)
                        throws Exception{
    FileWriter f= new FileWriter(fileName,true);
    f.write(content);
    f.close();
    return fileName;
  }
  public static String appendFile(String fileName,int content)
                        throws Exception{
    FileWriter f= new FileWriter(fileName,true);
    f.write(content+"");
    f.close();
    return fileName;
  }
  public static String appendFile(String fileName,char content)
                        throws Exception{
    FileWriter f= new FileWriter(fileName,true);
    f.write(content+"");
    f.close();
    return fileName;
  }
  public static String appendFile(String fileName,Object content)
                        throws Exception{
    FileWriter f= new FileWriter(fileName,true);
    f.write(content+"");
    f.close();
    return fileName;
  }
  public static String appendFile(String fileName,Integer content)
                        throws Exception{
    FileWriter f= new FileWriter(fileName,true);
    f.write(content+"");
    f.close();
    return fileName;
  }
  public static String appendFile(String fileName,Character content)
                        throws Exception{
    FileWriter f= new FileWriter(fileName,true);
    f.write(content+"");
    f.close();
    return fileName;
  }
}

