3838import java .io .StringWriter ;
3939import java .net .URL ;
4040import java .nio .charset .Charset ;
41+ import java .nio .charset .StandardCharsets ;
4142import java .util .ArrayList ;
4243import java .util .Iterator ;
4344import java .util .List ;
6061 */
6162public class CSVParserTest {
6263
64+ private static final Charset UTF_8 = StandardCharsets .UTF_8 ;
65+
66+ private static final String UTF_8_NAME = UTF_8 .name ();
67+
6368 private static final String CSV_INPUT = "a,b,c,d\n " + " a , b , 1 2 \n " + "\" foo baar\" , b,\n "
6469 // + " \"foo\n,,\n\"\",,\n\\\"\",d,e\n";
6570 + " \" foo\n ,,\n \" \" ,,\n \" \" \" ,d,e\n " ; // changed to use standard CSV escaping
@@ -167,7 +172,7 @@ public void testBackslashEscapingOld() throws IOException {
167172 @ Ignore ("CSV-107" )
168173 public void testBOM () throws IOException {
169174 final URL url = ClassLoader .getSystemClassLoader ().getResource ("CSVFileParser/bom.csv" );
170- try (final CSVParser parser = CSVParser .parse (url , Charset .forName ("UTF-8" ), CSVFormat .EXCEL .withHeader ())) {
175+ try (final CSVParser parser = CSVParser .parse (url , Charset .forName (UTF_8_NAME ), CSVFormat .EXCEL .withHeader ())) {
171176 for (final CSVRecord record : parser ) {
172177 final String string = record .get ("Date" );
173178 Assert .assertNotNull (string );
@@ -178,7 +183,7 @@ public void testBOM() throws IOException {
178183
179184 @ Test
180185 public void testBOMInputStream_ParserWithReader () throws IOException {
181- try (final Reader reader = new InputStreamReader (createBOMInputStream ("CSVFileParser/bom.csv" ), "UTF-8" );
186+ try (final Reader reader = new InputStreamReader (createBOMInputStream ("CSVFileParser/bom.csv" ), UTF_8_NAME );
182187 final CSVParser parser = new CSVParser (reader , CSVFormat .EXCEL .withHeader ())) {
183188 for (final CSVRecord record : parser ) {
184189 final String string = record .get ("Date" );
@@ -190,7 +195,7 @@ public void testBOMInputStream_ParserWithReader() throws IOException {
190195
191196 @ Test
192197 public void testBOMInputStream_parseWithReader () throws IOException {
193- try (final Reader reader = new InputStreamReader (createBOMInputStream ("CSVFileParser/bom.csv" ), "UTF-8" );
198+ try (final Reader reader = new InputStreamReader (createBOMInputStream ("CSVFileParser/bom.csv" ), UTF_8_NAME );
194199 final CSVParser parser = CSVParser .parse (reader , CSVFormat .EXCEL .withHeader ())) {
195200 for (final CSVRecord record : parser ) {
196201 final String string = record .get ("Date" );
@@ -203,7 +208,7 @@ public void testBOMInputStream_parseWithReader() throws IOException {
203208 @ Test
204209 public void testBOMInputStream_ParserWithInputStream () throws IOException {
205210 try (final BOMInputStream inputStream = createBOMInputStream ("CSVFileParser/bom.csv" );
206- final CSVParser parser = CSVParser .parse (inputStream , "UTF-8" , CSVFormat .EXCEL .withHeader ())) {
211+ final CSVParser parser = CSVParser .parse (inputStream , UTF_8 , CSVFormat .EXCEL .withHeader ())) {
207212 for (final CSVRecord record : parser ) {
208213 final String string = record .get ("Date" );
209214 Assert .assertNotNull (string );
0 commit comments