diff --git a/spring-batch-docs/src/main/asciidoc/readersAndWriters.adoc b/spring-batch-docs/src/main/asciidoc/readersAndWriters.adoc index 1f3b4f4ae..ce60b65e0 100644 --- a/spring-batch-docs/src/main/asciidoc/readersAndWriters.adoc +++ b/spring-batch-docs/src/main/asciidoc/readersAndWriters.adoc @@ -285,7 +285,7 @@ interpreted, as described in the following table: |=============== |Property|Type|Description |comments|String[]|Specifies line prefixes that indicate comment rows. -|encoding|String|Specifies what text encoding to use. The default is the value of `Charset.defaultCharset()`. +|encoding|String|Specifies what text encoding to use. The default value is `UTF-8`. |lineMapper|`LineMapper`|Converts a `String` to an `Object` representing the item. |linesToSkip|int|Number of lines to ignore at the top of the file. |recordSeparatorPolicy|RecordSeparatorPolicy|Used to determine where the line endings are diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemReader.java index 9e4e737bb..1b1eca32b 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2020 the original author or authors. + * Copyright 2006-2022 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 @@ package org.springframework.batch.item.file; import java.io.BufferedReader; import java.io.IOException; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -48,8 +49,7 @@ public class FlatFileItemReader extends AbstractItemCountingItemStreamItemRea private static final Log logger = LogFactory.getLog(FlatFileItemReader.class); - // default encoding for input files - public static final String DEFAULT_CHARSET = Charset.defaultCharset().name(); + public static final String DEFAULT_CHARSET = StandardCharsets.UTF_8.name(); public static final String[] DEFAULT_COMMENT_PREFIXES = new String[] { "#" }; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/AbstractFileItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/AbstractFileItemWriter.java index 1b2911154..069ef3140 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/AbstractFileItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/AbstractFileItemWriter.java @@ -24,6 +24,7 @@ import java.io.Writer; import java.nio.channels.Channels; import java.nio.channels.FileChannel; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.nio.charset.UnsupportedCharsetException; import java.util.List; @@ -74,8 +75,7 @@ public abstract class AbstractFileItemWriter extends AbstractItemStreamItemWr public static final String DEFAULT_LINE_SEPARATOR = System.getProperty("line.separator"); - // 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 static final String DEFAULT_CHARSET = StandardCharsets.UTF_8.name(); private static final String WRITTEN_STATISTICS_NAME = "written"; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemReader.java index 9da16b274..4bc56d341 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2020 the original author or authors. + * Copyright 2006-2022 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 @@ package org.springframework.batch.item.xml; import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.NoSuchElementException; @@ -64,7 +65,7 @@ ResourceAwareItemReaderItemStream, InitializingBean { private static final Log logger = LogFactory.getLog(StaxEventItemReader.class); - public static final String DEFAULT_ENCODING = Charset.defaultCharset().name(); + public static final String DEFAULT_ENCODING = StandardCharsets.UTF_8.name(); private FragmentEventReader fragmentReader;