Example usage for org.apache.commons.csv CSVFormat MYSQL

List of usage examples for org.apache.commons.csv CSVFormat MYSQL

Introduction

In this page you can find the example usage for org.apache.commons.csv CSVFormat MYSQL.

Prototype

CSVFormat MYSQL

To view the source code for org.apache.commons.csv CSVFormat MYSQL.

Click Source Link

Document

Default MySQL format used by the SELECT INTO OUTFILE and LOAD DATA INFILE operations.

Usage

From source file:org.apache.camel.dataformat.csv.CsvDataFormatTest.java

@Test
public void shouldUseSpecifiedFormat() {
    CsvDataFormat dataFormat = new CsvDataFormat().setFormat(CSVFormat.MYSQL);

    // Properly saved
    assertSame(CSVFormat.MYSQL, dataFormat.getFormat());

    // Properly used
    assertEquals(CSVFormat.MYSQL, dataFormat.getActiveFormat());
}

From source file:org.apache.logging.log4j.core.layout.CsvLogEventLayoutTest.java

@Test
public void testLayoutMySQL() throws Exception {
    testLayout(CSVFormat.MYSQL);
}

From source file:org.apache.nifi.csv.CSVUtils.java

public static CSVFormat createCSVFormat(final PropertyContext context) {
    final String formatName = context.getProperty(CSV_FORMAT).getValue();
    if (formatName.equalsIgnoreCase(CUSTOM.getValue())) {
        return buildCustomFormat(context);
    }//from  w w w  .  j  av  a 2  s  .c o m
    if (formatName.equalsIgnoreCase(RFC_4180.getValue())) {
        return CSVFormat.RFC4180;
    } else if (formatName.equalsIgnoreCase(EXCEL.getValue())) {
        return CSVFormat.EXCEL;
    } else if (formatName.equalsIgnoreCase(TDF.getValue())) {
        return CSVFormat.TDF;
    } else if (formatName.equalsIgnoreCase(MYSQL.getValue())) {
        return CSVFormat.MYSQL;
    } else if (formatName.equalsIgnoreCase(INFORMIX_UNLOAD.getValue())) {
        return CSVFormat.INFORMIX_UNLOAD;
    } else if (formatName.equalsIgnoreCase(INFORMIX_UNLOAD_CSV.getValue())) {
        return CSVFormat.INFORMIX_UNLOAD_CSV;
    } else {
        return CSVFormat.DEFAULT;
    }
}

From source file:org.jboss.jbossset.CommandLineParser.java

public CommandLineParser(String[] args) {
    this.args = args;

    validCSVFormats = new HashMap<>();
    validCSVFormats.put("excel", CSVFormat.EXCEL);
    validCSVFormats.put("mysql", CSVFormat.MYSQL);
    validCSVFormats.put("rfc4180", CSVFormat.RFC4180);
    validCSVFormats.put("tdf", CSVFormat.TDF);

    addOptions();/*from www  .  ja  v  a 2  s.  c o  m*/
}

From source file:org.jvalue.ods.processor.adapter.CsvSourceAdapter.java

@Inject
CsvSourceAdapter(@Assisted DataSource source,
        @Assisted(SourceAdapterFactory.ARGUMENT_SOURCE_URL) String sourceUrl,
        @Assisted(SourceAdapterFactory.ARGUMENT_CSV_FORMAT) String csvFormatString, MetricRegistry registry) {

    super(source, sourceUrl, registry);
    switch (csvFormatString) {
    case "DEFAULT":
        csvFormat = CSVFormat.DEFAULT;/*from w  ww .  j  av a 2 s  .co  m*/
        break;

    case "EXCEL":
        csvFormat = CSVFormat.EXCEL;
        break;

    case "MYSQL":
        csvFormat = CSVFormat.MYSQL;
        break;

    case "RFC4180":
        csvFormat = CSVFormat.RFC4180;
        break;

    case "TDF":
        csvFormat = CSVFormat.TDF;
        break;

    default:
        throw new IllegalArgumentException("unknown csv format \"" + csvFormatString + "\"");
    }
}

From source file:org.ohdsi.whiteRabbit.WhiteRabbitMain.java

private DbSettings getTargetDbSettings() {
    DbSettings dbSettings = new DbSettings();
    if (targetType.getSelectedItem().equals("Delimited text files")) {
        dbSettings.dataType = DbSettings.CSVFILES;

        switch ((String) targetCSVFormat.getSelectedItem()) {
        case "Default (comma, CRLF)":
            dbSettings.csvFormat = CSVFormat.DEFAULT;
            break;
        case "RFC4180":
            dbSettings.csvFormat = CSVFormat.RFC4180;
            break;
        case "Excel CSV":
            dbSettings.csvFormat = CSVFormat.EXCEL;
            break;
        case "TDF (tab, CRLF)":
            dbSettings.csvFormat = CSVFormat.TDF;
            break;
        case "MySQL (tab, LF)":
            dbSettings.csvFormat = CSVFormat.MYSQL;
            break;
        default:/* www  .j  ava2 s .  com*/
            dbSettings.csvFormat = CSVFormat.RFC4180;
        }

    } else {
        dbSettings.dataType = DbSettings.DATABASE;
        dbSettings.user = targetUserField.getText();
        dbSettings.password = targetPasswordField.getText();
        dbSettings.server = targetServerField.getText();
        dbSettings.database = targetDatabaseField.getText();
        if (targetType.getSelectedItem().toString().equals("MySQL"))
            dbSettings.dbType = DbType.MYSQL;
        else if (targetType.getSelectedItem().toString().equals("Oracle"))
            dbSettings.dbType = DbType.ORACLE;
        else if (sourceType.getSelectedItem().toString().equals("PostgreSQL"))
            dbSettings.dbType = DbType.POSTGRESQL;
        else if (sourceType.getSelectedItem().toString().equals("SQL Server")) {
            dbSettings.dbType = DbType.MSSQL;
            if (sourceUserField.getText().length() != 0) { // Not using windows authentication
                String[] parts = sourceUserField.getText().split("/");
                if (parts.length == 2) {
                    dbSettings.user = parts[1];
                    dbSettings.domain = parts[0];
                }
            }
        } else if (sourceType.getSelectedItem().toString().equals("PDW")) {
            dbSettings.dbType = DbType.PDW;
            if (sourceUserField.getText().length() != 0) { // Not using windows authentication
                String[] parts = sourceUserField.getText().split("/");
                if (parts.length == 2) {
                    dbSettings.user = parts[1];
                    dbSettings.domain = parts[0];
                }
            }
        }

        if (dbSettings.database.trim().length() == 0) {
            String message = "Please specify a name for the target database";
            JOptionPane.showMessageDialog(frame, StringUtilities.wordWrap(message, 80), "Database error",
                    JOptionPane.ERROR_MESSAGE);
            return null;
        }
    }
    return dbSettings;
}

From source file:us.parr.animl.data.DataTable.java

public static DataTable loadCSV(String fileName, String formatType, VariableType[] colTypesOverride,
        String[] colNamesOverride, boolean hasHeaderRow) {
    try {/*from  www . j  a  va2s  .  co m*/
        // use apache commons io + csv to load but convert to list of String[]
        // byte-order markers are handled if present at start of file.
        FileInputStream fis = new FileInputStream(fileName);
        final Reader reader = new InputStreamReader(new BOMInputStream(fis), "UTF-8");
        CSVFormat format;
        if (formatType == null) {
            format = hasHeaderRow ? CSVFormat.RFC4180.withHeader() : CSVFormat.RFC4180;
        } else {
            switch (formatType.toLowerCase()) {
            case "tsv":
                format = hasHeaderRow ? CSVFormat.TDF.withHeader() : CSVFormat.TDF;
                break;
            case "mysql":
                format = hasHeaderRow ? CSVFormat.MYSQL.withHeader() : CSVFormat.MYSQL;
                break;
            case "excel":
                format = hasHeaderRow ? CSVFormat.EXCEL.withHeader() : CSVFormat.EXCEL;
                break;
            case "rfc4180":
            default:
                format = hasHeaderRow ? CSVFormat.RFC4180.withHeader() : CSVFormat.RFC4180;
                break;
            }
        }
        final CSVParser parser = new CSVParser(reader, format);
        List<String[]> rows = new ArrayList<>();
        int numHeaderNames = parser.getHeaderMap().size();
        try {
            for (final CSVRecord record : parser) {
                String[] row = new String[record.size()];
                for (int j = 0; j < record.size(); j++) {
                    row[j] = record.get(j);
                }
                rows.add(row);
            }
        } finally {
            parser.close();
            reader.close();
        }

        VariableType[] actualTypes = computeColTypes(rows, numHeaderNames);

        Set<String> colNameSet = parser.getHeaderMap().keySet();
        String[] colNames = colNameSet.toArray(new String[colNameSet.size()]);
        if (colNamesOverride != null) {
            colNames = colNamesOverride;
        }
        if (colTypesOverride != null) {
            actualTypes = colTypesOverride;
        }
        return fromStrings(rows, actualTypes, colNames, false);
    } catch (Exception e) {
        throw new IllegalArgumentException("Can't open and/or read " + fileName, e);
    }
}