We are committed to implement the absolutely most efficient code, with all the features you need.
Download and see for yourself.

Speed

Our parsers offer the faster implementations you can get. Our CSV parser is at least 40% faster than any other CSV parser for Java. See the comparison on Github!

Flexibility

Map records to simple Strings:

    String[] row;
    while ((row = parser.parseNext()) != null) {
        System.out.println(Arrays.toString(row));
    }

 

Or convert them to Objects:

    rowProcessor
            .convertFields(Conversions.toDate("yyyy-MMM-dd"))
            .set("dateOfBirth", "dateJoined");

 

Or even fields i n JavaBeans, using annotations:

    @Trim
    @LowerCase
    @BooleanString(falseStrings = { "no", "n", "null" }, trueStrings = { "yes", "y" })
    @Parsed
    private Boolean pending;

 

You can easily define custom processors to execute all sorts of operations over the records, and even write your own parser for your specific format.

Field selection

Don't waste resources and processing power parsing unwanted values. You can select specific fields on an input text and get only values from these, in the order you specify.

For example, using the following CSV:


    Year,Make,Model,Description,Price
    1997,Ford,E350,"ac, abs, moon",3000.00
    1999,Chevy,"Venture ""Extended Edition""","",4900.00

 

You can select some fields:

    parserSettings.selectFields("Price", "Year", "Make");

 

To produce:


    3000.00, 1997, Ford
    4900.00, 1999, Chevy

 

When writing, simply define what values you have for each record, in whatever order you need, and uniVocity-parsers will write all records in the correct format.

    writer.writeRow(3000.00, 1997, "Ford");
    writer.writeRow(4900.00, 1999, "Chevy");

 

The result will be:


    Year,Make,Model,Description,Price
    1997,Ford,,,3000.00
    1999,Chevy,,,4900.00

 

Parellel input buffering

Parsers written on top of uniVocity-parsers architecture will buffer input files' content using a separate thread to optimize the processing of large inputs even further.

Easy to extend

We made it easy for you to create your own parsers. All existing features of the uniVocity-parsers architecture will work out of the box for your parser. You won't need much to create a feature-complete parser from scratch.

This is our entire CSV parser implementation:

public class CsvParser extends AbstractParser<CsvParserSettings> {

    private final boolean ignoreTrailingWhitespace;
    private final boolean ignoreLeadingWhitespace;

    private final char delimiter;
    private final char quote;
    private final char quoteEscape;
    private final char newLine;
    public CsvParser(CsvParserSettings settings) {
        super(settings);
        ignoreTrailingWhitespace = settings.getIgnoreTrailingWhitespaces();
        ignoreLeadingWhitespace = settings.getIgnoreLeadingWhitespaces();

        CsvFormat format = settings.getFormat();
        delimiter = format.getDelimiter();
        quote = format.getQuote();
        quoteEscape = format.getQuoteEscape();
        newLine = format.getNormalizedNewline();
    }

    @Override
    protected void parseRecord() {
        if (ch <= ' ' && ignoreLeadingWhitespace) {
            skipWhitespace();
        }
        while (ch != newLine) {
            parseField();
            if (ch != newLine) {
                ch = input.nextChar();
                if (ch == newLine) {
                    output.emptyParsed();
                }
            }
        }
    }

    private void parseValue() {
        if (ignoreTrailingWhitespace) {
            while (ch != delimiter && ch != newLine) {
                output.appender.appendIgnoringWhitespace(ch);
                ch = input.nextChar();
            }
        } else {
            while (ch != delimiter && ch != newLine) {
                output.appender.append(ch);
                ch = input.nextChar();
            }
        }
    }

    private void parseQuotedValue() {
        char prev = '\0';
        ch = input.nextChar();

        while (!(prev == quote && (ch == delimiter || ch <= ' '))) {
            if (ch != quote) {
                output.appender.append(ch);
                prev = ch;
            } else if (prev == quoteEscape) {
                output.appender.append(quote);
                prev = '\0';
            } else {
                prev = ch;
            }
            ch = input.nextChar();
        }
        if (ch <= ' ') {
            skipWhitespace();
        }
    }

    private void parseField() {
        if (ch <= ' ' && ignoreLeadingWhitespace) {
            skipWhitespace();
        }
        if (ch == delimiter) {
            output.emptyParsed();
        } else {
            if (ch == quote) {
                parseQuotedValue();
            } else {
                parseValue();
            }
            output.valueParsed();
        }
    }

    private void skipWhitespace() {
        while (ch <= ' ' && ch != delimiter && ch != newLine) {
            ch = input.nextChar();
        }
    }
}

 

Try and create your own parsers!


Let's build the best suite of parsers together! Contributions are welcome.

Check our tutorials, documentation and source code.