diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemWriter.java index 2443908427..1c7f2bb55f 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2018 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package org.springframework.batch.item.file; +import java.nio.charset.Charset; import java.util.List; import org.springframework.batch.item.file.transform.LineAggregator; @@ -39,11 +40,15 @@ * @author Dave Syer * @author Michael Minella * @author Mahmoud Ben Hassine + * @author Glenn Renfro */ public class FlatFileItemWriter extends AbstractFileItemWriter { protected LineAggregator lineAggregator; + // default encoding for writing to flat files - set to charset of this Java virtual machine. + public static final String DEFAULT_CHARSET = Charset.defaultCharset().name(); + public FlatFileItemWriter() { this.setExecutionContextName(ClassUtils.getShortName(FlatFileItemWriter.class)); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/builder/FlatFileItemWriterBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/builder/FlatFileItemWriterBuilderTests.java index bda8417c50..0aae1d2a90 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/builder/FlatFileItemWriterBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/builder/FlatFileItemWriterBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 the original author or authors. + * Copyright 2016-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStreamReader; +import java.nio.charset.Charset; import java.util.Arrays; import org.junit.Test; @@ -38,6 +39,7 @@ * @author Michael Minella * @author Mahmoud Ben Hassine * @author Drummond Dawson + * @author Glenn Renfro */ public class FlatFileItemWriterBuilderTests { @@ -275,13 +277,13 @@ public void testFlags() throws Exception { .transactional(false) .lineAggregator(new PassThroughLineAggregator<>()) .build(); - assertFalse((Boolean) ReflectionTestUtils.getField(writer, "saveState")); assertTrue((Boolean) ReflectionTestUtils.getField(writer, "append")); assertFalse((Boolean) ReflectionTestUtils.getField(writer, "transactional")); assertTrue((Boolean) ReflectionTestUtils.getField(writer, "shouldDeleteIfEmpty")); assertFalse((Boolean) ReflectionTestUtils.getField(writer, "shouldDeleteIfExists")); assertTrue((Boolean) ReflectionTestUtils.getField(writer, "forceSync")); + assertEquals( Charset.defaultCharset().name(), ReflectionTestUtils.getField(writer, "encoding")); } private String readLine(String encoding, Resource outputFile ) throws IOException {