File tree Expand file tree Collapse file tree
src/test/java/org/apache/commons/csv Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3030
3131import java .io .File ;
3232import java .io .IOException ;
33+ import java .io .InputStreamReader ;
3334import java .io .Reader ;
3435import java .io .StringReader ;
3536import java .io .StringWriter ;
4142import java .util .Map ;
4243import java .util .NoSuchElementException ;
4344
45+ import org .apache .commons .io .input .BOMInputStream ;
4446import org .junit .Assert ;
4547import org .junit .Ignore ;
4648import 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\r baar,\r hello,world\r ,kanu" ;
You can’t perform that action at this time.
0 commit comments