Search in sources :

Example 1 with FixedWidthWriterSettings

use of com.univocity.parsers.fixed.FixedWidthWriterSettings in project tablesaw by jtablesaw.

the class FixedWidthWriter method fixedWidthWriterSettings.

protected FixedWidthWriterSettings fixedWidthWriterSettings(FixedWidthWriteOptions options) {
    FixedWidthWriterSettings settings = new FixedWidthWriterSettings();
    if (options.columnSpecs() != null) {
        settings = new FixedWidthWriterSettings(options.columnSpecs());
    }
    if (options.autoConfigurationEnabled()) {
        settings.setAutoConfigurationEnabled(options.autoConfigurationEnabled());
    } else {
        columnRowSettings(settings, options);
        errorSettings(settings, options);
        skipIgnoreSettings(settings, options);
    }
    return settings;
}
Also used : FixedWidthWriterSettings(com.univocity.parsers.fixed.FixedWidthWriterSettings)

Example 2 with FixedWidthWriterSettings

use of com.univocity.parsers.fixed.FixedWidthWriterSettings in project powsybl-core by powsybl.

the class IeeeCdfWriter method writeRecords.

private static <T> void writeRecords(Writer writer, List<T> beans, Class<T> aClass) {
    FixedWidthWriterSettings settings = new FixedWidthWriterSettings();
    settings.setWriteLineSeparatorAfterRecord(true);
    BeanWriterProcessor<T> processor = new BeanWriterProcessor<>(aClass);
    settings.setRowWriterProcessor(processor);
    new FixedWidthWriter(writer, settings).processRecords(beans);
}
Also used : FixedWidthWriterSettings(com.univocity.parsers.fixed.FixedWidthWriterSettings) BeanWriterProcessor(com.univocity.parsers.common.processor.BeanWriterProcessor) FixedWidthWriter(com.univocity.parsers.fixed.FixedWidthWriter)

Example 3 with FixedWidthWriterSettings

use of com.univocity.parsers.fixed.FixedWidthWriterSettings in project tablesaw by jtablesaw.

the class FixedWidthWriter method write.

public void write(Table table, FixedWidthWriteOptions options) {
    FixedWidthWriterSettings settings = fixedWidthWriterSettings(options);
    settings.setFormat(fixedWidthFormat(options));
    com.univocity.parsers.fixed.FixedWidthWriter fixedWidthWriter = null;
    // Creates a writer with the above settings;
    try {
        Writer writer = options.destination().createWriter();
        fixedWidthWriter = new com.univocity.parsers.fixed.FixedWidthWriter(writer, settings);
        if (options.header()) {
            String[] header = new String[table.columnCount()];
            for (int c = 0; c < table.columnCount(); c++) {
                header[c] = table.column(c).name();
            }
            fixedWidthWriter.writeHeaders(header);
        }
        for (int r = 0; r < table.rowCount(); r++) {
            String[] entries = new String[table.columnCount()];
            for (int c = 0; c < table.columnCount(); c++) {
                table.get(r, c);
                entries[c] = table.getUnformatted(r, c);
            }
            fixedWidthWriter.writeRow(entries);
        }
    } finally {
        if (fixedWidthWriter != null) {
            fixedWidthWriter.flush();
            if (options.autoClose())
                fixedWidthWriter.close();
        }
    }
}
Also used : FixedWidthWriterSettings(com.univocity.parsers.fixed.FixedWidthWriterSettings) DataWriter(tech.tablesaw.io.DataWriter) Writer(java.io.Writer)

Example 4 with FixedWidthWriterSettings

use of com.univocity.parsers.fixed.FixedWidthWriterSettings in project symja_android_library by axkr.

the class FixedWidthWriter method write.

public void write(Table table, FixedWidthWriteOptions options) {
    FixedWidthWriterSettings settings = fixedWidthWriterSettings(options);
    settings.setFormat(fixedWidthFormat(options));
    com.univocity.parsers.fixed.FixedWidthWriter fixedWidthWriter = null;
    // Creates a writer with the above settings;
    try {
        Writer writer = options.destination().createWriter();
        fixedWidthWriter = new com.univocity.parsers.fixed.FixedWidthWriter(writer, settings);
        if (options.header()) {
            String[] header = new String[table.columnCount()];
            for (int c = 0; c < table.columnCount(); c++) {
                header[c] = table.column(c).name();
            }
            fixedWidthWriter.writeHeaders(header);
        }
        for (int r = 0; r < table.rowCount(); r++) {
            String[] entries = new String[table.columnCount()];
            for (int c = 0; c < table.columnCount(); c++) {
                table.get(r, c);
                entries[c] = table.getUnformatted(r, c);
            }
            fixedWidthWriter.writeRow(entries);
        }
    } finally {
        if (fixedWidthWriter != null) {
            fixedWidthWriter.flush();
            if (options.autoClose())
                fixedWidthWriter.close();
        }
    }
}
Also used : FixedWidthWriterSettings(com.univocity.parsers.fixed.FixedWidthWriterSettings) DataWriter(tech.tablesaw.io.DataWriter) Writer(java.io.Writer)

Example 5 with FixedWidthWriterSettings

use of com.univocity.parsers.fixed.FixedWidthWriterSettings in project symja_android_library by axkr.

the class FixedWidthWriter method fixedWidthWriterSettings.

protected FixedWidthWriterSettings fixedWidthWriterSettings(FixedWidthWriteOptions options) {
    FixedWidthWriterSettings settings = new FixedWidthWriterSettings();
    if (options.columnSpecs() != null) {
        settings = new FixedWidthWriterSettings(options.columnSpecs());
    }
    if (options.autoConfigurationEnabled()) {
        settings.setAutoConfigurationEnabled(options.autoConfigurationEnabled());
    } else {
        columnRowSettings(settings, options);
        errorSettings(settings, options);
        skipIgnoreSettings(settings, options);
    }
    return settings;
}
Also used : FixedWidthWriterSettings(com.univocity.parsers.fixed.FixedWidthWriterSettings)

Aggregations

FixedWidthWriterSettings (com.univocity.parsers.fixed.FixedWidthWriterSettings)5 Writer (java.io.Writer)2 DataWriter (tech.tablesaw.io.DataWriter)2 BeanWriterProcessor (com.univocity.parsers.common.processor.BeanWriterProcessor)1 FixedWidthWriter (com.univocity.parsers.fixed.FixedWidthWriter)1