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

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

Introduction

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

Prototype

CSVFormat TDF

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

Click Source Link

Document

Tab-delimited format.

Usage

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

@Test
public void testLayoutTab() throws Exception {
    final Logger root = (Logger) LogManager.getRootLogger();
    CsvParameterLayoutTest.testLayoutNormalApi(root, CsvParameterLayout.createLayout(CSVFormat.TDF), true);
}

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

@Test
public void testLayoutTab() throws Exception {
    final Logger root = this.init.getRootLogger();
    testLayoutNormalApi(root, CsvParameterLayout.createLayout(CSVFormat.TDF), true);
}

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);
    }/* ww  w . j ava 2  s  .  c  om*/
    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.apache.tika.parser.isatab.ISATabAssayParser.java

@Override
public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context)
        throws IOException, SAXException, TikaException {

    // Automatically detect the character encoding
    AutoDetectReader reader = new AutoDetectReader(new CloseShieldInputStream(stream), metadata,
            context.get(ServiceLoader.class, LOADER));
    CSVParser csvParser = null;/*from   www  . j  ava2  s.co m*/

    try {
        Charset charset = reader.getCharset();
        MediaType type = new MediaType(MediaType.application("x-isatab-assay"), charset);
        metadata.set(Metadata.CONTENT_TYPE, type.toString());
        metadata.set(Metadata.CONTENT_ENCODING, charset.name());

        XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
        xhtml.newline();

        csvParser = new CSVParser(reader, CSVFormat.TDF);

        xhtml.startDocument();
        xhtml.newline();

        xhtml.startElement("table");
        xhtml.newline();

        List<CSVRecord> records = csvParser.getRecords();

        for (int i = 0; i < records.get(0).size(); i++) {
            xhtml.startElement("th");
            xhtml.characters(records.get(0).get(i));
            xhtml.endElement("th");
            xhtml.newline();
        }

        for (int i = 1; i < records.size(); i++) {
            xhtml.startElement("tr");
            xhtml.newline();

            for (int j = 0; j < records.get(i).size(); j++) {
                xhtml.startElement("td");
                xhtml.characters(records.get(i).get(j));
                xhtml.endElement("td");
                xhtml.newline();
            }

            xhtml.endElement("tr");
            xhtml.newline();
        }

        xhtml.endElement("table");
        xhtml.newline();

        xhtml.endDocument();

    } finally {
        reader.close();
        csvParser.close();
    }
}

From source file:org.apache.tika.parser.isatab.ISATabStudyParser.java

@Override
public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context)
        throws IOException, SAXException, TikaException {

    // Automatically detect the character encoding
    AutoDetectReader reader = new AutoDetectReader(new CloseShieldInputStream(stream), metadata,
            context.get(ServiceLoader.class, LOADER));
    CSVParser csvParser = null;/*from   ww  w.  j a v a 2 s.com*/

    try {
        Charset charset = reader.getCharset();
        MediaType type = new MediaType(MediaType.application("x-isatab-study"), charset);
        metadata.set(Metadata.CONTENT_TYPE, type.toString());
        metadata.set(Metadata.CONTENT_ENCODING, charset.name());

        XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
        xhtml.newline();

        csvParser = new CSVParser(reader, CSVFormat.TDF);

        xhtml.startDocument();
        xhtml.newline();

        xhtml.startElement("table");
        xhtml.newline();

        List<CSVRecord> records = csvParser.getRecords();

        for (int i = 0; i < records.get(0).size(); i++) {
            xhtml.startElement("th");
            xhtml.characters(records.get(0).get(i));
            xhtml.endElement("th");
            xhtml.newline();
        }

        for (int i = 1; i < records.get(0).size(); i++) {
            xhtml.startElement("tr");
            xhtml.newline();

            for (int j = 0; j < records.get(i).size(); j++) {
                xhtml.startElement("td");
                xhtml.characters(records.get(i).get(j));
                xhtml.endElement("td");
                xhtml.newline();
            }

            xhtml.endElement("tr");
            xhtml.newline();
        }

        xhtml.endElement("table");
        xhtml.newline();

        xhtml.endDocument();

    } finally {
        reader.close();
        csvParser.close();
    }
}

From source file:org.apache.tika.parser.isatab.ISATabUtils.java

public static void parseStudy(InputStream stream, XHTMLContentHandler xhtml, Metadata metadata,
        ParseContext context) throws IOException, TikaException, SAXException {
    TikaInputStream tis = TikaInputStream.get(stream);
    // Automatically detect the character encoding
    TikaConfig tikaConfig = context.get(TikaConfig.class);
    if (tikaConfig == null) {
        tikaConfig = TikaConfig.getDefaultConfig();
    }/*from   ww w.jav a  2 s  . c o m*/
    try (AutoDetectReader reader = new AutoDetectReader(new CloseShieldInputStream(tis), metadata,
            tikaConfig.getEncodingDetector()); CSVParser csvParser = new CSVParser(reader, CSVFormat.TDF)) {
        Iterator<CSVRecord> iterator = csvParser.iterator();

        xhtml.startElement("table");

        xhtml.startElement("thead");
        if (iterator.hasNext()) {
            CSVRecord record = iterator.next();
            for (int i = 0; i < record.size(); i++) {
                xhtml.startElement("th");
                xhtml.characters(record.get(i));
                xhtml.endElement("th");
            }
        }
        xhtml.endElement("thead");

        xhtml.startElement("tbody");
        while (iterator.hasNext()) {
            CSVRecord record = iterator.next();
            xhtml.startElement("tr");
            for (int j = 0; j < record.size(); j++) {
                xhtml.startElement("td");
                xhtml.characters(record.get(j));
                xhtml.endElement("td");
            }
            xhtml.endElement("tr");
        }
        xhtml.endElement("tbody");

        xhtml.endElement("table");
    }
}

From source file:org.apache.tika.parser.isatab.ISATabUtils.java

public static void parseAssay(InputStream stream, XHTMLContentHandler xhtml, Metadata metadata,
        ParseContext context) throws IOException, TikaException, SAXException {
    TikaInputStream tis = TikaInputStream.get(stream);

    // Automatically detect the character encoding

    TikaConfig tikaConfig = context.get(TikaConfig.class);
    if (tikaConfig == null) {
        tikaConfig = TikaConfig.getDefaultConfig();
    }/*from  w ww  . j a  va  2s  .  c om*/
    try (AutoDetectReader reader = new AutoDetectReader(new CloseShieldInputStream(tis), metadata,
            tikaConfig.getEncodingDetector()); CSVParser csvParser = new CSVParser(reader, CSVFormat.TDF)) {
        xhtml.startElement("table");

        Iterator<CSVRecord> iterator = csvParser.iterator();

        xhtml.startElement("thead");
        if (iterator.hasNext()) {
            CSVRecord record = iterator.next();
            for (int i = 0; i < record.size(); i++) {
                xhtml.startElement("th");
                xhtml.characters(record.get(i));
                xhtml.endElement("th");
            }
        }
        xhtml.endElement("thead");

        xhtml.startElement("tbody");
        while (iterator.hasNext()) {
            CSVRecord record = iterator.next();
            xhtml.startElement("tr");
            for (int j = 0; j < record.size(); j++) {
                xhtml.startElement("td");
                xhtml.characters(record.get(j));
                xhtml.endElement("td");
            }
            xhtml.endElement("tr");
        }
        xhtml.endElement("tbody");

        xhtml.endElement("table");
    }
}

From source file:org.apache.tika.parser.isatab.ISATabUtils.java

private static void extractMetadata(Reader reader, Metadata metadata, String studyFileName) throws IOException {
    boolean investigationSection = false;
    boolean studySection = false;
    boolean studyTarget = false;

    Map<String, String> map = new HashMap<String, String>();

    try (CSVParser csvParser = new CSVParser(reader, CSVFormat.TDF)) {
        Iterator<CSVRecord> iterator = csvParser.iterator();

        while (iterator.hasNext()) {
            CSVRecord record = iterator.next();
            String field = record.get(0);
            if ((field.toUpperCase(Locale.ENGLISH).equals(field)) && (record.size() == 1)) {
                investigationSection = Arrays.asList(sections).contains(field);
                studySection = (studyFileName != null) && (field.equals(studySectionField));
            } else {
                if (investigationSection) {
                    addMetadata(field, record, metadata);
                } else if (studySection) {
                    if (studyTarget) {
                        break;
                    }/*from  ww w .j  a  v a2  s .  co m*/
                    String value = record.get(1);
                    map.put(field, value);
                    studyTarget = (field.equals(studyFileNameField)) && (value.equals(studyFileName));
                    if (studyTarget) {
                        mapStudyToMetadata(map, metadata);
                        studySection = false;
                    }
                } else if (studyTarget) {
                    addMetadata(field, record, metadata);
                }
            }
        }
    } catch (IOException ioe) {
        throw ioe;
    }
}

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();//  w  w  w .  j av a 2 s . c  om
}

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 w w.  jav a2s. 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 + "\"");
    }
}