Package systole.ioHandling.fileWriter

Source Code of systole.ioHandling.fileWriter.FileWriterSystlole

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package systole.ioHandling.fileWriter;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;

import systole.exceptions.ExceptionIO;
import systole.ioHandling.logs.SystoleLogger;

/**
*
* @author jmj
*/
public class FileWriterSystlole {

    private Writer writer = null;

    /**
     * @param fileName Name of file to create and write.
     * @throws ExceptionIO
     */
    public FileWriterSystlole(String fileName) throws ExceptionIO {
        try {
            this.writer = new BufferedWriter(new FileWriter(fileName));
        } catch (IOException ex) {
            SystoleLogger.getInstance().logError(ex.getMessage());
            throw new ExceptionIO(ex.getMessage());
        }
    }

   
    /**
     * @param line Line to write on the file.
     * @throws ExceptionIO
     */
    public void write(String line) throws ExceptionIO {

        if (this.writer != null) {

            try {
                //FileWriter always assumes default encoding is OK!
                this.writer.write(line);

            } catch (IOException ex) {
               SystoleLogger.getInstance().logError(ex.getMessage())
               throw new ExceptionIO(ex.getMessage());
            }
        }
   }


    /**
     * Close the file.
     */
    public void close(){
    if (this.writer != null) {
          try {
                this.writer.close();

            } catch (IOException ex) {
               SystoleLogger.getInstance().logError(ex.getMessage());
            }
        }
    }


}
TOP

Related Classes of systole.ioHandling.fileWriter.FileWriterSystlole

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.