Skip to content

Commit

Permalink
Merge pull request #232 from mivek/bugfix/CSV-parser
Browse files Browse the repository at this point in the history
Fix the CSV
  • Loading branch information
mivek authored Feb 5, 2021
2 parents a62a975 + 1c65edd commit d4674b3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.mivek.provider.airport.impl;

import com.opencsv.CSVParser;
import com.opencsv.CSVParserBuilder;
import com.opencsv.CSVReader;
import com.opencsv.CSVReaderBuilder;
import com.opencsv.exceptions.CsvValidationException;
Expand Down Expand Up @@ -33,6 +34,8 @@ public final class OurAirportsAirportProvider implements AirportProvider {
private Map<String, Country> countries;
/** Map of airports. */
private Map<String, Airport> airports;
/** Common CSV Parser. */
private final CSVParser parser;

/**
* Default constructor.
Expand All @@ -44,6 +47,7 @@ public final class OurAirportsAirportProvider implements AirportProvider {
public OurAirportsAirportProvider() throws CsvValidationException, IOException, URISyntaxException {
countries = new HashMap<>();
airports = new HashMap<>();
parser = new CSVParserBuilder().withIgnoreQuotations(true).build();
buildCountries();
buildAirport();
}
Expand All @@ -59,7 +63,7 @@ public void buildCountries() throws URISyntaxException, IOException, CsvValidati
countries = new HashMap<>();
URI countriesUri = new URI(COUNTRIES_URI);
try (InputStream countriesStream = countriesUri.toURL().openStream();
CSVReader reader = new CSVReaderBuilder(new InputStreamReader(countriesStream, StandardCharsets.UTF_8)).withCSVParser(new CSVParser()).withSkipLines(1).build()) {
CSVReader reader = new CSVReaderBuilder(new InputStreamReader(countriesStream, StandardCharsets.UTF_8)).withCSVParser(parser).withSkipLines(1).build()) {
String[] line;
while ((line = reader.readNext()) != null) {
Country c = new Country();
Expand All @@ -80,7 +84,7 @@ public void buildAirport() throws URISyntaxException, IOException, CsvValidation
URI airportsURI = new URI(AIRPORT_URI);
airports = new HashMap<>();
try (InputStream airportStream = airportsURI.toURL().openStream();
CSVReader reader = new CSVReaderBuilder(new InputStreamReader(airportStream, StandardCharsets.UTF_8)).withCSVParser(new CSVParser()).withSkipLines(1).build()) {
CSVReader reader = new CSVReaderBuilder(new InputStreamReader(airportStream, StandardCharsets.UTF_8)).withCSVParser(parser).withSkipLines(1).build()) {
String[] line;

while ((line = reader.readNext()) != null) {
Expand Down
14 changes: 11 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,19 @@
<junit.version>4.13.1</junit.version>
<hamcrest.version>2.2</hamcrest.version>
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<spotbugs-maven-plugin.version>4.1.4</spotbugs-maven-plugin.version>
<spotbugs-maven-plugin.version>4.2.0</spotbugs-maven-plugin.version>
<commons-lang3.version>3.11</commons-lang3.version>
<opencsv.version>5.3</opencsv.version>
<pitmp-maven-plugin.version>1.3.7</pitmp-maven-plugin.version>
<jacoco.coverage.instruction.minimum>0.98</jacoco.coverage.instruction.minimum>
<jacoco.coverage.branch.minimum>0.96</jacoco.coverage.branch.minimum>
<jacoco.coverage.complexity.minimum>0.97</jacoco.coverage.complexity.minimum>
<archunit-junit4.version>0.14.1</archunit-junit4.version>
<archunit-junit4.version>0.16.0</archunit-junit4.version>
<maven-project-info-reports-plugin.version>3.1.1</maven-project-info-reports-plugin.version>
<maven-site-plugin.version>3.9.1</maven-site-plugin.version>
<maven-surefire-plugin.version>3.0.0-M5</maven-surefire-plugin.version>
<jacoco-maven-plugin.version>0.8.6</jacoco-maven-plugin.version>
<maven-checkstyle-plugin.version>3.1.2</maven-checkstyle-plugin.version>
</properties>

<developers>
Expand Down Expand Up @@ -234,7 +235,14 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.1</version>
<version>${maven-checkstyle-plugin.version}</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.35</version>
</dependency>
</dependencies>
<configuration>
<excludes>*Test.java</excludes>
<configLocation>/checkstyle.xml</configLocation>
Expand Down

0 comments on commit d4674b3

Please sign in to comment.