// Path: src/main/java/au/com/anthonybruno/record/RecordSupplier.java
// public interface RecordSupplier {
// 
//     List<String> getFields();
// 
//     Stream<Record> supplyRecords(int numToGenerate);
// 
// }
// 
// Path: src/main/java/au/com/anthonybruno/record/factory/RecordFactory.java
// public interface RecordFactory {
// 
//     RecordSupplier getRecordSupplier();
// }
// 
// Path: src/main/java/au/com/anthonybruno/settings/FixedWidthSettings.java
// public class FixedWidthSettings extends FlatFileSettings {
// 
//     private final List<FixedWidthField> fixedWidthFields;
// 
//     public FixedWidthSettings(boolean includeHeaders, List<FixedWidthField> fields) {
//         super(includeHeaders);
//         this.fixedWidthFields = fields;
//     }
// 
//     public List<FixedWidthField> getFixedWidthFields() {
//         return fixedWidthFields;
//     }
// }
// 
// Path: src/main/java/au/com/anthonybruno/utils/TextFile.java
// public class TextFile {
// 
//     public static final Charset DEFAULT_ENCODING = Charset.forName("utf-8");
// 
//     private final File file;
//     private final Lazy<String> text;
//     private final Charset encoding;
// 
//     public TextFile(File file) {
//         this(file, DEFAULT_ENCODING);
//     }
// 
//     public TextFile(File file, Charset encoding) {
//         if (!file.exists()) {
//             throw new IllegalArgumentException(file + " does not exist.");
//         }
//         this.file = file;
//         this.text = new Lazy<>(() -> readTextFromFile(file));
//         this.encoding = encoding;
//     }
// 
//     public Writer getWriter() {
//         try {
//             return new FileWriter(file);
//         } catch (IOException e) {
//             throw new RuntimeException(e);
//         }
//     }
// 
//     public String getText() {
//         return text.get();
//     }
// 
//     private String readTextFromFile(File file) {
//         BufferedReader reader;
//         try {
//             reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), encoding));
//         } catch (FileNotFoundException e) {
//             throw new IllegalArgumentException(e);
//         }
//         StringBuilder stringBuilder = new StringBuilder();
//         reader.lines().forEach((line) -> stringBuilder.append(line).append("\n"));
//         return stringBuilder.toString();
//     }
// 
// }
// 
// Path: src/main/java/au/com/anthonybruno/writer/WriterFactory.java
// public class WriterFactory {
// 
//     public static AbstractCsvWriter getDefaultCsvWriter(Writer writer, CsvSettings csvSettings) {
//         return new UnivocityCsvWriter(writer, csvSettings);
//     }
// 
//     public static AbstractFixedWidthWriter getDefaultFixedWidthWriter(Writer writer, FixedWidthSettings settings) {
//         return new UnivocityFixedWidthWriter(writer, settings);
//     }
// }
// 
// Path: src/main/java/au/com/anthonybruno/writer/fixedwidth/AbstractFixedWidthWriter.java
// public abstract class AbstractFixedWidthWriter extends FlatFileWriter<FixedWidthSettings> {
// 
//     public AbstractFixedWidthWriter(Writer writer, FixedWidthSettings settings) {
//         super(writer, settings);
//     }
// 
// }


import au.com.anthonybruno.record.RecordSupplier;
import au.com.anthonybruno.record.factory.RecordFactory;
import au.com.anthonybruno.settings.FixedWidthSettings;
import au.com.anthonybruno.utils.TextFile;
import au.com.anthonybruno.writer.WriterFactory;
import au.com.anthonybruno.writer.fixedwidth.AbstractFixedWidthWriter;
import java.io.File;
import java.io.StringWriter;
package au.com.anthonybruno.creator;



public class FixedWidthFactory extends FlatFileFactory<FixedWidthSettings> {

    public FixedWidthFactory(FixedWidthSettings settings, RecordFactory recordFactory) {
        super(settings, recordFactory);
    }

    @Override
    public String createString(int numToGenerate) {
        StringWriter stringWriter = new StringWriter();
        try (AbstractFixedWidthWriter fixedWidthWriter = WriterFactory.getDefaultFixedWidthWriter(stringWriter, settings)) {
            generateAndWriteValues(fixedWidthWriter, numToGenerate);
        }
        return stringWriter.toString();
    }


    private void generateAndWriteValues(AbstractFixedWidthWriter writer, int numToGenerate) {
        RecordSupplier recordSupplier = recordFactory.getRecordSupplier();
        if (settings.isIncludingHeaders()) {
            writer.writeRow(recordSupplier.getFields());
        }
// Path: src/main/java/au/com/anthonybruno/record/RecordSupplier.java
// public interface RecordSupplier {
// 
//     List<String> getFields();
// 
//     Stream<Record> supplyRecords(int numToGenerate);
// 
// }
// 
// Path: src/main/java/au/com/anthonybruno/record/factory/RecordFactory.java
// public interface RecordFactory {
// 
//     RecordSupplier getRecordSupplier();
// }
// 
// Path: src/main/java/au/com/anthonybruno/settings/FixedWidthSettings.java
// public class FixedWidthSettings extends FlatFileSettings {
// 
//     private final List<FixedWidthField> fixedWidthFields;
// 
//     public FixedWidthSettings(boolean includeHeaders, List<FixedWidthField> fields) {
//         super(includeHeaders);
//         this.fixedWidthFields = fields;
//     }
// 
//     public List<FixedWidthField> getFixedWidthFields() {
//         return fixedWidthFields;
//     }
// }
// 
// Path: src/main/java/au/com/anthonybruno/utils/TextFile.java
// public class TextFile {
// 
//     public static final Charset DEFAULT_ENCODING = Charset.forName("utf-8");
// 
//     private final File file;
//     private final Lazy<String> text;
//     private final Charset encoding;
// 
//     public TextFile(File file) {
//         this(file, DEFAULT_ENCODING);
//     }
// 
//     public TextFile(File file, Charset encoding) {
//         if (!file.exists()) {
//             throw new IllegalArgumentException(file + " does not exist.");
//         }
//         this.file = file;
//         this.text = new Lazy<>(() -> readTextFromFile(file));
//         this.encoding = encoding;
//     }
// 
//     public Writer getWriter() {
//         try {
//             return new FileWriter(file);
//         } catch (IOException e) {
//             throw new RuntimeException(e);
//         }
//     }
// 
//     public String getText() {
//         return text.get();
//     }
// 
//     private String readTextFromFile(File file) {
//         BufferedReader reader;
//         try {
//             reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), encoding));
//         } catch (FileNotFoundException e) {
//             throw new IllegalArgumentException(e);
//         }
//         StringBuilder stringBuilder = new StringBuilder();
//         reader.lines().forEach((line) -> stringBuilder.append(line).append("\n"));
//         return stringBuilder.toString();
//     }
// 
// }
// 
// Path: src/main/java/au/com/anthonybruno/writer/WriterFactory.java
// public class WriterFactory {
// 
//     public static AbstractCsvWriter getDefaultCsvWriter(Writer writer, CsvSettings csvSettings) {
//         return new UnivocityCsvWriter(writer, csvSettings);
//     }
// 
//     public static AbstractFixedWidthWriter getDefaultFixedWidthWriter(Writer writer, FixedWidthSettings settings) {
//         return new UnivocityFixedWidthWriter(writer, settings);
//     }
// }
// 
// Path: src/main/java/au/com/anthonybruno/writer/fixedwidth/AbstractFixedWidthWriter.java
// public abstract class AbstractFixedWidthWriter extends FlatFileWriter<FixedWidthSettings> {
// 
//     public AbstractFixedWidthWriter(Writer writer, FixedWidthSettings settings) {
//         super(writer, settings);
//     }
// 
// }


// Path: src/main/java/au/com/anthonybruno/creator/FixedWidthFactory.java
import au.com.anthonybruno.record.RecordSupplier;
import au.com.anthonybruno.record.factory.RecordFactory;
import au.com.anthonybruno.settings.FixedWidthSettings;
import au.com.anthonybruno.utils.TextFile;
import au.com.anthonybruno.writer.WriterFactory;
import au.com.anthonybruno.writer.fixedwidth.AbstractFixedWidthWriter;
import java.io.File;
import java.io.StringWriter;

package au.com.anthonybruno.creator;



public class FixedWidthFactory extends FlatFileFactory<FixedWidthSettings> {

    public FixedWidthFactory(FixedWidthSettings settings, RecordFactory recordFactory) {
        super(settings, recordFactory);
    }

    @Override
    public String createString(int numToGenerate) {
        StringWriter stringWriter = new StringWriter();
        try (AbstractFixedWidthWriter fixedWidthWriter = WriterFactory.getDefaultFixedWidthWriter(stringWriter, settings)) {
            generateAndWriteValues(fixedWidthWriter, numToGenerate);
        }
        return stringWriter.toString();
    }


    private void generateAndWriteValues(AbstractFixedWidthWriter writer, int numToGenerate) {
        RecordSupplier recordSupplier = recordFactory.getRecordSupplier();
        if (settings.isIncludingHeaders()) {
            writer.writeRow(recordSupplier.getFields());
        }
        recordSupplier.supplyRecords(numToGenerate)