Skip to content

Commit 21a80d4

Browse files
authored
Merge pull request #1 from apache/master
Rebase
2 parents b2a50d4 + a775784 commit 21a80d4

10 files changed

Lines changed: 18887 additions & 28 deletions

File tree

.travis.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one or more
2+
# contributor license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright ownership.
4+
# The ASF licenses this file to You under the Apache License, Version 2.0
5+
# (the "License"); you may not use this file except in compliance with
6+
# the License. You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
language: java
17+
sudo: false
18+
19+
jdk:
20+
- openjdk7
21+
- oraclejdk7
22+
- oraclejdk8
23+
24+
after_success:
25+
- mvn -B -V -Ptravis-jacoco clean test jacoco:report coveralls:report

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ Apache Commons CSV
4646
The Apache Commons CSV library provides a simple interface for reading and writing
4747
CSV files of various types.
4848

49+
[![Build Status](https://travis-ci.org/apache/commons-csv.svg?branch=master)](https://travis-ci.org/apache/commons-csv)
50+
[![Coverage Status](https://coveralls.io/repos/github/apache/commons-csv/badge.svg?branch=master)](https://coveralls.io/github/apache/commons-csv?branch=master)
51+
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.apache.commons/commons-csv/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.apache.commons/commons-csv/)
52+
[![License](http://img.shields.io/:license-apache-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0.html)
53+
4954
Documentation
5055
-------------
5156

@@ -63,7 +68,7 @@ Alternatively you can pull it from the central Maven repositories:
6368
<dependency>
6469
<groupId>org.apache.commons</groupId>
6570
<artifactId>commons-csv</artifactId>
66-
<version>1.3</version>
71+
<version>1.4</version>
6772
</dependency>
6873
```
6974

pom.xml

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
<?xml version="1.0"?>
22
<!--
3-
Licensed to the Apache Software Foundation (ASF) under one or more
4-
contributor license agreements. See the NOTICE file distributed with
5-
this work for additional information regarding copyright ownership.
6-
The ASF licenses this file to You under the Apache License, Version 2.0
7-
(the "License"); you may not use this file except in compliance with
8-
the License. You may obtain a copy of the License at
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
99
10-
http://www.apache.org/licenses/LICENSE-2.0
10+
http://www.apache.org/licenses/LICENSE-2.0
1111
12-
Unless required by applicable law or agreed to in writing, software
13-
distributed under the License is distributed on an "AS IS" BASIS,
14-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15-
See the License for the specific language governing permissions and
16-
limitations under the License.
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
1717
-->
1818
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
1919
<modelVersion>4.0.0</modelVersion>
2020
<parent>
2121
<groupId>org.apache.commons</groupId>
2222
<artifactId>commons-parent</artifactId>
23-
<version>40</version>
23+
<version>42</version>
2424
</parent>
25-
<groupId>org.apache.commons</groupId>
2625
<artifactId>commons-csv</artifactId>
2726
<version>1.5-SNAPSHOT</version>
2827
<name>Apache Commons CSV</name>
@@ -414,9 +413,9 @@ CSV files of various types.
414413
</dependency>
415414

416415
<dependency>
417-
<groupId>net.sourceforge.javacsv</groupId>
418-
<artifactId>javacsv</artifactId>
419-
<version>2.0</version>
416+
<groupId>net.sourceforge.javacsv</groupId>
417+
<artifactId>javacsv</artifactId>
418+
<version>2.0</version>
420419
<scope>test</scope>
421420
</dependency>
422421

src/changes/changes.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@
4343
<action issue="CSV-193" type="fix" dev="ggregory" due-to="Matthias Wiehl">Fix incorrect method name 'withFirstRowAsHeader' in user guide.</action>
4444
<action issue="CSV-171" type="fix" dev="ggregory" due-to="Gary Gregory, Michael Graessle, Adrian Bridgett">Negative numeric values in the first column are always quoted in minimal mode.</action>
4545
<action issue="CSV-187" type="update" dev="ggregory" due-to="Gary Gregory">Update platform requirement from Java 6 to 7.</action>
46+
<action issue="CSV-201" type="update" dev="ggregory" due-to="Benedikt Ritter, Gary Gregory">Do not use RuntimeException in CSVParser.iterator().new Iterator() {...}.getNextRecord()</action>
4647
<action issue="CSV-189" type="add" dev="ggregory" due-to="Peter Holzwarth, Gary Gregory">CSVParser: Add factory method accepting InputStream.</action>
4748
<action issue="CSV-190" type="add" dev="ggregory" due-to="Gary Gregory">Add convenience API CSVFormat.print(File, Charset)</action>
4849
<action issue="CSV-191" type="add" dev="ggregory" due-to="Gary Gregory">Add convenience API CSVFormat.print(Path, Charset)</action>
4950
<action issue="CSV-192" type="add" dev="ggregory" due-to="Gary Gregory">Add convenience API CSVParser.parse(Path, Charset, CSVFormat)</action>
51+
<action issue="CSV-205" type="add" dev="ggregory" due-to="Gary Gregory">Add convenience API CSVFormat#printer() to print to System.out</action>
5052
</release>
5153
<release version="1.4" date="2016-05-28" description="Feature and bug fix release">
5254
<action issue="CSV-181" type="update" dev="ggregory" due-to="Gary Gregory">Make CSVPrinter.print(Object) GC-free.</action>

src/main/java/org/apache/commons/csv/CSVFormat.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,22 @@ public CSVPrinter print(final Appendable out) throws IOException {
869869
return new CSVPrinter(out, this);
870870
}
871871

872+
/**
873+
* Prints to the {@link System#out}.
874+
*
875+
* <p>
876+
* See also {@link CSVPrinter}.
877+
* </p>
878+
*
879+
* @return a printer to {@link System#out}.
880+
* @throws IOException
881+
* thrown if the optional header cannot be printed.
882+
* @since 1.5
883+
*/
884+
public CSVPrinter printer() throws IOException {
885+
return new CSVPrinter(System.out, this);
886+
}
887+
872888
/**
873889
* Prints to the specified output.
874890
*

src/main/java/org/apache/commons/csv/CSVParser.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ public static CSVParser parse(final File file, final Charset charset, final CSVF
165165
* call {@link #close()} on the parser, unless you close the {@code reader}.
166166
* </p>
167167
*
168-
* @param reader
169-
* a Reader containing CSV-formatted input. Must not be null.
168+
* @param inputStream
169+
* an InputStream containing CSV-formatted input. Must not be null.
170170
* @param charset
171171
* a Charset.
172172
* @param format
@@ -501,10 +501,14 @@ public boolean isClosed() {
501501
/**
502502
* Returns an iterator on the records.
503503
*
504-
* <p>IOExceptions occurring during the iteration are wrapped in a
505-
* RuntimeException.
506-
* If the parser is closed a call to {@code next()} will throw a
507-
* NoSuchElementException.</p>
504+
* <p>
505+
* An {@link IOException} caught during the iteration are re-thrown as an
506+
* {@link IllegalStateException}.
507+
* </p>
508+
* <p>
509+
* If the parser is closed a call to {@link Iterator#next()} will throw a
510+
* {@link NoSuchElementException}.
511+
* </p>
508512
*/
509513
@Override
510514
public Iterator<CSVRecord> iterator() {
@@ -515,8 +519,8 @@ private CSVRecord getNextRecord() {
515519
try {
516520
return CSVParser.this.nextRecord();
517521
} catch (final IOException e) {
518-
// TODO: This is not great, throw an ISE instead?
519-
throw new RuntimeException(e);
522+
throw new IllegalStateException(
523+
e.getClass().getSimpleName() + " reading next record: " + e.toString(), e);
520524
}
521525
}
522526

src/test/java/org/apache/commons/csv/bugs/JiraCsv164Test.java renamed to src/test/java/org/apache/commons/csv/issues/JiraCsv164Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
package org.apache.commons.csv.bugs;
17+
package org.apache.commons.csv.issues;
1818

1919
import static org.junit.Assert.assertTrue;
2020

src/test/java/org/apache/commons/csv/bugs/JiraCsv167Test.java renamed to src/test/java/org/apache/commons/csv/issues/JiraCsv167Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
package org.apache.commons.csv.bugs;
17+
package org.apache.commons.csv.issues;
1818

1919
import java.io.BufferedReader;
2020
import java.io.IOException;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.commons.csv.issues;
18+
19+
import java.io.IOException;
20+
import java.io.InputStream;
21+
import java.io.InputStreamReader;
22+
import java.io.UnsupportedEncodingException;
23+
24+
import org.apache.commons.csv.CSVFormat;
25+
import org.apache.commons.csv.CSVParser;
26+
import org.apache.commons.csv.CSVRecord;
27+
import org.junit.Assert;
28+
import org.junit.Test;
29+
30+
public class JiraCsv198Test {
31+
32+
private static final CSVFormat CSV_FORMAT = CSVFormat.EXCEL.withDelimiter('^').withFirstRecordAsHeader();
33+
34+
@Test
35+
public void test() throws UnsupportedEncodingException, IOException {
36+
InputStream pointsOfReference = getClass().getResourceAsStream("/CSV-198/optd_por_public.csv");
37+
Assert.assertNotNull(pointsOfReference);
38+
try (@SuppressWarnings("resource")
39+
CSVParser parser = CSV_FORMAT.parse(new InputStreamReader(pointsOfReference, "UTF-8"))) {
40+
for (CSVRecord record : parser) {
41+
String locationType = record.get("location_type");
42+
Assert.assertNotNull(locationType);
43+
}
44+
}
45+
}
46+
47+
}

0 commit comments

Comments
 (0)