Search in sources :

Example 1 with ParseAnalysis

use of com.khartec.waltz.model.catalog.ParseAnalysis in project waltz by khartec.

the class TabularFileAnalyserTest method foo.

@Test
public void foo() throws IOException {
    char[] delimeters = new char[] { ',', '|', '\t', ';', '!' };
    char[] quoteChars = new char[] { '"', '\'' };
    List<ParseAnalysis> analysisResults = ListUtilities.newArrayList();
    for (char quoteChar : quoteChars) {
        for (char delimeter : delimeters) {
            InputStreamReader simpleReader = getReader();
            CsvPreference prefs = new CsvPreference.Builder(quoteChar, delimeter, "\n").ignoreEmptyLines(false).build();
            CsvListReader csvReader = new CsvListReader(simpleReader, prefs);
            List<String> cells = csvReader.read();
            ImmutableParseAnalysis.Builder parseAnalysisBuilder = ImmutableParseAnalysis.builder().quoteChar(quoteChar).delimiterChar(delimeter);
            while (cells != null) {
                parseAnalysisBuilder.addFieldCounts(cells.size());
                cells = csvReader.read();
            }
            ParseAnalysis parseAnalysis = parseAnalysisBuilder.build();
            analysisResults.add(parseAnalysis);
        }
    }
    analysisResults.forEach(r -> {
        System.out.println(r.quoteChar() + " " + r.delimiterChar() + " => [ " + r.fieldCounts().size() + " ] " + r.fieldCounts());
    });
}
Also used : CsvPreference(org.supercsv.prefs.CsvPreference) CsvListReader(org.supercsv.io.CsvListReader) InputStreamReader(java.io.InputStreamReader) ImmutableParseAnalysis(com.khartec.waltz.model.catalog.ImmutableParseAnalysis) ImmutableParseAnalysis(com.khartec.waltz.model.catalog.ImmutableParseAnalysis) ParseAnalysis(com.khartec.waltz.model.catalog.ParseAnalysis) Test(org.junit.Test)

Aggregations

ImmutableParseAnalysis (com.khartec.waltz.model.catalog.ImmutableParseAnalysis)1 ParseAnalysis (com.khartec.waltz.model.catalog.ParseAnalysis)1 InputStreamReader (java.io.InputStreamReader)1 Test (org.junit.Test)1 CsvListReader (org.supercsv.io.CsvListReader)1 CsvPreference (org.supercsv.prefs.CsvPreference)1