package uk.ac.ebi.atlas.commons.writers;


import org.springframework.context.annotation.Scope;
import uk.ac.ebi.atlas.commons.readers.TsvReader;
import uk.ac.ebi.atlas.commons.readers.impl.TsvReaderImpl;
import uk.ac.ebi.atlas.commons.writers.impl.TsvWriterImpl;

import javax.inject.Named;
import java.io.*;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.text.MessageFormat;

@Named
@Scope("prototype")
public class FileTsvWriterBuilder {

    private String experimentAccession;
    private String tsvFilePathTemplate;
    private boolean append = true;

    public FileTsvWriterBuilder() {
    }

    public FileTsvWriterBuilder withExperimentAccession(String experimentAccession) {
        this.experimentAccession = experimentAccession;
        return this;
    }

    public FileTsvWriterBuilder forTsvFilePathTemplate(String tsvFilePathTemplate) {
        this.tsvFilePathTemplate = tsvFilePathTemplate;
        return this;
    }
    public FileTsvWriterBuilder withAppend(boolean append) {
        this.append = append;
        return this;
    }

    public TsvWriter build() {
        String tsvFilePath = MessageFormat.format(tsvFilePathTemplate, experimentAccession);
        try {
            return new TsvWriterImpl(new OutputStreamWriter(new FileOutputStream(new File(tsvFilePath), append)));
        } catch (IOException e) {
            throw new IllegalStateException("Cannot write TSV file to path " + tsvFilePath.toString(), e);
        }
    }

}
@@ -35,17 +35,16 @@
 iters;%0A%0A
-%0A
 import o
@@ -92,117 +92,8 @@
 pe;%0A
-import uk.ac.ebi.atlas.commons.readers.TsvReader;%0Aimport uk.ac.ebi.atlas.commons.readers.impl.TsvReaderImpl;%0A
 impo
@@ -175,16 +175,17 @@
 .Named;%0A
+%0A
 import j
@@ -195,9 +195,12 @@
 .io.
-*
+File
 ;%0Aim
@@ -213,28 +213,27 @@
 ava.
-n
 io.
-file.FileSystems
+FileOutputStream
 ;%0Aim
@@ -246,22 +246,22 @@
 ava.
-n
 io.
-file.Files
+IOException
 ;%0Aim
@@ -274,21 +274,29 @@
 ava.
-n
 io.
-file.Path
+OutputStreamWriter
 ;%0Aim
@@ -1387,19 +1387,8 @@
 Path
-.toString()
 , e)
@@ -1407,8 +1407,9 @@
     %7D%0A%0A%7D
+%0A

Clean imports and remove unnecessary toString()