Skip to content

Commit c4f7475

Browse files
committed
Testing [CSV-107] CSVFormat.EXCEL.parse should handle byte order marks
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1578196 13f79535-47bb-0310-9956-ffa450edef68
1 parent c473d87 commit c4f7475

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

src/test/java/org/apache/commons/csv/CSVParserTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import java.io.File;
3232
import java.io.IOException;
33+
import java.io.InputStreamReader;
3334
import java.io.Reader;
3435
import java.io.StringReader;
3536
import java.io.StringWriter;
@@ -41,6 +42,7 @@
4142
import java.util.Map;
4243
import java.util.NoSuchElementException;
4344

45+
import org.apache.commons.io.input.BOMInputStream;
4446
import org.junit.Assert;
4547
import org.junit.Ignore;
4648
import org.junit.Test;
@@ -176,6 +178,34 @@ public void testBackslashEscapingOld() throws IOException {
176178
}
177179
}
178180

181+
@Test
182+
@Ignore("CSV-107")
183+
public void testBOM() throws IOException {
184+
URL url = ClassLoader.getSystemClassLoader().getResource("CSVFileParser/bom.csv");
185+
final CSVParser parser = CSVParser.parse(url, null, CSVFormat.EXCEL.withHeader());
186+
try {
187+
for (CSVRecord record : parser) {
188+
System.out.println("date: " + record.get("Date"));
189+
}
190+
} finally {
191+
parser.close();
192+
}
193+
}
194+
195+
@Test
196+
public void testBOMInputStream() throws IOException {
197+
URL url = ClassLoader.getSystemClassLoader().getResource("CSVFileParser/bom.csv");
198+
Reader reader = new InputStreamReader(new BOMInputStream(url.openStream()), "UTF-8");
199+
final CSVParser parser = new CSVParser(reader, CSVFormat.EXCEL.withHeader());
200+
try {
201+
for (CSVRecord record : parser) {
202+
System.out.println("date: " + record.get("Date"));
203+
}
204+
} finally {
205+
parser.close();
206+
}
207+
}
208+
179209
@Test
180210
public void testCarriageReturnEndings() throws IOException {
181211
final String code = "foo\rbaar,\rhello,world\r,kanu";

0 commit comments

Comments
 (0)