@@ -0,0 +1,2035 @@
+package com.github.aureliano.evtbridge.output.file;%0A%0Aimport java.io.BufferedOutputStream;%0Aimport java.io.FileOutputStream;%0Aimport java.io.IOException;%0Aimport java.io.OutputStreamWriter;%0Aimport java.io.PrintWriter;%0A%0Aimport org.apache.log4j.Logger;%0A%0Aimport com.github.aureliano.evtbridge.core.agent.AbstractDataWriter;%0Aimport com.github.aureliano.evtbridge.core.formatter.PlainTextFormatter;%0A%0Apublic class FileDataWriter extends AbstractDataWriter %7B%0A%09%0A%09private PrintWriter writer;%0A%09private FileOutputConfig fileOutputConfiguration;%0A%09%0A%09private static final Logger logger = Logger.getLogger(FileDataWriter.class);%0A%09%0A%09public FileDataWriter() %7B%0A%09%09super();%0A%09%7D%0A%09%0A%09@Override%0A%09public void initializeResources() %7B%0A%09%09this.initialize();%0A%09%7D%0A%0A%09@Override%0A%09public void write(Object data) %7B%0A%09%09this.writer.println(data);%0A%09%09%0A%09%09if (!this.fileOutputConfiguration.isUseBuffer()) %7B%0A%09%09%09this.writer.flush();%0A%09%09%7D%0A%09%7D%0A%09%0A%09@Override%0A%09public void finalizeResources() %7B%0A%09%09if (this.writer == null) %7B%0A%09%09%09return;%0A%09%09%7D%0A%09%09%0A%09%09logger.debug(%22 %3E%3E%3E Flushing and closing stream writer.%22);%0A%09%09%0A%09%09this.writer.flush();%0A%09%09this.writer.close();%09%09%0A%09%7D%0A%09%0A%09private void initialize() %7B%0A%09%09this.fileOutputConfiguration = (FileOutputConfig) super.outputConfiguration;%0A%09%09%0A%09%09logger.info(%22Outputing data to %22 + this.fileOutputConfiguration.getFile().getPath());%0A%09%09logger.debug(%22Data encondig: %22 + this.fileOutputConfiguration.getEncoding());%0A%09%09logger.debug(%22Append data to file? %22 + this.fileOutputConfiguration.isAppend());%0A%09%09%0A%09%09if (super.getConfiguration().getOutputFormatter() == null) %7B%0A%09%09%09super.getConfiguration().withOutputFormatter(new PlainTextFormatter());%0A%09%09%7D%0A%09%09%0A%09%09try %7B%0A%09%09%09FileOutputStream stream = new FileOutputStream(this.fileOutputConfiguration.getFile(), this.fileOutputConfiguration.isAppend());%0A%09%09%09BufferedOutputStream buffer = new BufferedOutputStream(stream);%0A%09%09%09OutputStreamWriter osw = new OutputStreamWriter(buffer, this.fileOutputConfiguration.getEncoding());%0A%09%09%09this.writer = new PrintWriter(osw);%0A%09%09%7D catch (IOException ex) %7B%0A%09%09%09throw new FileOutputException(ex);%0A%09%09%7D%0A%09%7D%0A%7D

Create file data writer.