Change default encoding to UTF-8 in file-based readers and writers

This commit overrides the fix in #3910 by using UTF-8
as default encoding in file-based item readers and writers.

Issue #1154
This commit is contained in:
Mahmoud Ben Hassine
2022-05-17 20:06:21 +02:00
parent 12c5cb967d
commit df8dac19df
4 changed files with 9 additions and 8 deletions

View File

@@ -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<T> 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[] { "#" };

View File

@@ -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<T> 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";

View File

@@ -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<T>, 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;