Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added mneri/csv parser (https://github.com/mneri/csv) #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,12 @@
<version>3.1.0-RELEASE</version>
</dependency>

<dependency>
<groupId>com.github.mneri</groupId>
<artifactId>csv</artifactId>
<version>1.1</version>
</dependency>

</dependencies>

<build>
Expand Down Expand Up @@ -414,6 +420,12 @@
<url>https://jcenter.bintray.com</url>
</repository>

<!-- Needed for mneri/csv -->
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>

</repositories>

</profile>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*******************************************************************************
* Copyright 2014 uniVocity Software Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package com.univocity.articles.csvcomparison.parser;

import me.mneri.csv.CsvDeserializer;
import me.mneri.csv.CsvException;
import me.mneri.csv.CsvReader;
import me.mneri.csv.RecyclableCsvLine;

import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.List;

class MneriCsvParser extends AbstractParser {
private static class DummyDeserializer implements CsvDeserializer<RecyclableCsvLine> {
@Override
public RecyclableCsvLine deserialize(RecyclableCsvLine line) {
// At this point parsing has been completed. For the sake of the benchmark we return line here, but you
// never want to do that. In fact, line is recycled between iterations of CsvReader.
return line;
}
}

private static class StringArrayCsvDeserializer implements CsvDeserializer<String[]> {
@Override
public String[] deserialize(RecyclableCsvLine line) {
int count = line.getFieldCount();
String[] strings = new String[count];

for (int i = 0; i < count; i++) {
strings[i] = line.getString(i);
}

return strings;
}
}

protected MneriCsvParser() {
super("mneri/csv");
}

@Override
public List<String[]> parseRows(final Reader input) throws IOException, CsvException {
List<String[]> lines = new ArrayList<String[]>();
CsvReader<String[]> reader = null;

try {
reader = CsvReader.open(input, new StringArrayCsvDeserializer());

while (reader.hasNext()) {
lines.add(reader.next());
}
} finally {
if (reader != null) {
reader.close();
}
}

return lines;
}

@Override
public void processRows(final Reader input) throws IOException, CsvException {
CsvReader<?> reader = null;

try {
reader = CsvReader.open(input, new DummyDeserializer());

while (reader.hasNext()) {
process(reader.next());
}
} finally {
if (reader != null) {
reader.close();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public class Parsers {
new OsterMillerParser(),
new JacksonParser(),
new SimpleFlatMapperParser(),
new ProductCollectionsParser()
new ProductCollectionsParser(),
new MneriCsvParser()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add it to Parsers in the parsers8 package as your parser will not work with Java 6 or 7 as far as I know (also move the MneriCsvParser into that package).

);

private Parsers() {
Expand Down