Apache Solr open-source search software
LUCENE-5560: Cleanup charset handling for Java 7
Uwe Schindler2f8192f3c5a8
diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/br/BrazilianAnalyzer.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/br/BrazilianAnalyzer.javaindex 81d13389369..cddd3920c24 100644--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/br/BrazilianAnalyzer.java+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/br/BrazilianAnalyzer.java@@ -19,6 +19,7 @@ package org.apache.lucene.analysis.br;import java.io.IOException;import java.io.Reader;+import java.nio.charset.StandardCharsets;import org.apache.lucene.analysis.Analyzer;import org.apache.lucene.analysis.TokenStream;@@ -64,7 +65,7 @@ public final class BrazilianAnalyzer extends StopwordAnalyzerBase {static {try {DEFAULT_STOP_SET = WordlistLoader.getWordSet(IOUtils.getDecodingReader(BrazilianAnalyzer.class,- DEFAULT_STOPWORD_FILE, IOUtils.CHARSET_UTF_8), "#", Version.LUCENE_CURRENT);+ DEFAULT_STOPWORD_FILE, StandardCharsets.UTF_8), "#", Version.LUCENE_CURRENT);} catch (IOException ex) {// default set should always be present as it is part of the// distribution (JAR)diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/ckb/SoraniAnalyzer.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/ckb/SoraniAnalyzer.javaindex e67136be594..8a89ae5a978 100644--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/ckb/SoraniAnalyzer.java+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/ckb/SoraniAnalyzer.java@@ -19,6 +19,7 @@ package org.apache.lucene.analysis.ckb;import java.io.IOException;import java.io.Reader;+import java.nio.charset.StandardCharsets;import org.apache.lucene.analysis.Analyzer;import org.apache.lucene.analysis.core.LowerCaseFilter;@@ -61,7 +62,7 @@ public final class SoraniAnalyzer extends StopwordAnalyzerBase {static {try {DEFAULT_STOP_SET = WordlistLoader.getWordSet(IOUtils.getDecodingReader(SoraniAnalyzer.class,- DEFAULT_STOPWORD_FILE, IOUtils.CHARSET_UTF_8), Version.LUCENE_CURRENT);+ DEFAULT_STOPWORD_FILE, StandardCharsets.UTF_8), Version.LUCENE_CURRENT);} catch (IOException ex) {// default set should always be present as it is part of the// distribution (JAR)diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/cz/CzechAnalyzer.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/cz/CzechAnalyzer.javaindex 6530f34de70..b54739be60e 100644--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/cz/CzechAnalyzer.java+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/cz/CzechAnalyzer.java@@ -32,6 +32,7 @@ import org.apache.lucene.util.IOUtils;import org.apache.lucene.util.Version;import java.io.*;+import java.nio.charset.StandardCharsets;/*** {@link Analyzer} for Czech language.@@ -60,7 +61,7 @@ public final class CzechAnalyzer extends StopwordAnalyzerBase {static {try {DEFAULT_SET = WordlistLoader.getWordSet(IOUtils.getDecodingReader(CzechAnalyzer.class,- DEFAULT_STOPWORD_FILE, IOUtils.CHARSET_UTF_8), "#", Version.LUCENE_CURRENT);+ DEFAULT_STOPWORD_FILE, StandardCharsets.UTF_8), "#", Version.LUCENE_CURRENT);} catch (IOException ex) {// default set should always be present as it is part of the// distribution (JAR)diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/da/DanishAnalyzer.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/da/DanishAnalyzer.javaindex 4da371222cc..00f7520af9f 100644--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/da/DanishAnalyzer.java+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/da/DanishAnalyzer.java@@ -19,6 +19,7 @@ package org.apache.lucene.analysis.da;import java.io.IOException;import java.io.Reader;+import java.nio.charset.StandardCharsets;import org.apache.lucene.analysis.Analyzer;import org.apache.lucene.analysis.core.LowerCaseFilter;@@ -63,7 +64,7 @@ public final class DanishAnalyzer extends StopwordAnalyzerBase {static {try {DEFAULT_STOP_SET = WordlistLoader.getSnowballWordSet(IOUtils.getDecodingReader(SnowballFilter.class,- DEFAULT_STOPWORD_FILE, IOUtils.CHARSET_UTF_8), Version.LUCENE_CURRENT);+ DEFAULT_STOPWORD_FILE, StandardCharsets.UTF_8), Version.LUCENE_CURRENT);} catch (IOException ex) {// default set should always be present as it is part of the// distribution (JAR)diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/de/GermanAnalyzer.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/de/GermanAnalyzer.javaindex 11b9064a752..6cab61ea1f4 100644--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/de/GermanAnalyzer.java+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/de/GermanAnalyzer.java@@ -20,6 +20,7 @@ package org.apache.lucene.analysis.de;import java.io.IOException;import java.io.Reader;+import java.nio.charset.StandardCharsets;import org.apache.lucene.analysis.Analyzer;import org.apache.lucene.analysis.core.LowerCaseFilter;@@ -68,7 +69,7 @@ public final class GermanAnalyzer extends StopwordAnalyzerBase {static {try {DEFAULT_SET = WordlistLoader.getSnowballWordSet(IOUtils.getDecodingReader(SnowballFilter.class,- DEFAULT_STOPWORD_FILE, IOUtils.CHARSET_UTF_8), Version.LUCENE_CURRENT);+ DEFAULT_STOPWORD_FILE, StandardCharsets.UTF_8), Version.LUCENE_CURRENT);} catch (IOException ex) {// default set should always be present as it is part of the// distribution (JAR)diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/es/SpanishAnalyzer.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/es/SpanishAnalyzer.javaindex ea423c6807d..2ce1965af61 100644--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/es/SpanishAnalyzer.java+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/es/SpanishAnalyzer.java@@ -19,6 +19,7 @@ package org.apache.lucene.analysis.es;import java.io.IOException;import java.io.Reader;+import java.nio.charset.StandardCharsets;import org.apache.lucene.analysis.Analyzer;import org.apache.lucene.analysis.core.LowerCaseFilter;@@ -62,7 +63,7 @@ public final class SpanishAnalyzer extends StopwordAnalyzerBase {static {try {DEFAULT_STOP_SET = WordlistLoader.getSnowballWordSet(IOUtils.getDecodingReader(SnowballFilter.class,- DEFAULT_STOPWORD_FILE, IOUtils.CHARSET_UTF_8), Version.LUCENE_CURRENT);+ DEFAULT_STOPWORD_FILE, StandardCharsets.UTF_8), Version.LUCENE_CURRENT);} catch (IOException ex) {// default set should always be present as it is part of the// distribution (JAR)diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/fi/FinnishAnalyzer.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/fi/FinnishAnalyzer.javaindex 66d69374ba9..5f824429772 100644--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/fi/FinnishAnalyzer.java+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/fi/FinnishAnalyzer.java@@ -19,6 +19,7 @@ package org.apache.lucene.analysis.fi;import java.io.IOException;import java.io.Reader;+import java.nio.charset.StandardCharsets;import org.apache.lucene.analysis.Analyzer;import org.apache.lucene.analysis.core.LowerCaseFilter;@@ -63,7 +64,7 @@ public final class FinnishAnalyzer extends StopwordAnalyzerBase {static {try {DEFAULT_STOP_SET = WordlistLoader.getSnowballWordSet(IOUtils.getDecodingReader(SnowballFilter.class,- DEFAULT_STOPWORD_FILE, IOUtils.CHARSET_UTF_8), Version.LUCENE_CURRENT);+ DEFAULT_STOPWORD_FILE, StandardCharsets.UTF_8), Version.LUCENE_CURRENT);} catch (IOException ex) {// default set should always be present as it is part of the// distribution (JAR)diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/fr/FrenchAnalyzer.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/fr/FrenchAnalyzer.javaindex 0605b0ceac0..b86fb80cb86 100644--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/fr/FrenchAnalyzer.java+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/fr/FrenchAnalyzer.java@@ -36,6 +36,7 @@ import org.apache.lucene.util.Version;import java.io.IOException;import java.io.Reader;+import java.nio.charset.StandardCharsets;import java.util.Arrays;/**@@ -79,7 +80,7 @@ public final class FrenchAnalyzer extends StopwordAnalyzerBase {static {try {DEFAULT_STOP_SET = WordlistLoader.getSnowballWordSet(IOUtils.getDecodingReader(SnowballFilter.class,- DEFAULT_STOPWORD_FILE, IOUtils.CHARSET_UTF_8), Version.LUCENE_CURRENT);+ DEFAULT_STOPWORD_FILE, StandardCharsets.UTF_8), Version.LUCENE_CURRENT);} catch (IOException ex) {// default set should always be present as it is part of the// distribution (JAR)diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/gl/GalicianAnalyzer.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/gl/GalicianAnalyzer.javaindex f5e4cc402d1..a40276ff6de 100644--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/gl/GalicianAnalyzer.java+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/gl/GalicianAnalyzer.java@@ -19,6 +19,7 @@ package org.apache.lucene.analysis.gl;import java.io.IOException;import java.io.Reader;+import java.nio.charset.StandardCharsets;import org.apache.lucene.analysis.Analyzer;import org.apache.lucene.analysis.core.LowerCaseFilter;@@ -61,7 +62,7 @@ public final class GalicianAnalyzer extends StopwordAnalyzerBase {static {try {DEFAULT_STOP_SET = WordlistLoader.getWordSet(IOUtils.getDecodingReader(GalicianAnalyzer.class,- DEFAULT_STOPWORD_FILE, IOUtils.CHARSET_UTF_8), Version.LUCENE_CURRENT);+ DEFAULT_STOPWORD_FILE, StandardCharsets.UTF_8), Version.LUCENE_CURRENT);} catch (IOException ex) {// default set should always be present as it is part of the// distribution (JAR)diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hu/HungarianAnalyzer.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hu/HungarianAnalyzer.javaindex 327f37fc9de..d2addb81747 100644--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hu/HungarianAnalyzer.java+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hu/HungarianAnalyzer.java@@ -19,6 +19,7 @@ package org.apache.lucene.analysis.hu;import java.io.IOException;import java.io.Reader;+import java.nio.charset.StandardCharsets;import org.apache.lucene.analysis.Analyzer;import org.apache.lucene.analysis.core.LowerCaseFilter;@@ -63,7 +64,7 @@ public final class HungarianAnalyzer extends StopwordAnalyzerBase {static {try {DEFAULT_STOP_SET = WordlistLoader.getSnowballWordSet(IOUtils.getDecodingReader(SnowballFilter.class,- DEFAULT_STOPWORD_FILE, IOUtils.CHARSET_UTF_8), Version.LUCENE_CURRENT);+ DEFAULT_STOPWORD_FILE, StandardCharsets.UTF_8), Version.LUCENE_CURRENT);} catch (IOException ex) {// default set should always be present as it is part of the// distribution (JAR)diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Dictionary.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Dictionary.javaindex 01af90f3c4d..bcf3be55303 100644--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Dictionary.java+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Dictionary.java@@ -50,6 +50,7 @@ import java.io.OutputStream;import java.nio.charset.Charset;import java.nio.charset.CharsetDecoder;import java.nio.charset.CodingErrorAction;+import java.nio.charset.StandardCharsets;import java.text.ParseException;import java.util.ArrayList;import java.util.Arrays;@@ -672,7 +673,7 @@ public class Dictionary {int flagSep = line.lastIndexOf(FLAG_SEPARATOR);if (flagSep == -1) {CharSequence cleansed = cleanInput(line, sb);- writer.write(cleansed.toString().getBytes(IOUtils.CHARSET_UTF_8));+ writer.write(cleansed.toString().getBytes(StandardCharsets.UTF_8));} else {String text = line.substring(0, flagSep);CharSequence cleansed = cleanInput(text, sb);@@ -681,10 +682,10 @@ public class Dictionary {sb.append(cleansed);}sb.append(line.substring(flagSep));- writer.write(sb.toString().getBytes(IOUtils.CHARSET_UTF_8));+ writer.write(sb.toString().getBytes(StandardCharsets.UTF_8));}} else {- writer.write(line.getBytes(IOUtils.CHARSET_UTF_8));+ writer.write(line.getBytes(StandardCharsets.UTF_8));}}}diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/ISO8859_14Decoder.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/ISO8859_14Decoder.javaindex 2d87947ab3d..e1f6e00f722 100644--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/ISO8859_14Decoder.java+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/ISO8859_14Decoder.java@@ -21,8 +21,7 @@ import java.nio.ByteBuffer;import java.nio.CharBuffer;import java.nio.charset.CharsetDecoder;import java.nio.charset.CoderResult;--import org.apache.lucene.util.IOUtils;+import java.nio.charset.StandardCharsets;// many hunspell dictionaries use this encoding, yet java does not have it?!?!final class ISO8859_14Decoder extends CharsetDecoder {@@ -43,7 +42,7 @@ final class ISO8859_14Decoder extends CharsetDecoder {};ISO8859_14Decoder() {- super(IOUtils.CHARSET_UTF_8, 1f, 1f);+ super(StandardCharsets.ISO_8859_1 /* fake with similar properties */, 1f, 1f);}@Overridediff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/it/ItalianAnalyzer.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/it/ItalianAnalyzer.javaindex a4651e6bb2f..382bfaef9c8 100644--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/it/ItalianAnalyzer.java+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/it/ItalianAnalyzer.java@@ -19,13 +19,13 @@ package org.apache.lucene.analysis.it;import java.io.IOException;import java.io.Reader;+import java.nio.charset.StandardCharsets;import java.util.Arrays;import org.apache.lucene.analysis.Analyzer;import org.apache.lucene.analysis.core.LowerCaseFilter;import org.apache.lucene.analysis.core.StopFilter;import org.apache.lucene.analysis.miscellaneous.SetKeywordMarkerFilter;-import org.apache.lucene.analysis.miscellaneous.SetKeywordMarkerFilter;import org.apache.lucene.analysis.TokenStream;import org.apache.lucene.analysis.Tokenizer;import org.apache.lucene.analysis.snowball.SnowballFilter;@@ -72,7 +72,7 @@ public final class ItalianAnalyzer extends StopwordAnalyzerBase {static {try {DEFAULT_STOP_SET = WordlistLoader.getSnowballWordSet(IOUtils.getDecodingReader(SnowballFilter.class,- DEFAULT_STOPWORD_FILE, IOUtils.CHARSET_UTF_8), Version.LUCENE_CURRENT);+ DEFAULT_STOPWORD_FILE, StandardCharsets.UTF_8), Version.LUCENE_CURRENT);} catch (IOException ex) {// default set should always be present as it is part of the// distribution (JAR)diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/lv/LatvianAnalyzer.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/lv/LatvianAnalyzer.javaindex 58d1d360401..c6b80ed756b 100644--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/lv/LatvianAnalyzer.java+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/lv/LatvianAnalyzer.java@@ -19,6 +19,7 @@ package org.apache.lucene.analysis.lv;import java.io.IOException;import java.io.Reader;+import java.nio.charset.StandardCharsets;import org.apache.lucene.analysis.Analyzer;import org.apache.lucene.analysis.core.LowerCaseFilter;@@ -61,7 +62,7 @@ public final class LatvianAnalyzer extends StopwordAnalyzerBase {static {try {DEFAULT_STOP_SET = WordlistLoader.getWordSet(IOUtils.getDecodingReader(LatvianAnalyzer.class,- DEFAULT_STOPWORD_FILE, IOUtils.CHARSET_UTF_8), Version.LUCENE_CURRENT);+ DEFAULT_STOPWORD_FILE, StandardCharsets.UTF_8), Version.LUCENE_CURRENT);} catch (IOException ex) {// default set should always be present as it is part of the// distribution (JAR)diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/nl/DutchAnalyzer.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/nl/DutchAnalyzer.javaindex 3904919139d..1f29184429d 100644--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/nl/DutchAnalyzer.java+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/nl/DutchAnalyzer.java@@ -31,16 +31,14 @@ import org.apache.lucene.analysis.standard.StandardTokenizer;import org.apache.lucene.analysis.standard.StandardAnalyzer; // for javadocimport org.apache.lucene.analysis.util.CharArrayMap;import org.apache.lucene.analysis.util.CharArraySet;-import org.apache.lucene.analysis.util.CharacterUtils;import org.apache.lucene.analysis.util.WordlistLoader;-import org.apache.lucene.util.BytesRef;import org.apache.lucene.util.CharsRef;import org.apache.lucene.util.IOUtils;import org.apache.lucene.util.Version;-import org.apache.lucene.util.fst.FST;import java.io.IOException;import java.io.Reader;+import java.nio.charset.StandardCharsets;/*** {@link Analyzer} for Dutch language.@@ -75,7 +73,7 @@ public final class DutchAnalyzer extends Analyzer {static {try {DEFAULT_STOP_SET = WordlistLoader.getSnowballWordSet(IOUtils.getDecodingReader(SnowballFilter.class,- DEFAULT_STOPWORD_FILE, IOUtils.CHARSET_UTF_8), Version.LUCENE_CURRENT);+ DEFAULT_STOPWORD_FILE, StandardCharsets.UTF_8), Version.LUCENE_CURRENT);} catch (IOException ex) {// default set should always be present as it is part of the// distribution (JAR)diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/no/NorwegianAnalyzer.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/no/NorwegianAnalyzer.javaindex 968c5393b8a..ffe519947d0 100644--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/no/NorwegianAnalyzer.java+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/no/NorwegianAnalyzer.java@@ -19,6 +19,7 @@ package org.apache.lucene.analysis.no;import java.io.IOException;import java.io.Reader;+import java.nio.charset.StandardCharsets;import org.apache.lucene.analysis.Analyzer;import org.apache.lucene.analysis.core.LowerCaseFilter;@@ -63,7 +64,7 @@ public final class NorwegianAnalyzer extends StopwordAnalyzerBase {static {try {DEFAULT_STOP_SET = WordlistLoader.getSnowballWordSet(IOUtils.getDecodingReader(SnowballFilter.class,- DEFAULT_STOPWORD_FILE, IOUtils.CHARSET_UTF_8), Version.LUCENE_CURRENT);+ DEFAULT_STOPWORD_FILE, StandardCharsets.UTF_8), Version.LUCENE_CURRENT);} catch (IOException ex) {// default set should always be present as it is part of the// distribution (JAR)diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/payloads/IdentityEncoder.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/payloads/IdentityEncoder.javaindex cc5939cfd8e..721ecbffd0a 100644--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/payloads/IdentityEncoder.java+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/payloads/IdentityEncoder.java@@ -19,6 +19,7 @@ package org.apache.lucene.analysis.payloads;import java.nio.ByteBuffer;import java.nio.CharBuffer;import java.nio.charset.Charset;+import java.nio.charset.StandardCharsets;import org.apache.lucene.util.BytesRef;@@ -28,7 +29,7 @@ import org.apache.lucene.util.BytesRef;***/public class IdentityEncoder extends AbstractEncoder implements PayloadEncoder{- protected Charset charset = Charset.forName("UTF-8");+ protected Charset charset = StandardCharsets.UTF_8;public IdentityEncoder() {}diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/payloads/TypeAsPayloadTokenFilter.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/payloads/TypeAsPayloadTokenFilter.javaindex b21535aeb7d..e513f600906 100644--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/payloads/TypeAsPayloadTokenFilter.java+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/payloads/TypeAsPayloadTokenFilter.java@@ -45,8 +45,8 @@ public class TypeAsPayloadTokenFilter extends TokenFilter {public final boolean incrementToken() throws IOException {if (input.incrementToken()) {String type = typeAtt.type();- if (type != null && type.equals("") == false) {- payloadAtt.setPayload(new BytesRef(type.getBytes("UTF-8")));+ if (type != null && !type.isEmpty()) {+ payloadAtt.setPayload(new BytesRef(type));}return true;} else {diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/pt/PortugueseAnalyzer.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/pt/PortugueseAnalyzer.javaindex 960ec53c3a0..3bceb5c6ab3 100644--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/pt/PortugueseAnalyzer.java+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/pt/PortugueseAnalyzer.java@@ -19,6 +19,7 @@ package org.apache.lucene.analysis.pt;import java.io.IOException;import java.io.Reader;+import java.nio.charset.StandardCharsets;import org.apache.lucene.analysis.Analyzer;import org.apache.lucene.analysis.core.LowerCaseFilter;@@ -62,7 +63,7 @@ public final class PortugueseAnalyzer extends StopwordAnalyzerBase {static {try {DEFAULT_STOP_SET = WordlistLoader.getSnowballWordSet(IOUtils.getDecodingReader(SnowballFilter.class,- DEFAULT_STOPWORD_FILE, IOUtils.CHARSET_UTF_8), Version.LUCENE_CURRENT);+ DEFAULT_STOPWORD_FILE, StandardCharsets.UTF_8), Version.LUCENE_CURRENT);} catch (IOException ex) {// default set should always be present as it is part of the// distribution (JAR)diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/pt/RSLPStemmerBase.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/pt/RSLPStemmerBase.javaindex f8da03451c3..f8ad153cfb4 100644--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/pt/RSLPStemmerBase.java+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/pt/RSLPStemmerBase.java@@ -21,6 +21,7 @@ import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.LineNumberReader;+import java.nio.charset.StandardCharsets;import java.util.ArrayList;import java.util.Arrays;import java.util.HashMap;@@ -247,7 +248,7 @@ public abstract class RSLPStemmerBase {// TODO: this parser is ugly, but works. use a jflex grammar instead.try {InputStream is = clazz.getResourceAsStream(resource);- LineNumberReader r = new LineNumberReader(new InputStreamReader(is, "UTF-8"));+ LineNumberReader r = new LineNumberReader(new InputStreamReader(is, StandardCharsets.UTF_8));Map<String,Step> steps = new HashMap<>();String step;while ((step = readLine(r)) != null) {diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/ru/RussianAnalyzer.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/ru/RussianAnalyzer.javaindex 156dcb92b7b..69ab96fa679 100644--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/ru/RussianAnalyzer.java+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/ru/RussianAnalyzer.java@@ -19,6 +19,7 @@ package org.apache.lucene.analysis.ru;import java.io.IOException;import java.io.Reader;+import java.nio.charset.StandardCharsets;import org.apache.lucene.analysis.Analyzer;import org.apache.lucene.analysis.snowball.SnowballFilter;@@ -53,7 +54,7 @@ public final class RussianAnalyzer extends StopwordAnalyzerBase {static {try {DEFAULT_STOP_SET = WordlistLoader.getSnowballWordSet(IOUtils.getDecodingReader(SnowballFilter.class,- DEFAULT_STOPWORD_FILE, IOUtils.CHARSET_UTF_8), Version.LUCENE_CURRENT);+ DEFAULT_STOPWORD_FILE, StandardCharsets.UTF_8), Version.LUCENE_CURRENT);} catch (IOException ex) {// default set should always be present as it is part of the// distribution (JAR)diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/sv/SwedishAnalyzer.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/sv/SwedishAnalyzer.javaindex c4e24127806..a8878ea2139 100644--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/sv/SwedishAnalyzer.java+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/sv/SwedishAnalyzer.java@@ -19,6 +19,7 @@ package org.apache.lucene.analysis.sv;import java.io.IOException;import java.io.Reader;+import java.nio.charset.StandardCharsets;import org.apache.lucene.analysis.Analyzer;import org.apache.lucene.analysis.core.LowerCaseFilter;@@ -63,7 +64,7 @@ public final class SwedishAnalyzer extends StopwordAnalyzerBase {static {try {DEFAULT_STOP_SET = WordlistLoader.getSnowballWordSet(IOUtils.getDecodingReader(SnowballFilter.class,- DEFAULT_STOPWORD_FILE, IOUtils.CHARSET_UTF_8), Version.LUCENE_CURRENT);+ DEFAULT_STOPWORD_FILE, StandardCharsets.UTF_8), Version.LUCENE_CURRENT);} catch (IOException ex) {// default set should always be present as it is part of the// distribution (JAR)diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/synonym/SynonymFilterFactory.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/synonym/SynonymFilterFactory.javaindex c06b247815c..8df01e58fd1 100644--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/synonym/SynonymFilterFactory.java+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/synonym/SynonymFilterFactory.java@@ -24,6 +24,7 @@ import java.io.Reader;import java.nio.charset.Charset;import java.nio.charset.CharsetDecoder;import java.nio.charset.CodingErrorAction;+import java.nio.charset.StandardCharsets;import java.text.ParseException;import java.util.HashMap;import java.util.Iterator;@@ -158,7 +159,7 @@ public class SynonymFilterFactory extends TokenFilterFactory implements Resource* Load synonyms with the given {@link SynonymMap.Parser} class.*/private SynonymMap loadSynonyms(ResourceLoader loader, String cname, boolean dedup, Analyzer analyzer) throws IOException, ParseException {- CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder()+ CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder().onMalformedInput(CodingErrorAction.REPORT).onUnmappableCharacter(CodingErrorAction.REPORT);diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/AbstractAnalysisFactory.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/AbstractAnalysisFactory.javaindex 4ad1473ed84..5234440d0ac 100644--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/AbstractAnalysisFactory.java+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/AbstractAnalysisFactory.java@@ -27,6 +27,7 @@ import java.io.InputStreamReader;import java.io.Reader;import java.nio.charset.CharsetDecoder;import java.nio.charset.CodingErrorAction;+import java.nio.charset.StandardCharsets;import java.util.ArrayList;import java.util.Collection;import java.util.Collections;@@ -252,7 +253,7 @@ public abstract class AbstractAnalysisFactory {* Returns the resource's lines (with content treated as UTF-8)*/protected final List<String> getLines(ResourceLoader loader, String resource) throws IOException {- return WordlistLoader.getLines(loader.openResource(resource), IOUtils.CHARSET_UTF_8);+ return WordlistLoader.getLines(loader.openResource(resource), StandardCharsets.UTF_8);}/** same as {@link #getWordSet(ResourceLoader, String, boolean)},@@ -272,7 +273,7 @@ public abstract class AbstractAnalysisFactory {Reader reader = null;try {stream = loader.openResource(file.trim());- CharsetDecoder decoder = IOUtils.CHARSET_UTF_8.newDecoder()+ CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder().onMalformedInput(CodingErrorAction.REPORT).onUnmappableCharacter(CodingErrorAction.REPORT);reader = new InputStreamReader(stream, decoder);diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/StopwordAnalyzerBase.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/StopwordAnalyzerBase.javaindex 9d8890e2ea0..b98c33588c5 100644--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/StopwordAnalyzerBase.java+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/StopwordAnalyzerBase.java@@ -20,6 +20,7 @@ package org.apache.lucene.analysis.util;import java.io.File;import java.io.IOException;import java.io.Reader;+import java.nio.charset.StandardCharsets;import org.apache.lucene.analysis.Analyzer;import org.apache.lucene.util.IOUtils;@@ -97,7 +98,7 @@ public abstract class StopwordAnalyzerBase extends Analyzer {final String comment) throws IOException {Reader reader = null;try {- reader = IOUtils.getDecodingReader(aClass.getResourceAsStream(resource), IOUtils.CHARSET_UTF_8);+ reader = IOUtils.getDecodingReader(aClass.getResourceAsStream(resource), StandardCharsets.UTF_8);return WordlistLoader.getWordSet(reader, comment, new CharArraySet(Version.LUCENE_CURRENT, 16, ignoreCase));} finally {IOUtils.close(reader);@@ -122,7 +123,7 @@ public abstract class StopwordAnalyzerBase extends Analyzer {Version matchVersion) throws IOException {Reader reader = null;try {- reader = IOUtils.getDecodingReader(stopwords, IOUtils.CHARSET_UTF_8);+ reader = IOUtils.getDecodingReader(stopwords, StandardCharsets.UTF_8);return WordlistLoader.getWordSet(reader, matchVersion);} finally {IOUtils.close(reader);diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/charfilter/HTMLStripCharFilterTest.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/charfilter/HTMLStripCharFilterTest.javaindex 85e4d69119f..93cfd5e2194 100644--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/charfilter/HTMLStripCharFilterTest.java+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/charfilter/HTMLStripCharFilterTest.java@@ -23,6 +23,7 @@ import java.io.InputStream;import java.io.InputStreamReader;import java.io.Reader;import java.io.StringReader;+import java.nio.charset.StandardCharsets;import java.util.Arrays;import java.util.HashSet;import java.util.Set;@@ -78,7 +79,7 @@ public class HTMLStripCharFilterTest extends BaseTokenStreamTestCase {//Some sanity checks, but not a full-fledged checkpublic void testHTML() throws Exception {InputStream stream = getClass().getResourceAsStream("htmlStripReaderTest.html");- HTMLStripCharFilter reader = new HTMLStripCharFilter(new InputStreamReader(stream, "UTF-8"));+ HTMLStripCharFilter reader = new HTMLStripCharFilter(new InputStreamReader(stream, StandardCharsets.UTF_8));StringBuilder builder = new StringBuilder();int ch = -1;while ((ch = reader.read()) != -1){@@ -95,7 +96,7 @@ public class HTMLStripCharFilterTest extends BaseTokenStreamTestCase {public void testMSWord14GeneratedHTML() throws Exception {InputStream stream = getClass().getResourceAsStream("MS-Word 14 generated.htm");- HTMLStripCharFilter reader = new HTMLStripCharFilter(new InputStreamReader(stream, "UTF-8"));+ HTMLStripCharFilter reader = new HTMLStripCharFilter(new InputStreamReader(stream, StandardCharsets.UTF_8));String gold = "This is a test";StringBuilder builder = new StringBuilder();int ch = 0;diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestUAX29URLEmailTokenizer.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestUAX29URLEmailTokenizer.javaindex b433d308f83..1d924e8ff87 100644--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestUAX29URLEmailTokenizer.java+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestUAX29URLEmailTokenizer.java@@ -15,6 +15,7 @@ import java.io.IOException;import java.io.InputStreamReader;import java.io.Reader;import java.io.StringReader;+import java.nio.charset.StandardCharsets;import java.util.ArrayList;import java.util.Arrays;import java.util.List;@@ -269,7 +270,7 @@ public class TestUAX29URLEmailTokenizer extends BaseTokenStreamTestCase {String luceneResourcesWikiPage;try {reader = new InputStreamReader(getClass().getResourceAsStream- ("LuceneResourcesWikiPage.html"), "UTF-8");+ ("LuceneResourcesWikiPage.html"), StandardCharsets.UTF_8);StringBuilder builder = new StringBuilder();char[] buffer = new char[1024];int numCharsRead;@@ -289,7 +290,7 @@ public class TestUAX29URLEmailTokenizer extends BaseTokenStreamTestCase {try {List<String> urlList = new ArrayList<>();bufferedReader = new BufferedReader(new InputStreamReader- (getClass().getResourceAsStream("LuceneResourcesWikiPageURLs.txt"), "UTF-8"));+ (getClass().getResourceAsStream("LuceneResourcesWikiPageURLs.txt"), StandardCharsets.UTF_8));String line;while (null != (line = bufferedReader.readLine())) {line = line.trim();@@ -313,7 +314,7 @@ public class TestUAX29URLEmailTokenizer extends BaseTokenStreamTestCase {String randomTextWithEmails;try {reader = new InputStreamReader(getClass().getResourceAsStream- ("random.text.with.email.addresses.txt"), "UTF-8");+ ("random.text.with.email.addresses.txt"), StandardCharsets.UTF_8);StringBuilder builder = new StringBuilder();char[] buffer = new char[1024];int numCharsRead;@@ -334,7 +335,7 @@ public class TestUAX29URLEmailTokenizer extends BaseTokenStreamTestCase {List<String> emailList = new ArrayList<>();bufferedReader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream- ("email.addresses.from.random.text.with.email.addresses.txt"), "UTF-8"));+ ("email.addresses.from.random.text.with.email.addresses.txt"), StandardCharsets.UTF_8));String line;while (null != (line = bufferedReader.readLine())) {line = line.trim();@@ -383,7 +384,7 @@ public class TestUAX29URLEmailTokenizer extends BaseTokenStreamTestCase {String randomTextWithURLs;try {reader = new InputStreamReader(getClass().getResourceAsStream- ("random.text.with.urls.txt"), "UTF-8");+ ("random.text.with.urls.txt"), StandardCharsets.UTF_8);StringBuilder builder = new StringBuilder();char[] buffer = new char[1024];int numCharsRead;@@ -404,7 +405,7 @@ public class TestUAX29URLEmailTokenizer extends BaseTokenStreamTestCase {List<String> urlList = new ArrayList<>();bufferedReader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream- ("urls.from.random.text.with.urls.txt"), "UTF-8"));+ ("urls.from.random.text.with.urls.txt"), StandardCharsets.UTF_8));String line;while (null != (line = bufferedReader.readLine())) {line = line.trim();diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestAllDictionaries.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestAllDictionaries.javaindex 578b0d22278..44db27424ca 100644--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestAllDictionaries.java+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestAllDictionaries.java@@ -19,6 +19,7 @@ package org.apache.lucene.analysis.hunspell;import java.io.File;import java.io.InputStream;+import java.nio.charset.StandardCharsets;import java.util.zip.ZipEntry;import java.util.zip.ZipFile;@@ -157,7 +158,7 @@ public class TestAllDictionaries extends LuceneTestCase {File f = new File(DICTIONARY_HOME, tests[i]);assert f.exists();- try (ZipFile zip = new ZipFile(f, IOUtils.CHARSET_UTF_8)) {+ try (ZipFile zip = new ZipFile(f, StandardCharsets.UTF_8)) {ZipEntry dicEntry = zip.getEntry(tests[i+1]);assert dicEntry != null;ZipEntry affEntry = zip.getEntry(tests[i+2]);@@ -186,7 +187,7 @@ public class TestAllDictionaries extends LuceneTestCase {File f = new File(DICTIONARY_HOME, tests[i]);assert f.exists();- try (ZipFile zip = new ZipFile(f, IOUtils.CHARSET_UTF_8)) {+ try (ZipFile zip = new ZipFile(f, StandardCharsets.UTF_8)) {ZipEntry dicEntry = zip.getEntry(tests[i+1]);assert dicEntry != null;ZipEntry affEntry = zip.getEntry(tests[i+2]);diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestAllDictionaries2.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestAllDictionaries2.javaindex 7a855f14777..68e9d4f0c04 100644--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestAllDictionaries2.java+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestAllDictionaries2.java@@ -19,6 +19,7 @@ package org.apache.lucene.analysis.hunspell;import java.io.File;import java.io.InputStream;+import java.nio.charset.StandardCharsets;import java.util.zip.ZipEntry;import java.util.zip.ZipFile;@@ -173,7 +174,7 @@ public class TestAllDictionaries2 extends LuceneTestCase {File f = new File(DICTIONARY_HOME, tests[i]);assert f.exists();- try (ZipFile zip = new ZipFile(f, IOUtils.CHARSET_UTF_8)) {+ try (ZipFile zip = new ZipFile(f, StandardCharsets.UTF_8)) {ZipEntry dicEntry = zip.getEntry(tests[i+1]);assert dicEntry != null;ZipEntry affEntry = zip.getEntry(tests[i+2]);@@ -202,7 +203,7 @@ public class TestAllDictionaries2 extends LuceneTestCase {File f = new File(DICTIONARY_HOME, tests[i]);assert f.exists();- try (ZipFile zip = new ZipFile(f, IOUtils.CHARSET_UTF_8)) {+ try (ZipFile zip = new ZipFile(f, StandardCharsets.UTF_8)) {ZipEntry dicEntry = zip.getEntry(tests[i+1]);assert dicEntry != null;ZipEntry affEntry = zip.getEntry(tests[i+2]);diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestDictionary.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestDictionary.javaindex 030181e89da..63ac534e8f0 100644--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestDictionary.java+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestDictionary.java@@ -21,6 +21,7 @@ import java.io.ByteArrayInputStream;import java.io.FilterInputStream;import java.io.IOException;import java.io.InputStream;+import java.nio.charset.StandardCharsets;import java.text.ParseException;import org.apache.lucene.util.BytesRef;@@ -232,10 +233,10 @@ public class TestDictionary extends LuceneTestCase {}public void testSetWithCrazyWhitespaceAndBOMs() throws Exception {- assertEquals("UTF-8", Dictionary.getDictionaryEncoding(new ByteArrayInputStream("SET\tUTF-8\n".getBytes(IOUtils.CHARSET_UTF_8))));- assertEquals("UTF-8", Dictionary.getDictionaryEncoding(new ByteArrayInputStream("SET\t UTF-8\n".getBytes(IOUtils.CHARSET_UTF_8))));- assertEquals("UTF-8", Dictionary.getDictionaryEncoding(new ByteArrayInputStream("\uFEFFSET\tUTF-8\n".getBytes(IOUtils.CHARSET_UTF_8))));- assertEquals("UTF-8", Dictionary.getDictionaryEncoding(new ByteArrayInputStream("\uFEFFSET\tUTF-8\r\n".getBytes(IOUtils.CHARSET_UTF_8))));+ assertEquals("UTF-8", Dictionary.getDictionaryEncoding(new ByteArrayInputStream("SET\tUTF-8\n".getBytes(StandardCharsets.UTF_8))));+ assertEquals("UTF-8", Dictionary.getDictionaryEncoding(new ByteArrayInputStream("SET\t UTF-8\n".getBytes(StandardCharsets.UTF_8))));+ assertEquals("UTF-8", Dictionary.getDictionaryEncoding(new ByteArrayInputStream("\uFEFFSET\tUTF-8\n".getBytes(StandardCharsets.UTF_8))));+ assertEquals("UTF-8", Dictionary.getDictionaryEncoding(new ByteArrayInputStream("\uFEFFSET\tUTF-8\r\n".getBytes(StandardCharsets.UTF_8))));}public void testFlagWithCrazyWhitespace() throws Exception {diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/payloads/DelimitedPayloadTokenFilterTest.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/payloads/DelimitedPayloadTokenFilterTest.javaindex 1f4efec3596..6dc5b3fd602 100644--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/payloads/DelimitedPayloadTokenFilterTest.java+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/payloads/DelimitedPayloadTokenFilterTest.java@@ -25,6 +25,7 @@ import org.apache.lucene.util.BytesRef;import org.apache.lucene.util.LuceneTestCase;import java.io.StringReader;+import java.nio.charset.StandardCharsets;public class DelimitedPayloadTokenFilterTest extends BaseTokenStreamTestCase {@@ -37,15 +38,15 @@ public class DelimitedPayloadTokenFilterTest extends BaseTokenStreamTestCase {PayloadAttribute payAtt = filter.getAttribute(PayloadAttribute.class);filter.reset();assertTermEquals("The", filter, termAtt, payAtt, null);- assertTermEquals("quick", filter, termAtt, payAtt, "JJ".getBytes("UTF-8"));- assertTermEquals("red", filter, termAtt, payAtt, "JJ".getBytes("UTF-8"));- assertTermEquals("fox", filter, termAtt, payAtt, "NN".getBytes("UTF-8"));- assertTermEquals("jumped", filter, termAtt, payAtt, "VB".getBytes("UTF-8"));+ assertTermEquals("quick", filter, termAtt, payAtt, "JJ".getBytes(StandardCharsets.UTF_8));+ assertTermEquals("red", filter, termAtt, payAtt, "JJ".getBytes(StandardCharsets.UTF_8));+ assertTermEquals("fox", filter, termAtt, payAtt, "NN".getBytes(StandardCharsets.UTF_8));+ assertTermEquals("jumped", filter, termAtt, payAtt, "VB".getBytes(StandardCharsets.UTF_8));assertTermEquals("over", filter, termAtt, payAtt, null);assertTermEquals("the", filter, termAtt, payAtt, null);- assertTermEquals("lazy", filter, termAtt, payAtt, "JJ".getBytes("UTF-8"));- assertTermEquals("brown", filter, termAtt, payAtt, "JJ".getBytes("UTF-8"));- assertTermEquals("dogs", filter, termAtt, payAtt, "NN".getBytes("UTF-8"));+ assertTermEquals("lazy", filter, termAtt, payAtt, "JJ".getBytes(StandardCharsets.UTF_8));+ assertTermEquals("brown", filter, termAtt, payAtt, "JJ".getBytes(StandardCharsets.UTF_8));+ assertTermEquals("dogs", filter, termAtt, payAtt, "NN".getBytes(StandardCharsets.UTF_8));assertFalse(filter.incrementToken());filter.end();filter.close();@@ -59,15 +60,15 @@ public class DelimitedPayloadTokenFilterTest extends BaseTokenStreamTestCase {DelimitedPayloadTokenFilter.DEFAULT_DELIMITER, new IdentityEncoder());filter.reset();assertTermEquals("The", filter, null);- assertTermEquals("quick", filter, "JJ".getBytes("UTF-8"));- assertTermEquals("red", filter, "JJ".getBytes("UTF-8"));- assertTermEquals("fox", filter, "NN".getBytes("UTF-8"));- assertTermEquals("jumped", filter, "VB".getBytes("UTF-8"));+ assertTermEquals("quick", filter, "JJ".getBytes(StandardCharsets.UTF_8));+ assertTermEquals("red", filter, "JJ".getBytes(StandardCharsets.UTF_8));+ assertTermEquals("fox", filter, "NN".getBytes(StandardCharsets.UTF_8));+ assertTermEquals("jumped", filter, "VB".getBytes(StandardCharsets.UTF_8));assertTermEquals("over", filter, null);assertTermEquals("the", filter, null);- assertTermEquals("lazy", filter, "JJ".getBytes("UTF-8"));- assertTermEquals("brown", filter, "JJ".getBytes("UTF-8"));- assertTermEquals("dogs", filter, "NN".getBytes("UTF-8"));+ assertTermEquals("lazy", filter, "JJ".getBytes(StandardCharsets.UTF_8));+ assertTermEquals("brown", filter, "JJ".getBytes(StandardCharsets.UTF_8));+ assertTermEquals("dogs", filter, "NN".getBytes(StandardCharsets.UTF_8));assertFalse(filter.incrementToken());filter.end();filter.close();diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/payloads/TypeAsPayloadTokenFilterTest.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/payloads/TypeAsPayloadTokenFilterTest.javaindex 9f5442f2fe6..7239d7cc6a1 100644--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/payloads/TypeAsPayloadTokenFilterTest.java+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/payloads/TypeAsPayloadTokenFilterTest.java@@ -26,6 +26,7 @@ import org.apache.lucene.analysis.tokenattributes.TypeAttribute;import java.io.IOException;import java.io.StringReader;+import java.nio.charset.StandardCharsets;public class TypeAsPayloadTokenFilterTest extends BaseTokenStreamTestCase {@@ -41,8 +42,8 @@ public class TypeAsPayloadTokenFilterTest extends BaseTokenStreamTestCase {while (nptf.incrementToken()) {assertTrue(typeAtt.type() + " is not null and it should be", typeAtt.type().equals(String.valueOf(Character.toUpperCase(termAtt.buffer()[0]))));assertTrue("nextToken.getPayload() is null and it shouldn't be", payloadAtt.getPayload() != null);- String type = new String(payloadAtt.getPayload().bytes, "UTF-8");- assertTrue(type + " is not equal to " + typeAtt.type(), type.equals(typeAtt.type()) == true);+ String type = payloadAtt.getPayload().utf8ToString();+ assertTrue(type + " is not equal to " + typeAtt.type(), type.equals(typeAtt.type()));count++;}diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/util/StringMockResourceLoader.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/util/StringMockResourceLoader.javaindex 4a3ca489d61..6a8d1b58a35 100644--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/util/StringMockResourceLoader.java+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/util/StringMockResourceLoader.java@@ -20,6 +20,7 @@ package org.apache.lucene.analysis.util;import java.io.ByteArrayInputStream;import java.io.IOException;import java.io.InputStream;+import java.nio.charset.StandardCharsets;/** Fake resource loader for tests: works if you want to fake reading a single file */public class StringMockResourceLoader implements ResourceLoader {@@ -50,6 +51,6 @@ public class StringMockResourceLoader implements ResourceLoader {@Overridepublic InputStream openResource(String resource) throws IOException {- return new ByteArrayInputStream(text.getBytes("UTF-8"));+ return new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8));}}diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/util/TestFilesystemResourceLoader.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/util/TestFilesystemResourceLoader.javaindex 977781b6f22..8bf5dd1d44e 100644--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/util/TestFilesystemResourceLoader.java+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/util/TestFilesystemResourceLoader.java@@ -23,6 +23,7 @@ import java.io.IOException;import java.io.InputStreamReader;import java.io.OutputStreamWriter;import java.io.Writer;+import java.nio.charset.StandardCharsets;import org.apache.lucene.util.IOUtils;import org.apache.lucene.util.LuceneTestCase;@@ -49,7 +50,7 @@ public class TestFilesystemResourceLoader extends LuceneTestCase {private void assertClasspathDelegation(ResourceLoader rl) throws Exception {// try a stopwords file from classpathCharArraySet set = WordlistLoader.getSnowballWordSet(- new InputStreamReader(rl.openResource("org/apache/lucene/analysis/snowball/english_stop.txt"), IOUtils.CHARSET_UTF_8),+ new InputStreamReader(rl.openResource("org/apache/lucene/analysis/snowball/english_stop.txt"), StandardCharsets.UTF_8),TEST_VERSION_CURRENT);assertTrue(set.contains("you"));@@ -64,7 +65,7 @@ public class TestFilesystemResourceLoader extends LuceneTestCase {final File base = TestUtil.getTempDir("fsResourceLoaderBase").getAbsoluteFile();try {base.mkdirs();- Writer os = new OutputStreamWriter(new FileOutputStream(new File(base, "template.txt")), IOUtils.CHARSET_UTF_8);+ Writer os = new OutputStreamWriter(new FileOutputStream(new File(base, "template.txt")), StandardCharsets.UTF_8);try {os.write("foobar\n");} finally {@@ -72,18 +73,18 @@ public class TestFilesystemResourceLoader extends LuceneTestCase {}ResourceLoader rl = new FilesystemResourceLoader(base);- assertEquals("foobar", WordlistLoader.getLines(rl.openResource("template.txt"), IOUtils.CHARSET_UTF_8).get(0));+ assertEquals("foobar", WordlistLoader.getLines(rl.openResource("template.txt"), StandardCharsets.UTF_8).get(0));// Same with full path name:String fullPath = new File(base, "template.txt").toString();assertEquals("foobar",- WordlistLoader.getLines(rl.openResource(fullPath), IOUtils.CHARSET_UTF_8).get(0));+ WordlistLoader.getLines(rl.openResource(fullPath), StandardCharsets.UTF_8).get(0));assertClasspathDelegation(rl);assertNotFound(rl);// now use RL without base dir:rl = new FilesystemResourceLoader();assertEquals("foobar",- WordlistLoader.getLines(rl.openResource(new File(base, "template.txt").toString()), IOUtils.CHARSET_UTF_8).get(0));+ WordlistLoader.getLines(rl.openResource(new File(base, "template.txt").toString()), StandardCharsets.UTF_8).get(0));assertClasspathDelegation(rl);assertNotFound(rl);} finally {@@ -93,7 +94,7 @@ public class TestFilesystemResourceLoader extends LuceneTestCase {public void testDelegation() throws Exception {ResourceLoader rl = new FilesystemResourceLoader(null, new StringMockResourceLoader("foobar\n"));- assertEquals("foobar", WordlistLoader.getLines(rl.openResource("template.txt"), IOUtils.CHARSET_UTF_8).get(0));+ assertEquals("foobar", WordlistLoader.getLines(rl.openResource("template.txt"), StandardCharsets.UTF_8).get(0));}}diff --git a/lucene/analysis/common/src/tools/java/org/apache/lucene/analysis/standard/GenerateJflexTLDMacros.java b/lucene/analysis/common/src/tools/java/org/apache/lucene/analysis/standard/GenerateJflexTLDMacros.javaindex 69b4b392f94..a96e41d77ce 100644--- a/lucene/analysis/common/src/tools/java/org/apache/lucene/analysis/standard/GenerateJflexTLDMacros.java+++ b/lucene/analysis/common/src/tools/java/org/apache/lucene/analysis/standard/GenerateJflexTLDMacros.java@@ -25,6 +25,7 @@ import java.io.OutputStreamWriter;import java.io.Writer;import java.net.URL;import java.net.URLConnection;+import java.nio.charset.StandardCharsets;import java.text.DateFormat;import java.util.Date;import java.util.Locale;@@ -118,7 +119,7 @@ public class GenerateJflexTLDMacros {connection.connect();tldFileLastModified = connection.getLastModified();BufferedReader reader = new BufferedReader- (new InputStreamReader(connection.getInputStream(), "US-ASCII"));+ (new InputStreamReader(connection.getInputStream(), StandardCharsets.US_ASCII));try {String line;while (null != (line = reader.readLine())) {@@ -150,7 +151,7 @@ public class GenerateJflexTLDMacros {(DateFormat.FULL, DateFormat.FULL, Locale.ROOT);dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));final Writer writer = new OutputStreamWriter- (new FileOutputStream(outputFile), "UTF-8");+ (new FileOutputStream(outputFile), StandardCharsets.UTF_8);try {writer.write(APACHE_LICENSE);writer.write("// Generated from IANA Root Zone Database <");diff --git a/lucene/analysis/icu/src/java/org/apache/lucene/analysis/icu/segmentation/ICUTokenizerFactory.java b/lucene/analysis/icu/src/java/org/apache/lucene/analysis/icu/segmentation/ICUTokenizerFactory.javaindex 307becc0cc9..12b5f824e18 100644--- a/lucene/analysis/icu/src/java/org/apache/lucene/analysis/icu/segmentation/ICUTokenizerFactory.java+++ b/lucene/analysis/icu/src/java/org/apache/lucene/analysis/icu/segmentation/ICUTokenizerFactory.java@@ -20,7 +20,7 @@ package org.apache.lucene.analysis.icu.segmentation;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;-import java.io.Reader;+import java.nio.charset.StandardCharsets;import java.util.HashMap;import java.util.List;import java.util.Map;@@ -132,7 +132,7 @@ public class ICUTokenizerFactory extends TokenizerFactory implements ResourceLoaStringBuilder rules = new StringBuilder();InputStream rulesStream = loader.openResource(filename);BufferedReader reader = new BufferedReader- (IOUtils.getDecodingReader(rulesStream, IOUtils.CHARSET_UTF_8));+ (IOUtils.getDecodingReader(rulesStream, StandardCharsets.UTF_8));String line = null;while ((line = reader.readLine()) != null) {if ( ! line.startsWith("#"))diff --git a/lucene/analysis/icu/src/tools/java/org/apache/lucene/analysis/icu/GenerateUTR30DataFiles.java b/lucene/analysis/icu/src/tools/java/org/apache/lucene/analysis/icu/GenerateUTR30DataFiles.javaindex 7f1bdfe1269..2c194ff707d 100644--- a/lucene/analysis/icu/src/tools/java/org/apache/lucene/analysis/icu/GenerateUTR30DataFiles.java+++ b/lucene/analysis/icu/src/tools/java/org/apache/lucene/analysis/icu/GenerateUTR30DataFiles.java@@ -35,6 +35,7 @@ import java.io.OutputStreamWriter;import java.io.Writer;import java.net.URL;import java.net.URLConnection;+import java.nio.charset.StandardCharsets;import java.util.ArrayList;import java.util.List;import java.util.Locale;@@ -106,7 +107,7 @@ public class GenerateUTR30DataFiles {private static void expandDataFileRules(File file) throws IOException {final FileInputStream stream = new FileInputStream(file);- final InputStreamReader reader = new InputStreamReader(stream, "UTF-8");+ final InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8);final BufferedReader bufferedReader = new BufferedReader(reader);StringBuilder builder = new StringBuilder();String line;@@ -154,7 +155,7 @@ public class GenerateUTR30DataFiles {if (modified) {System.err.println("Expanding rules in and overwriting " + file.getName());final FileOutputStream out = new FileOutputStream(file, false);- Writer writer = new OutputStreamWriter(out, "UTF-8");+ Writer writer = new OutputStreamWriter(out, StandardCharsets.UTF_8);try {writer.write(builder.toString());} finally {@@ -178,8 +179,8 @@ public class GenerateUTR30DataFiles {System.err.print("Downloading " + NFKC_CF_TXT + " and making diacritic rules one-way ... ");URLConnection connection = openConnection(new URL(norm2url, NFC_TXT));BufferedReader reader = new BufferedReader- (new InputStreamReader(connection.getInputStream(), "UTF-8"));- Writer writer = new OutputStreamWriter(new FileOutputStream(NFC_TXT), "UTF-8");+ (new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8));+ Writer writer = new OutputStreamWriter(new FileOutputStream(NFC_TXT), StandardCharsets.UTF_8);try {String line;diff --git a/lucene/analysis/icu/src/tools/java/org/apache/lucene/analysis/icu/RBBIRuleCompiler.java b/lucene/analysis/icu/src/tools/java/org/apache/lucene/analysis/icu/RBBIRuleCompiler.javaindex 59f49903290..a4745d75e1f 100644--- a/lucene/analysis/icu/src/tools/java/org/apache/lucene/analysis/icu/RBBIRuleCompiler.java+++ b/lucene/analysis/icu/src/tools/java/org/apache/lucene/analysis/icu/RBBIRuleCompiler.java@@ -25,6 +25,7 @@ import java.io.FilenameFilter;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;+import java.nio.charset.StandardCharsets;import com.ibm.icu.text.RuleBasedBreakIterator;@@ -37,7 +38,7 @@ public class RBBIRuleCompiler {static String getRules(File ruleFile) throws IOException {StringBuilder rules = new StringBuilder();InputStream in = new FileInputStream(ruleFile);- BufferedReader cin = new BufferedReader(new InputStreamReader(in, "UTF-8"));+ BufferedReader cin = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));String line = null;while ((line = cin.readLine()) != null) {if (!line.startsWith("#"))diff --git a/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/StringMockResourceLoader.java b/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/StringMockResourceLoader.javaindex 856f6268ad2..611b2025f81 100644--- a/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/StringMockResourceLoader.java+++ b/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/StringMockResourceLoader.java@@ -20,6 +20,7 @@ package org.apache.lucene.analysis.ja;import java.io.ByteArrayInputStream;import java.io.IOException;import java.io.InputStream;+import java.nio.charset.StandardCharsets;import org.apache.lucene.analysis.util.ResourceLoader;@@ -52,6 +53,6 @@ class StringMockResourceLoader implements ResourceLoader {@Overridepublic InputStream openResource(String resource) throws IOException {- return new ByteArrayInputStream(text.getBytes("UTF-8"));+ return new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8));}}diff --git a/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapaneseTokenizer.java b/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapaneseTokenizer.javaindex 3ca8a465a88..1dc39615bde 100644--- a/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapaneseTokenizer.java+++ b/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestJapaneseTokenizer.java@@ -22,6 +22,7 @@ import java.io.InputStream;import java.io.InputStreamReader;import java.io.LineNumberReader;import java.io.Reader;+import java.nio.charset.StandardCharsets;import java.util.Random;import org.apache.lucene.analysis.Analyzer;@@ -34,7 +35,6 @@ import org.apache.lucene.analysis.ja.dict.ConnectionCosts;import org.apache.lucene.analysis.ja.dict.UserDictionary;import org.apache.lucene.analysis.ja.tokenattributes.*;import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;-import org.apache.lucene.util.IOUtils;import org.apache.lucene.util.TestUtil;import org.apache.lucene.util.UnicodeUtil;import org.apache.lucene.util.LuceneTestCase.Slow;@@ -49,7 +49,7 @@ public class TestJapaneseTokenizer extends BaseTokenStreamTestCase {}try {try {- Reader reader = new InputStreamReader(is, IOUtils.CHARSET_UTF_8);+ Reader reader = new InputStreamReader(is, StandardCharsets.UTF_8);return new UserDictionary(reader);} finally {is.close();@@ -571,7 +571,7 @@ public class TestJapaneseTokenizer extends BaseTokenStreamTestCase {/*public void testWikipedia() throws Exception {final FileInputStream fis = new FileInputStream("/q/lucene/jawiki-20120220-pages-articles.xml");- final Reader r = new BufferedReader(new InputStreamReader(fis, "UTF-8"));+ final Reader r = new BufferedReader(new InputStreamReader(fis, StandardCharsets.UTF_8));final long startTimeNS = System.nanoTime();boolean done = false;@@ -618,7 +618,7 @@ public class TestJapaneseTokenizer extends BaseTokenStreamTestCase {private void doTestBocchan(int numIterations) throws Exception {LineNumberReader reader = new LineNumberReader(new InputStreamReader(- this.getClass().getResourceAsStream("bocchan.utf-8"), "UTF-8"));+ this.getClass().getResourceAsStream("bocchan.utf-8"), StandardCharsets.UTF_8));String line = reader.readLine();reader.close();diff --git a/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestSearchMode.java b/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestSearchMode.javaindex 366fc5d7106..fa92e94a870 100644--- a/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestSearchMode.java+++ b/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/TestSearchMode.java@@ -22,13 +22,12 @@ import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.LineNumberReader;-import java.io.Reader;+import java.nio.charset.StandardCharsets;import org.apache.lucene.analysis.Analyzer;import org.apache.lucene.analysis.BaseTokenStreamTestCase;import org.apache.lucene.analysis.Tokenizer;import org.apache.lucene.analysis.ja.JapaneseTokenizer.Mode;-import org.apache.lucene.util.IOUtils;public class TestSearchMode extends BaseTokenStreamTestCase {private final static String SEGMENTATION_FILENAME = "search-segmentation-tests.txt";@@ -47,7 +46,7 @@ public class TestSearchMode extends BaseTokenStreamTestCase {throw new FileNotFoundException("Cannot find " + SEGMENTATION_FILENAME + " in test classpath");}try {- LineNumberReader reader = new LineNumberReader(new InputStreamReader(is, IOUtils.CHARSET_UTF_8));+ LineNumberReader reader = new LineNumberReader(new InputStreamReader(is, StandardCharsets.UTF_8));String line = null;while ((line = reader.readLine()) != null) {// Remove commentsdiff --git a/lucene/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/ja/util/ConnectionCostsBuilder.java b/lucene/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/ja/util/ConnectionCostsBuilder.javaindex c6ee197c520..bdabdb6b8d8 100644--- a/lucene/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/ja/util/ConnectionCostsBuilder.java+++ b/lucene/analysis/kuromoji/src/tools/java/org/apache/lucene/analysis/ja/util/ConnectionCostsBuilder.java@@ -24,6 +24,7 @@ import java.io.LineNumberReader;import java.nio.charset.Charset;import java.nio.charset.CharsetDecoder;import java.nio.charset.CodingErrorAction;+import java.nio.charset.StandardCharsets;public class ConnectionCostsBuilder {@@ -32,7 +33,7 @@ public class ConnectionCostsBuilder {public static ConnectionCostsWriter build(String filename) throws IOException {FileInputStream inputStream = new FileInputStream(filename);- Charset cs = Charset.forName("US-ASCII");+ Charset cs = StandardCharsets.US_ASCII;CharsetDecoder decoder = cs.newDecoder().onMalformedInput(CodingErrorAction.REPORT).onUnmappableCharacter(CodingErrorAction.REPORT);diff --git a/lucene/analysis/smartcn/src/java/org/apache/lucene/analysis/cn/smart/AnalyzerProfile.java b/lucene/analysis/smartcn/src/java/org/apache/lucene/analysis/cn/smart/AnalyzerProfile.javaindex 591a907bb25..8198abd6294 100644--- a/lucene/analysis/smartcn/src/java/org/apache/lucene/analysis/cn/smart/AnalyzerProfile.java+++ b/lucene/analysis/smartcn/src/java/org/apache/lucene/analysis/cn/smart/AnalyzerProfile.java@@ -21,10 +21,9 @@ import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStreamReader;+import java.nio.charset.StandardCharsets;import java.util.Properties;-import org.apache.lucene.util.IOUtils;-/*** Manages analysis data configuration for SmartChineseAnalyzer* <p>@@ -80,7 +79,7 @@ public class AnalyzerProfile {Properties prop = new Properties();try {FileInputStream input = new FileInputStream(propFile);- prop.load(new InputStreamReader(input, IOUtils.CHARSET_UTF_8));+ prop.load(new InputStreamReader(input, StandardCharsets.UTF_8));String dir = prop.getProperty("analysis.data.dir", "");input.close();return dir;diff --git a/lucene/analysis/smartcn/src/java/org/apache/lucene/analysis/cn/smart/SmartChineseAnalyzer.java b/lucene/analysis/smartcn/src/java/org/apache/lucene/analysis/cn/smart/SmartChineseAnalyzer.javaindex 283743e1685..a3a5a8c3680 100644--- a/lucene/analysis/smartcn/src/java/org/apache/lucene/analysis/cn/smart/SmartChineseAnalyzer.java+++ b/lucene/analysis/smartcn/src/java/org/apache/lucene/analysis/cn/smart/SmartChineseAnalyzer.java@@ -18,18 +18,16 @@package org.apache.lucene.analysis.cn.smart;import java.io.IOException;-import java.io.Reader;+import java.nio.charset.StandardCharsets;import java.util.Set;import org.apache.lucene.analysis.Analyzer;-import org.apache.lucene.analysis.en.PorterStemFilter;-import org.apache.lucene.analysis.util.CharArraySet;-import org.apache.lucene.analysis.util.WordlistLoader;import org.apache.lucene.analysis.TokenStream;import org.apache.lucene.analysis.Tokenizer;-import org.apache.lucene.analysis.cn.smart.SentenceTokenizer;-import org.apache.lucene.analysis.cn.smart.WordTokenFilter;import org.apache.lucene.analysis.core.StopFilter;+import org.apache.lucene.analysis.en.PorterStemFilter;+import org.apache.lucene.analysis.util.CharArraySet;+import org.apache.lucene.analysis.util.WordlistLoader;import org.apache.lucene.util.IOUtils;import org.apache.lucene.util.Version;@@ -90,7 +88,7 @@ public final class SmartChineseAnalyzer extends Analyzer {// make sure it is unmodifiable as we expose it in the outer classreturn CharArraySet.unmodifiableSet(WordlistLoader.getWordSet(IOUtils.getDecodingReader(SmartChineseAnalyzer.class, DEFAULT_STOPWORD_FILE,- IOUtils.CHARSET_UTF_8), STOPWORD_FILE_COMMENT,+ StandardCharsets.UTF_8), STOPWORD_FILE_COMMENT,Version.LUCENE_CURRENT));}}diff --git a/lucene/analysis/stempel/src/java/org/apache/lucene/analysis/pl/PolishAnalyzer.java b/lucene/analysis/stempel/src/java/org/apache/lucene/analysis/pl/PolishAnalyzer.javaindex 39f1e72b0fd..9240fbb623a 100644--- a/lucene/analysis/stempel/src/java/org/apache/lucene/analysis/pl/PolishAnalyzer.java+++ b/lucene/analysis/stempel/src/java/org/apache/lucene/analysis/pl/PolishAnalyzer.java@@ -19,6 +19,7 @@ package org.apache.lucene.analysis.pl;import java.io.IOException;import java.io.Reader;+import java.nio.charset.StandardCharsets;import org.apache.lucene.analysis.Analyzer;import org.apache.lucene.analysis.core.LowerCaseFilter;@@ -76,7 +77,7 @@ public final class PolishAnalyzer extends StopwordAnalyzerBase {static {try {DEFAULT_STOP_SET = WordlistLoader.getWordSet(IOUtils.getDecodingReader(PolishAnalyzer.class,- DEFAULT_STOPWORD_FILE, IOUtils.CHARSET_UTF_8), "#", Version.LUCENE_CURRENT);+ DEFAULT_STOPWORD_FILE, StandardCharsets.UTF_8), "#", Version.LUCENE_CURRENT);} catch (IOException ex) {// default set should always be present as it is part of the// distribution (JAR)diff --git a/lucene/analysis/stempel/src/test/org/egothor/stemmer/TestCompile.java b/lucene/analysis/stempel/src/test/org/egothor/stemmer/TestCompile.javaindex 76bd275cee1..8bca7bbf2e8 100644--- a/lucene/analysis/stempel/src/test/org/egothor/stemmer/TestCompile.java+++ b/lucene/analysis/stempel/src/test/org/egothor/stemmer/TestCompile.java@@ -65,10 +65,10 @@ import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.LineNumberReader;+import java.nio.charset.StandardCharsets;import java.util.Locale;import java.util.StringTokenizer;-import org.apache.lucene.util.IOUtils;import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.util.TestUtil;@@ -139,7 +139,7 @@ public class TestCompile extends LuceneTestCase {private static void assertTrie(Trie trie, String file, boolean usefull,boolean storeorig) throws Exception {LineNumberReader in = new LineNumberReader(new BufferedReader(- new InputStreamReader(new FileInputStream(file), IOUtils.CHARSET_UTF_8)));+ new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)));for (String line = in.readLine(); line != null; line = in.readLine()) {try {diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/Benchmark.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/Benchmark.javaindex 81ed4c2df0e..1ceb4d434e8 100644--- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/Benchmark.java+++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/Benchmark.java@@ -18,8 +18,8 @@ package org.apache.lucene.benchmark.byTask;*/import java.io.File;-import java.io.FileReader;import java.io.Reader;+import java.nio.charset.StandardCharsets;import org.apache.lucene.benchmark.byTask.utils.Algorithm;import org.apache.lucene.benchmark.byTask.utils.Config;@@ -107,7 +107,7 @@ public class Benchmark {Benchmark benchmark = null;try {- benchmark = new Benchmark(IOUtils.getDecodingReader(algFile, IOUtils.CHARSET_UTF_8));+ benchmark = new Benchmark(IOUtils.getDecodingReader(algFile, StandardCharsets.UTF_8));} catch (Exception e) {e.printStackTrace();System.exit(1);diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/DirContentSource.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/DirContentSource.javaindex 031a0f0b5bf..1357dce7305 100644--- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/DirContentSource.java+++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/DirContentSource.java@@ -18,7 +18,6 @@ package org.apache.lucene.benchmark.byTask.feeds;*/import org.apache.lucene.benchmark.byTask.utils.Config;-import org.apache.lucene.util.IOUtils;import java.io.BufferedReader;import java.io.File;@@ -26,6 +25,7 @@ import java.io.FileFilter;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStreamReader;+import java.nio.charset.StandardCharsets;import java.text.DateFormat;import java.text.ParsePosition;import java.text.SimpleDateFormat;@@ -206,7 +206,7 @@ public class DirContentSource extends ContentSource {name = f.getCanonicalPath()+"_"+iteration;}- BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(f), IOUtils.CHARSET_UTF_8));+ BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(f), StandardCharsets.UTF_8));String line = null;//First line is the date, 3rd is the title, rest is bodyString dateStr = reader.readLine();diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/DocMaker.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/DocMaker.javaindex 96768779817..45fb1a6a3fa 100644--- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/DocMaker.java+++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/DocMaker.java@@ -20,6 +20,7 @@ package org.apache.lucene.benchmark.byTask.feeds;import java.io.Closeable;import java.io.IOException;import java.io.UnsupportedEncodingException;+import java.nio.charset.StandardCharsets;import java.text.ParsePosition;import java.text.SimpleDateFormat;import java.util.Calendar;@@ -318,7 +319,7 @@ public class DocMaker implements Closeable {if (storeBytes) {Field bytesField = ds.getField(BYTES_FIELD, StringField.TYPE_STORED);- bytesField.setBytesValue(bdy.getBytes("UTF-8"));+ bytesField.setBytesValue(bdy.getBytes(StandardCharsets.UTF_8));doc.add(bytesField);}}diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/EnwikiContentSource.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/EnwikiContentSource.javaindex 86a2efafb07..10b61515032 100644--- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/EnwikiContentSource.java+++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/EnwikiContentSource.java@@ -20,18 +20,15 @@ package org.apache.lucene.benchmark.byTask.feeds;import java.io.File;import java.io.IOException;import java.io.InputStream;-import java.io.BufferedReader;-import java.io.InputStreamReader;-import java.nio.charset.CharsetDecoder;-import java.nio.charset.CodingErrorAction;+import java.nio.charset.StandardCharsets;import java.util.HashMap;import java.util.Locale;import java.util.Map;import org.apache.lucene.benchmark.byTask.utils.Config;import org.apache.lucene.benchmark.byTask.utils.StreamUtils;-import org.apache.lucene.util.ThreadInterruptedException;import org.apache.lucene.util.IOUtils;+import org.apache.lucene.util.ThreadInterruptedException;import org.xml.sax.Attributes;import org.xml.sax.InputSource;import org.xml.sax.SAXException;@@ -182,10 +179,7 @@ public class EnwikiContentSource extends ContentSource {if (localFileIS != null) { // null means fileIS was closed on ustry {// To work around a bug in XERCES (XERCESJ-1257), we assume the XML is always UTF8, so we simply provide reader.- CharsetDecoder decoder = IOUtils.CHARSET_UTF_8.newDecoder()- .onMalformedInput(CodingErrorAction.REPORT)- .onUnmappableCharacter(CodingErrorAction.REPORT);- reader.parse(new InputSource(new BufferedReader(new InputStreamReader(localFileIS, decoder))));+ reader.parse(new InputSource(IOUtils.getDecodingReader(localFileIS, StandardCharsets.UTF_8)));} catch (IOException ioe) {synchronized(EnwikiContentSource.this) {if (localFileIS != is) {diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/FileBasedQueryMaker.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/FileBasedQueryMaker.javaindex d7e3378c048..0d92db19824 100644--- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/FileBasedQueryMaker.java+++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/FileBasedQueryMaker.java@@ -9,6 +9,7 @@ import org.apache.lucene.util.IOUtils;import org.apache.lucene.util.Version;import java.io.*;+import java.nio.charset.StandardCharsets;import java.util.ArrayList;import java.util.List;@@ -62,12 +63,12 @@ public class FileBasedQueryMaker extends AbstractQueryMaker implements QueryMakeReader reader = null;// note: we use a decoding reader, so if your queries are screwed up you knowif (file.exists()) {- reader = IOUtils.getDecodingReader(file, IOUtils.CHARSET_UTF_8);+ reader = IOUtils.getDecodingReader(file, StandardCharsets.UTF_8);} else {//see if we can find it as a resourceInputStream asStream = FileBasedQueryMaker.class.getClassLoader().getResourceAsStream(fileName);if (asStream != null) {- reader = IOUtils.getDecodingReader(asStream, IOUtils.CHARSET_UTF_8);+ reader = IOUtils.getDecodingReader(asStream, StandardCharsets.UTF_8);}}if (reader != null) {diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/LineDocSource.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/LineDocSource.javaindex a1737e232a5..ad00211b62a 100644--- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/LineDocSource.java+++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/LineDocSource.java@@ -29,6 +29,7 @@ import java.util.Properties;import org.apache.lucene.benchmark.byTask.tasks.WriteLineDocTask;import org.apache.lucene.benchmark.byTask.utils.Config;import org.apache.lucene.benchmark.byTask.utils.StreamUtils;+import org.apache.lucene.util.IOUtils;/*** A {@link ContentSource} reading one line at a time as a@@ -277,7 +278,7 @@ public class LineDocSource extends ContentSource {}file = new File(fileName).getAbsoluteFile();if (encoding == null) {- encoding = "UTF-8";+ encoding = IOUtils.UTF_8;}}diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/ReutersContentSource.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/ReutersContentSource.javaindex b3106af48b1..b4d58bc0b01 100644--- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/ReutersContentSource.java+++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/ReutersContentSource.java@@ -22,6 +22,7 @@ import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStreamReader;+import java.nio.charset.StandardCharsets;import java.text.DateFormat;import java.text.ParsePosition;import java.text.SimpleDateFormat;@@ -30,7 +31,6 @@ import java.util.Date;import java.util.Locale;import org.apache.lucene.benchmark.byTask.utils.Config;-import org.apache.lucene.util.IOUtils;/*** A {@link ContentSource} reading from the Reuters collection.@@ -114,7 +114,7 @@ public class ReutersContentSource extends ContentSource {name = f.getCanonicalPath() + "_" + iteration;}- BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(f), IOUtils.CHARSET_UTF_8));+ BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(f), StandardCharsets.UTF_8));try {// First line is the date, 3rd is the title, rest is bodyString dateStr = reader.readLine();diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/TrecContentSource.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/TrecContentSource.javaindex 1942684b379..439fc594694 100644--- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/TrecContentSource.java+++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/TrecContentSource.java@@ -22,6 +22,7 @@ import java.io.File;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;+import java.nio.charset.StandardCharsets;import java.text.DateFormat;import java.text.ParsePosition;import java.text.SimpleDateFormat;@@ -320,7 +321,7 @@ public class TrecContentSource extends ContentSource {}// encodingif (encoding == null) {- encoding = "ISO-8859-1";+ encoding = StandardCharsets.ISO_8859_1.name();}// iteration exclusion in doc nameexcludeDocnameIteration = config.get("content.source.excludeIteration", false);diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/WriteEnwikiLineDocTask.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/WriteEnwikiLineDocTask.javaindex 5c9b88f1411..334e52fdc35 100644--- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/WriteEnwikiLineDocTask.java+++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/WriteEnwikiLineDocTask.java@@ -5,6 +5,7 @@ import java.io.File;import java.io.OutputStream;import java.io.OutputStreamWriter;import java.io.PrintWriter;+import java.nio.charset.StandardCharsets;import org.apache.lucene.benchmark.byTask.PerfRunData;import org.apache.lucene.benchmark.byTask.feeds.DocMaker;@@ -41,7 +42,7 @@ public class WriteEnwikiLineDocTask extends WriteLineDocTask {public WriteEnwikiLineDocTask(PerfRunData runData) throws Exception {super(runData);OutputStream out = StreamUtils.outputStream(categoriesLineFile(new File(fname)));- categoryLineFileOut = new PrintWriter(new BufferedWriter(new OutputStreamWriter(out, "UTF-8"), StreamUtils.BUFFER_SIZE));+ categoryLineFileOut = new PrintWriter(new BufferedWriter(new OutputStreamWriter(out, StandardCharsets.UTF_8), StreamUtils.BUFFER_SIZE));writeHeader(categoryLineFileOut);}diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/WriteLineDocTask.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/WriteLineDocTask.javaindex d0f1c5292ed..9715b35871c 100644--- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/WriteLineDocTask.java+++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/WriteLineDocTask.java@@ -22,6 +22,7 @@ import java.io.File;import java.io.OutputStream;import java.io.OutputStreamWriter;import java.io.PrintWriter;+import java.nio.charset.StandardCharsets;import java.util.Arrays;import java.util.HashSet;import java.util.regex.Matcher;@@ -101,7 +102,7 @@ public class WriteLineDocTask extends PerfTask {throw new IllegalArgumentException("line.file.out must be set");}OutputStream out = StreamUtils.outputStream(new File(fname));- lineFileOut = new PrintWriter(new BufferedWriter(new OutputStreamWriter(out, "UTF-8"), StreamUtils.BUFFER_SIZE));+ lineFileOut = new PrintWriter(new BufferedWriter(new OutputStreamWriter(out, StandardCharsets.UTF_8), StreamUtils.BUFFER_SIZE));docMaker = runData.getDocMaker();// init fieldsdiff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/quality/trec/QueryDriver.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/quality/trec/QueryDriver.javaindex b3bcb5544b1..a683b42d0ed 100644--- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/quality/trec/QueryDriver.java+++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/quality/trec/QueryDriver.java@@ -31,6 +31,7 @@ import java.io.File;import java.io.OutputStreamWriter;import java.io.PrintWriter;import java.nio.charset.Charset;+import java.nio.charset.StandardCharsets;import java.util.HashSet;import java.util.Set;@@ -53,7 +54,7 @@ public class QueryDriver {File topicsFile = new File(args[0]);File qrelsFile = new File(args[1]);- SubmissionReport submitLog = new SubmissionReport(new PrintWriter(args[2], "UTF-8"), "lucene");+ SubmissionReport submitLog = new SubmissionReport(new PrintWriter(args[2], IOUtils.UTF_8 /* huh, no nio.Charset ctor? */), "lucene");FSDirectory dir = FSDirectory.open(new File(args[3]));String fieldSpec = args.length == 5 ? args[4] : "T"; // default to Title-only if not specified.IndexReader reader = DirectoryReader.open(dir);@@ -66,10 +67,10 @@ public class QueryDriver {// use trec utilities to read trec topics into quality queriesTrecTopicsReader qReader = new TrecTopicsReader();- QualityQuery qqs[] = qReader.readQueries(new BufferedReader(IOUtils.getDecodingReader(topicsFile, IOUtils.CHARSET_UTF_8)));+ QualityQuery qqs[] = qReader.readQueries(new BufferedReader(IOUtils.getDecodingReader(topicsFile, StandardCharsets.UTF_8)));// prepare judge, with trec utilities that read from a QRels file- Judge judge = new TrecJudge(new BufferedReader(IOUtils.getDecodingReader(qrelsFile, IOUtils.CHARSET_UTF_8)));+ Judge judge = new TrecJudge(new BufferedReader(IOUtils.getDecodingReader(qrelsFile, StandardCharsets.UTF_8)));// validate topics & judgments match each otherjudge.validateData(qqs, logger);diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/utils/ExtractReuters.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/utils/ExtractReuters.javaindex e0fe7a62e27..8e7f7e639b7 100644--- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/utils/ExtractReuters.java+++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/utils/ExtractReuters.java@@ -21,16 +21,13 @@ import java.io.File;import java.io.FileFilter;import java.io.FileInputStream;import java.io.FileOutputStream;-import java.io.FileReader;-import java.io.FileWriter;import java.io.IOException;import java.io.InputStreamReader;import java.io.OutputStreamWriter;+import java.nio.charset.StandardCharsets;import java.util.regex.Matcher;import java.util.regex.Pattern;-import org.apache.lucene.util.IOUtils;-/*** Split the Reuters SGML documents into Simple Text files containing: Title, Date, Dateline, Body@@ -78,7 +75,7 @@ public class ExtractReuters {*/protected void extractFile(File sgmFile) {try {- BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(sgmFile), IOUtils.CHARSET_UTF_8));+ BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(sgmFile), StandardCharsets.UTF_8));StringBuilder buffer = new StringBuilder(1024);StringBuilder outBuffer = new StringBuilder(1024);@@ -112,7 +109,7 @@ public class ExtractReuters {File outFile = new File(outputDir, sgmFile.getName() + "-"+ (docNumber++) + ".txt");// System.out.println("Writing " + outFile);- OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(outFile), IOUtils.CHARSET_UTF_8);+ OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(outFile), StandardCharsets.UTF_8);writer.write(out);writer.close();outBuffer.setLength(0);diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/utils/ExtractWikipedia.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/utils/ExtractWikipedia.javaindex 387a0ad284d..6bc02196aa4 100644--- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/utils/ExtractWikipedia.java+++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/utils/ExtractWikipedia.java@@ -22,6 +22,7 @@ import java.io.FileOutputStream;import java.io.IOException;import java.io.OutputStreamWriter;import java.io.Writer;+import java.nio.charset.StandardCharsets;import java.util.Properties;import org.apache.lucene.benchmark.byTask.feeds.ContentSource;@@ -30,7 +31,6 @@ import org.apache.lucene.benchmark.byTask.feeds.EnwikiContentSource;import org.apache.lucene.benchmark.byTask.feeds.NoMoreDataException;import org.apache.lucene.benchmark.byTask.utils.Config;import org.apache.lucene.document.Document;-import org.apache.lucene.util.IOUtils;/*** Extract the downloaded Wikipedia dump into separate files for indexing.@@ -86,7 +86,7 @@ public class ExtractWikipedia {contents.append("\n");try {- Writer writer = new OutputStreamWriter(new FileOutputStream(f), IOUtils.CHARSET_UTF_8);+ Writer writer = new OutputStreamWriter(new FileOutputStream(f), StandardCharsets.UTF_8);writer.write(contents.toString());writer.close();} catch (IOException ioe) {diff --git a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.javaindex 2100e798b0c..12e1523a251 100644--- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java+++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java@@ -21,6 +21,7 @@ import java.io.BufferedReader;import java.io.File;import java.io.FileInputStream;import java.io.InputStreamReader;+import java.nio.charset.StandardCharsets;import java.text.Collator;import java.util.List;import java.util.Locale;@@ -406,7 +407,7 @@ public class TestPerfTasksLogic extends BenchmarkTestCase {BufferedReader r = new BufferedReader(new InputStreamReader(- new FileInputStream(lineFile), "UTF-8"));+ new FileInputStream(lineFile), StandardCharsets.UTF_8));int numLines = 0;String line;while((line = r.readLine()) != null) {diff --git a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksParse.java b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksParse.javaindex 2f8a555cf2b..7999a553de6 100644--- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksParse.java+++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksParse.java@@ -25,6 +25,7 @@ import java.io.IOException;import java.io.InputStreamReader;import java.io.StringReader;import java.nio.charset.Charset;+import java.nio.charset.StandardCharsets;import java.util.ArrayList;import org.apache.lucene.benchmark.byTask.feeds.AbstractQueryMaker;@@ -120,7 +121,7 @@ public class TestPerfTasksParse extends LuceneTestCase {public boolean accept(File pathname) { return pathname.isFile() && pathname.getName().endsWith(".alg"); }})) {try {- Config config = new Config(new InputStreamReader(new FileInputStream(algFile), "UTF-8"));+ Config config = new Config(new InputStreamReader(new FileInputStream(algFile), StandardCharsets.UTF_8));String contentSource = config.get("content.source", null);if (contentSource != null) { Class.forName(contentSource); }config.set("work.dir", new File(TEMP_DIR,"work").getAbsolutePath());diff --git a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/DocMakerTest.java b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/DocMakerTest.javaindex 6a509e4fcad..dcff96f8e24 100644--- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/DocMakerTest.java+++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/DocMakerTest.java@@ -36,6 +36,7 @@ import org.apache.lucene.index.Term;import org.apache.lucene.search.IndexSearcher;import org.apache.lucene.search.TermQuery;import org.apache.lucene.search.TopDocs;+import org.apache.lucene.util.IOUtils;/** Tests the functionality of {@link DocMaker}. */public class DocMakerTest extends BenchmarkTestCase {@@ -166,7 +167,7 @@ public class DocMakerTest extends BenchmarkTestCase {// DocMaker did not close its ContentSource if resetInputs was called twice,// leading to a file handle leak.File f = new File(getWorkDir(), "docMakerLeak.txt");- PrintStream ps = new PrintStream(f, "UTF-8");+ PrintStream ps = new PrintStream(f, IOUtils.UTF_8);ps.println("one title\t" + System.currentTimeMillis() + "\tsome content");ps.close();diff --git a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/EnwikiContentSourceTest.java b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/EnwikiContentSourceTest.javaindex 785cd4ffd76..b66b8e0d91f 100644--- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/EnwikiContentSourceTest.java+++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/EnwikiContentSourceTest.java@@ -18,15 +18,13 @@ package org.apache.lucene.benchmark.byTask.feeds;*/import java.io.ByteArrayInputStream;-import java.io.ByteArrayOutputStream;import java.io.IOException;import java.io.InputStream;-import java.io.OutputStreamWriter;+import java.nio.charset.StandardCharsets;import java.text.ParseException;import java.util.Properties;import org.apache.lucene.benchmark.byTask.utils.Config;-import org.apache.lucene.util.IOUtils;import org.apache.lucene.util.LuceneTestCase;import org.junit.Test;@@ -43,7 +41,7 @@ public class EnwikiContentSourceTest extends LuceneTestCase {@Overrideprotected InputStream openInputStream() throws IOException {- return new ByteArrayInputStream(docs.getBytes(IOUtils.CHARSET_UTF_8));+ return new ByteArrayInputStream(docs.getBytes(StandardCharsets.UTF_8));}}diff --git a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/LineDocSourceTest.java b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/LineDocSourceTest.javaindex d830d396d72..9b6bfd11b13 100644--- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/LineDocSourceTest.java+++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/feeds/LineDocSourceTest.java@@ -23,6 +23,7 @@ import java.io.FileOutputStream;import java.io.IOException;import java.io.OutputStream;import java.io.OutputStreamWriter;+import java.nio.charset.StandardCharsets;import java.util.Properties;import org.apache.commons.compress.compressors.CompressorStreamFactory;@@ -53,7 +54,7 @@ public class LineDocSourceTest extends BenchmarkTestCase {private void createBZ2LineFile(File file, boolean addHeader) throws Exception {OutputStream out = new FileOutputStream(file);out = csFactory.createCompressorOutputStream("bzip2", out);- BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, "utf-8"));+ BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, StandardCharsets.UTF_8));writeDocsToFile(writer, addHeader, null);writer.close();}@@ -90,14 +91,14 @@ public class LineDocSourceTest extends BenchmarkTestCase {private void createRegularLineFile(File file, boolean addHeader) throws Exception {OutputStream out = new FileOutputStream(file);- BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, "utf-8"));+ BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, StandardCharsets.UTF_8));writeDocsToFile(writer, addHeader, null);writer.close();}private void createRegularLineFileWithMoreFields(File file, String...extraFields) throws Exception {OutputStream out = new FileOutputStream(file);- BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, "utf-8"));+ BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, StandardCharsets.UTF_8));Properties p = new Properties();for (String f : extraFields) {p.setProperty(f, f);@@ -209,7 +210,7 @@ public class LineDocSourceTest extends BenchmarkTestCase {for (int i = 0; i < testCases.length; i++) {File file = new File(getWorkDir(), "one-line");- BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "utf-8"));+ BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8));writer.write(testCases[i]);writer.newLine();writer.close();diff --git a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/WriteEnwikiLineDocTaskTest.java b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/WriteEnwikiLineDocTaskTest.javaindex d129bbb7a37..d93fef2c7b0 100644--- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/WriteEnwikiLineDocTaskTest.java+++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/WriteEnwikiLineDocTaskTest.java@@ -22,6 +22,7 @@ import java.io.File;import java.io.FileInputStream;import java.io.InputStream;import java.io.InputStreamReader;+import java.nio.charset.StandardCharsets;import java.util.Properties;import java.util.concurrent.atomic.AtomicInteger;@@ -73,7 +74,7 @@ public class WriteEnwikiLineDocTaskTest extends BenchmarkTestCase {private void doReadTest(int n, File file, String expTitle, String expDate, String expBody) throws Exception {InputStream in = new FileInputStream(file);- BufferedReader br = new BufferedReader(new InputStreamReader(in, "utf-8"));+ BufferedReader br = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));try {String line = br.readLine();WriteLineDocTaskTest.assertHeaderLine(line);diff --git a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/WriteLineDocTaskTest.java b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/WriteLineDocTaskTest.javaindex 47aa48213b6..093d52ec60c 100644--- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/WriteLineDocTaskTest.java+++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/WriteLineDocTaskTest.java@@ -22,6 +22,7 @@ import java.io.File;import java.io.FileInputStream;import java.io.InputStream;import java.io.InputStreamReader;+import java.nio.charset.StandardCharsets;import java.util.HashSet;import java.util.Properties;import java.util.Set;@@ -168,7 +169,7 @@ public class WriteLineDocTaskTest extends BenchmarkTestCase {default:assertFalse("Unknown file type!",true); //fail, should not happen}- BufferedReader br = new BufferedReader(new InputStreamReader(in, "utf-8"));+ BufferedReader br = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));try {String line = br.readLine();assertHeaderLine(line);@@ -274,7 +275,7 @@ public class WriteLineDocTaskTest extends BenchmarkTestCase {wldt.doLogic();wldt.close();- BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "utf-8"));+ BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));try {String line = br.readLine();assertHeaderLine(line);@@ -292,7 +293,7 @@ public class WriteLineDocTaskTest extends BenchmarkTestCase {wldt.doLogic();wldt.close();- BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "utf-8"));+ BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));try {String line = br.readLine();assertHeaderLine(line);@@ -310,7 +311,7 @@ public class WriteLineDocTaskTest extends BenchmarkTestCase {wldt.doLogic();wldt.close();- BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "utf-8"));+ BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));try {String line = br.readLine();assertHeaderLine(line);@@ -345,7 +346,7 @@ public class WriteLineDocTaskTest extends BenchmarkTestCase {wldt.close();Set<String> ids = new HashSet<>();- BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "utf-8"));+ BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));try {String line = br.readLine();assertHeaderLine(line); // header line is written once, no matter how many threads there arediff --git a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/utils/StreamUtilsTest.java b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/utils/StreamUtilsTest.javaindex 8c4c50ca94f..15fb0c965f0 100644--- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/utils/StreamUtilsTest.java+++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/utils/StreamUtilsTest.java@@ -26,10 +26,10 @@ import java.io.InputStream;import java.io.InputStreamReader;import java.io.OutputStream;import java.io.OutputStreamWriter;+import java.nio.charset.StandardCharsets;import org.apache.commons.compress.compressors.CompressorStreamFactory;import org.apache.lucene.benchmark.BenchmarkTestCase;-import org.apache.lucene.util.IOUtils;import org.apache.lucene.util.TestUtil;import org.junit.After;import org.junit.Before;@@ -87,7 +87,7 @@ public class StreamUtilsTest extends BenchmarkTestCase {private File rawTextFile(String ext) throws Exception {File f = new File(testDir,"testfile." + ext);- BufferedWriter w = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), IOUtils.CHARSET_UTF_8));+ BufferedWriter w = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), StandardCharsets.UTF_8));w.write(TEXT);w.newLine();w.close();@@ -116,7 +116,7 @@ public class StreamUtilsTest extends BenchmarkTestCase {}private void writeText(OutputStream os) throws IOException {- BufferedWriter w = new BufferedWriter(new OutputStreamWriter(os, IOUtils.CHARSET_UTF_8));+ BufferedWriter w = new BufferedWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8));w.write(TEXT);w.newLine();w.close();@@ -124,7 +124,7 @@ public class StreamUtilsTest extends BenchmarkTestCase {private void assertReadText(File f) throws Exception {InputStream ir = StreamUtils.inputStream(f);- InputStreamReader in = new InputStreamReader(ir, IOUtils.CHARSET_UTF_8);+ InputStreamReader in = new InputStreamReader(ir, StandardCharsets.UTF_8);BufferedReader r = new BufferedReader(in);String line = r.readLine();assertEquals("Wrong text found in "+f.getName(), TEXT, line);diff --git a/lucene/benchmark/src/test/org/apache/lucene/benchmark/quality/TestQualityRun.java b/lucene/benchmark/src/test/org/apache/lucene/benchmark/quality/TestQualityRun.javaindex 09502a10140..64de265f588 100644--- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/quality/TestQualityRun.java+++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/quality/TestQualityRun.java@@ -34,6 +34,7 @@ import java.io.InputStreamReader;import java.io.OutputStreamWriter;import java.io.PrintWriter;import java.nio.charset.Charset;+import java.nio.charset.StandardCharsets;/*** Test that quality run does its job.@@ -62,11 +63,11 @@ public class TestQualityRun extends BenchmarkTestCase {// prepare topicsInputStream topics = getClass().getResourceAsStream("trecTopics.txt");TrecTopicsReader qReader = new TrecTopicsReader();- QualityQuery qqs[] = qReader.readQueries(new BufferedReader(new InputStreamReader(topics, "UTF-8")));+ QualityQuery qqs[] = qReader.readQueries(new BufferedReader(new InputStreamReader(topics, StandardCharsets.UTF_8)));// prepare judgeInputStream qrels = getClass().getResourceAsStream("trecQRels.txt");- Judge judge = new TrecJudge(new BufferedReader(new InputStreamReader(qrels, "UTF-8")));+ Judge judge = new TrecJudge(new BufferedReader(new InputStreamReader(qrels, StandardCharsets.UTF_8)));// validate topics & judgments match each otherjudge.validateData(qqs, logger);@@ -147,7 +148,7 @@ public class TestQualityRun extends BenchmarkTestCase {InputStream topicsFile = getClass().getResourceAsStream("trecTopics.txt");TrecTopicsReader qReader = new TrecTopicsReader();QualityQuery qqs[] = qReader.readQueries(- new BufferedReader(new InputStreamReader(topicsFile, "UTF-8")));+ new BufferedReader(new InputStreamReader(topicsFile, StandardCharsets.UTF_8)));assertEquals(20, qqs.length);diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextDocValuesReader.java b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextDocValuesReader.javaindex 7d1798b84a5..9b810b7e220 100644--- a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextDocValuesReader.java+++ b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextDocValuesReader.java@@ -30,6 +30,7 @@ import static org.apache.lucene.codecs.simpletext.SimpleTextDocValuesWriter.TYPEimport java.io.IOException;import java.math.BigDecimal;import java.math.BigInteger;+import java.nio.charset.StandardCharsets;import java.text.DecimalFormat;import java.text.DecimalFormatSymbols;import java.text.ParseException;@@ -225,7 +226,7 @@ class SimpleTextDocValuesReader extends DocValuesProducer {assert StringHelper.startsWith(scratch, LENGTH);int len;try {- len = decoder.parse(new String(scratch.bytes, scratch.offset + LENGTH.length, scratch.length - LENGTH.length, "UTF-8")).intValue();+ len = decoder.parse(new String(scratch.bytes, scratch.offset + LENGTH.length, scratch.length - LENGTH.length, StandardCharsets.UTF_8)).intValue();} catch (ParseException pe) {CorruptIndexException e = new CorruptIndexException("failed to parse int length (resource=" + in + ")");e.initCause(pe);@@ -257,7 +258,7 @@ class SimpleTextDocValuesReader extends DocValuesProducer {assert StringHelper.startsWith(scratch, LENGTH);int len;try {- len = decoder.parse(new String(scratch.bytes, scratch.offset + LENGTH.length, scratch.length - LENGTH.length, "UTF-8")).intValue();+ len = decoder.parse(new String(scratch.bytes, scratch.offset + LENGTH.length, scratch.length - LENGTH.length, StandardCharsets.UTF_8)).intValue();} catch (ParseException pe) {CorruptIndexException e = new CorruptIndexException("failed to parse int length (resource=" + in + ")");e.initCause(pe);@@ -326,7 +327,7 @@ class SimpleTextDocValuesReader extends DocValuesProducer {assert StringHelper.startsWith(scratch, LENGTH): "got " + scratch.utf8ToString() + " in=" + in;int len;try {- len = decoder.parse(new String(scratch.bytes, scratch.offset + LENGTH.length, scratch.length - LENGTH.length, "UTF-8")).intValue();+ len = decoder.parse(new String(scratch.bytes, scratch.offset + LENGTH.length, scratch.length - LENGTH.length, StandardCharsets.UTF_8)).intValue();} catch (ParseException pe) {CorruptIndexException e = new CorruptIndexException("failed to parse int length (resource=" + in + ")");e.initCause(pe);@@ -404,7 +405,7 @@ class SimpleTextDocValuesReader extends DocValuesProducer {assert StringHelper.startsWith(scratch, LENGTH): "got " + scratch.utf8ToString() + " in=" + in;int len;try {- len = decoder.parse(new String(scratch.bytes, scratch.offset + LENGTH.length, scratch.length - LENGTH.length, "UTF-8")).intValue();+ len = decoder.parse(new String(scratch.bytes, scratch.offset + LENGTH.length, scratch.length - LENGTH.length, StandardCharsets.UTF_8)).intValue();} catch (ParseException pe) {CorruptIndexException e = new CorruptIndexException("failed to parse int length (resource=" + in + ")");e.initCause(pe);@@ -460,7 +461,7 @@ class SimpleTextDocValuesReader extends DocValuesProducer {/** Used only in ctor: */private String stripPrefix(BytesRef prefix) throws IOException {- return new String(scratch.bytes, scratch.offset + prefix.length, scratch.length - prefix.length, "UTF-8");+ return new String(scratch.bytes, scratch.offset + prefix.length, scratch.length - prefix.length, StandardCharsets.UTF_8);}@Overridediff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldInfosReader.java b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldInfosReader.javaindex 79206a79a3c..16809793c1c 100644--- a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldInfosReader.java+++ b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldInfosReader.java@@ -18,6 +18,7 @@ package org.apache.lucene.codecs.simpletext;*/import java.io.IOException;+import java.nio.charset.StandardCharsets;import java.util.Collections;import java.util.HashMap;import java.util.Map;@@ -154,6 +155,6 @@ public class SimpleTextFieldInfosReader extends FieldInfosReader {}private String readString(int offset, BytesRef scratch) {- return new String(scratch.bytes, scratch.offset+offset, scratch.length-offset, IOUtils.CHARSET_UTF_8);+ return new String(scratch.bytes, scratch.offset+offset, scratch.length-offset, StandardCharsets.UTF_8);}}diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldsReader.java b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldsReader.javaindex 17b6014de9a..af3c52dec2a 100644--- a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldsReader.java+++ b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldsReader.java@@ -18,6 +18,7 @@ package org.apache.lucene.codecs.simpletext;*/import java.io.IOException;+import java.nio.charset.StandardCharsets;import java.util.Collections;import java.util.HashMap;import java.util.Iterator;@@ -90,7 +91,7 @@ class SimpleTextFieldsReader extends FieldsProducer {if (scratch.equals(END)) {return fields;} else if (StringHelper.startsWith(scratch, FIELD)) {- String fieldName = new String(scratch.bytes, scratch.offset + FIELD.length, scratch.length - FIELD.length, "UTF-8");+ String fieldName = new String(scratch.bytes, scratch.offset + FIELD.length, scratch.length - FIELD.length, StandardCharsets.UTF_8);fields.put(fieldName, in.getFilePointer());}}diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoReader.java b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoReader.javaindex e117155a77d..b52fdcb7128 100644--- a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoReader.java+++ b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoReader.java@@ -27,6 +27,7 @@ import static org.apache.lucene.codecs.simpletext.SimpleTextSegmentInfoWriter.SIimport static org.apache.lucene.codecs.simpletext.SimpleTextSegmentInfoWriter.SI_VERSION;import java.io.IOException;+import java.nio.charset.StandardCharsets;import java.util.HashMap;import java.util.HashSet;import java.util.Map;@@ -112,6 +113,6 @@ public class SimpleTextSegmentInfoReader extends SegmentInfoReader {}private String readString(int offset, BytesRef scratch) {- return new String(scratch.bytes, scratch.offset+offset, scratch.length-offset, IOUtils.CHARSET_UTF_8);+ return new String(scratch.bytes, scratch.offset+offset, scratch.length-offset, StandardCharsets.UTF_8);}}diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextStoredFieldsReader.java b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextStoredFieldsReader.javaindex ea31336afa4..37f2f036567 100644--- a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextStoredFieldsReader.java+++ b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextStoredFieldsReader.java@@ -18,6 +18,7 @@ package org.apache.lucene.codecs.simpletext;*/import java.io.IOException;+import java.nio.charset.StandardCharsets;import org.apache.lucene.codecs.StoredFieldsReader;import org.apache.lucene.index.FieldInfo;@@ -141,7 +142,7 @@ public class SimpleTextStoredFieldsReader extends StoredFieldsReader {readLine();assert StringHelper.startsWith(scratch, VALUE);if (type == TYPE_STRING) {- visitor.stringField(fieldInfo, new String(scratch.bytes, scratch.offset+VALUE.length, scratch.length-VALUE.length, "UTF-8"));+ visitor.stringField(fieldInfo, new String(scratch.bytes, scratch.offset+VALUE.length, scratch.length-VALUE.length, StandardCharsets.UTF_8));} else if (type == TYPE_BINARY) {byte[] copy = new byte[scratch.length-VALUE.length];System.arraycopy(scratch.bytes, scratch.offset+VALUE.length, copy, 0, copy.length);diff --git a/lucene/core/src/java/org/apache/lucene/codecs/BlockTreeTermsReader.java b/lucene/core/src/java/org/apache/lucene/codecs/BlockTreeTermsReader.javaindex 396315bb492..a66288d7c10 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/BlockTreeTermsReader.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/BlockTreeTermsReader.java@@ -391,7 +391,7 @@ public class BlockTreeTermsReader extends FieldsProducer {final ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);PrintStream out;try {- out = new PrintStream(bos, false, "UTF-8");+ out = new PrintStream(bos, false, IOUtils.UTF_8);} catch (UnsupportedEncodingException bogus) {throw new RuntimeException(bogus);}diff --git a/lucene/core/src/java/org/apache/lucene/codecs/compressing/CompressingStoredFieldsReader.java b/lucene/core/src/java/org/apache/lucene/codecs/compressing/CompressingStoredFieldsReader.javaindex 24fa291d4cd..c6704f8a0cb 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/compressing/CompressingStoredFieldsReader.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/compressing/CompressingStoredFieldsReader.java@@ -35,6 +35,7 @@ import static org.apache.lucene.codecs.lucene40.Lucene40StoredFieldsWriter.FIELDimport java.io.EOFException;import java.io.IOException;+import java.nio.charset.StandardCharsets;import java.util.Arrays;import org.apache.lucene.codecs.CodecUtil;@@ -187,7 +188,7 @@ public final class CompressingStoredFieldsReader extends StoredFieldsReader {length = in.readVInt();data = new byte[length];in.readBytes(data, 0, length);- visitor.stringField(info, new String(data, IOUtils.CHARSET_UTF_8));+ visitor.stringField(info, new String(data, StandardCharsets.UTF_8));break;case NUMERIC_INT:visitor.intField(info, in.readInt());diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40StoredFieldsReader.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40StoredFieldsReader.javaindex 651bbde52fd..5df27bb3f7c 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40StoredFieldsReader.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40StoredFieldsReader.java@@ -34,6 +34,7 @@ import org.apache.lucene.store.IndexInput;import org.apache.lucene.util.IOUtils;import java.io.Closeable;+import java.nio.charset.StandardCharsets;import static org.apache.lucene.codecs.lucene40.Lucene40StoredFieldsWriter.*;@@ -193,7 +194,7 @@ public final class Lucene40StoredFieldsReader extends StoredFieldsReader implemeif ((bits & FIELD_IS_BINARY) != 0) {visitor.binaryField(info, bytes);} else {- visitor.stringField(info, new String(bytes, 0, bytes.length, IOUtils.CHARSET_UTF_8));+ visitor.stringField(info, new String(bytes, 0, bytes.length, StandardCharsets.UTF_8));}}}diff --git a/lucene/core/src/java/org/apache/lucene/index/Term.java b/lucene/core/src/java/org/apache/lucene/index/Term.javaindex 30d89126d50..848fe3d4820 100644--- a/lucene/core/src/java/org/apache/lucene/index/Term.java+++ b/lucene/core/src/java/org/apache/lucene/index/Term.java@@ -21,9 +21,9 @@ import java.nio.ByteBuffer;import java.nio.charset.CharacterCodingException;import java.nio.charset.CharsetDecoder;import java.nio.charset.CodingErrorAction;+import java.nio.charset.StandardCharsets;import org.apache.lucene.util.BytesRef;-import org.apache.lucene.util.IOUtils;/**A Term represents a word from text. This is the unit of search. It is@@ -83,7 +83,7 @@ public final class Term implements Comparable<Term> {* the raw bytes will be printed instead. */public static final String toString(BytesRef termText) {// the term might not be text, but usually is. so we make a best effort- CharsetDecoder decoder = IOUtils.CHARSET_UTF_8.newDecoder()+ CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder().onMalformedInput(CodingErrorAction.REPORT).onUnmappableCharacter(CodingErrorAction.REPORT);try {diff --git a/lucene/core/src/java/org/apache/lucene/store/DataInput.java b/lucene/core/src/java/org/apache/lucene/store/DataInput.javaindex 6bcf18ee523..adbe38c1ada 100644--- a/lucene/core/src/java/org/apache/lucene/store/DataInput.java+++ b/lucene/core/src/java/org/apache/lucene/store/DataInput.java@@ -18,13 +18,12 @@ package org.apache.lucene.store;*/import java.io.IOException;+import java.nio.charset.StandardCharsets;import java.util.HashMap;import java.util.HashSet;import java.util.Map;import java.util.Set;-import org.apache.lucene.util.IOUtils;-/*** Abstract base class for performing read operations of Lucene's low-level* data types.@@ -188,7 +187,7 @@ public abstract class DataInput implements Cloneable {int length = readVInt();final byte[] bytes = new byte[length];readBytes(bytes, 0, length);- return new String(bytes, 0, length, IOUtils.CHARSET_UTF_8);+ return new String(bytes, 0, length, StandardCharsets.UTF_8);}/** Returns a clone of this stream.diff --git a/lucene/core/src/java/org/apache/lucene/util/IOUtils.java b/lucene/core/src/java/org/apache/lucene/util/IOUtils.javaindex 52cbf098d5b..2e183c42348 100644--- a/lucene/core/src/java/org/apache/lucene/util/IOUtils.java+++ b/lucene/core/src/java/org/apache/lucene/util/IOUtils.java@@ -31,6 +31,7 @@ import java.io.Reader;import java.nio.charset.Charset;import java.nio.charset.CharsetDecoder;import java.nio.charset.CodingErrorAction;+import java.nio.charset.StandardCharsets;/** This class emulates the new Java 7 "Try-With-Resources" statement.* Remove once Lucene is on Java 7.@@ -38,16 +39,21 @@ import java.nio.charset.CodingErrorAction;public final class IOUtils {/**- * UTF-8 charset string- * @see Charset#forName(String)+ * UTF-8 {@link Charset} instance to prevent repeated+ * {@link Charset#forName(String)} lookups+ * @deprecated Use {@link StandardCharsets#UTF_8} instead.*/- public static final String UTF_8 = "UTF-8";+ @Deprecated+ public static final Charset CHARSET_UTF_8 = StandardCharsets.UTF_8;/**- * UTF-8 {@link Charset} instance to prevent repeated- * {@link Charset#forName(String)} lookups+ * UTF-8 charset string.+ * <p>Where possible, use {@link StandardCharsets#UTF_8} instead,+ * as using the String constant may slow things down.+ * @see StandardCharsets#UTF_8*/- public static final Charset CHARSET_UTF_8 = Charset.forName("UTF-8");+ public static final String UTF_8 = StandardCharsets.UTF_8.name();+private IOUtils() {} // no instance/**diff --git a/lucene/core/src/java/org/apache/lucene/util/SPIClassIterator.java b/lucene/core/src/java/org/apache/lucene/util/SPIClassIterator.javaindex 764713c88a6..5ea20c4aaeb 100644--- a/lucene/core/src/java/org/apache/lucene/util/SPIClassIterator.java+++ b/lucene/core/src/java/org/apache/lucene/util/SPIClassIterator.java@@ -22,6 +22,7 @@ import java.io.InputStream;import java.io.BufferedReader;import java.io.InputStreamReader;import java.net.URL;+import java.nio.charset.StandardCharsets;import java.util.ArrayList;import java.util.Collections;import java.util.Enumeration;@@ -91,7 +92,7 @@ public final class SPIClassIterator<S> implements Iterator<Class<? extends S>> {final InputStream in = url.openStream();IOException priorE = null;try {- final BufferedReader reader = new BufferedReader(new InputStreamReader(in, IOUtils.CHARSET_UTF_8));+ final BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));String line;while ((line = reader.readLine()) != null) {final int pos = line.indexOf('#');diff --git a/lucene/core/src/java/org/apache/lucene/util/UnicodeUtil.java b/lucene/core/src/java/org/apache/lucene/util/UnicodeUtil.javaindex 70f5408781a..cbf54242a23 100644--- a/lucene/core/src/java/org/apache/lucene/util/UnicodeUtil.java+++ b/lucene/core/src/java/org/apache/lucene/util/UnicodeUtil.java@@ -1,5 +1,7 @@package org.apache.lucene.util;+import java.nio.charset.StandardCharsets;+/** Licensed to the Apache Software Foundation (ASF) under one or more* contributor license agreements. See the NOTICE file distributed with@@ -88,7 +90,7 @@ package org.apache.lucene.util;/*** Class to encode java's UTF16 char[] into UTF8 byte[]* without always allocating a new byte[] as- * String.getBytes("UTF-8") does.+ * String.getBytes(StandardCharsets.UTF_8) does.** @lucene.internal*/diff --git a/lucene/core/src/java/org/apache/lucene/util/fst/FST.java b/lucene/core/src/java/org/apache/lucene/util/fst/FST.javaindex f5977e00db6..63b535b681f 100644--- a/lucene/core/src/java/org/apache/lucene/util/fst/FST.java+++ b/lucene/core/src/java/org/apache/lucene/util/fst/FST.java@@ -25,6 +25,7 @@ import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;+import java.nio.charset.StandardCharsets;import java.util.HashMap;import java.util.Map;@@ -379,7 +380,7 @@ public final class FST<T> {/*if (bytes.length == 665) {- Writer w = new OutputStreamWriter(new FileOutputStream("out.dot"), "UTF-8");+ Writer w = new OutputStreamWriter(new FileOutputStream("out.dot"), StandardCharsets.UTF_8);Util.toDot(this, w, false, false);w.close();System.out.println("Wrote FST to out.dot");diff --git a/lucene/core/src/test/org/apache/lucene/codecs/compressing/AbstractTestLZ4CompressionMode.java b/lucene/core/src/test/org/apache/lucene/codecs/compressing/AbstractTestLZ4CompressionMode.javaindex c7978fdb92b..1cfdb446227 100644--- a/lucene/core/src/test/org/apache/lucene/codecs/compressing/AbstractTestLZ4CompressionMode.java+++ b/lucene/core/src/test/org/apache/lucene/codecs/compressing/AbstractTestLZ4CompressionMode.java@@ -18,6 +18,7 @@ package org.apache.lucene.codecs.compressing;*/import java.io.IOException;+import java.nio.charset.StandardCharsets;import com.carrotsearch.randomizedtesting.generators.RandomInts;@@ -81,7 +82,7 @@ public abstract class AbstractTestLZ4CompressionMode extends AbstractTestComprespublic void testShortLiteralsAndMatchs() throws IOException {// literals and matchs lengths <= 15- final byte[] decompressed = "1234562345673456745678910123".getBytes("UTF-8");+ final byte[] decompressed = "1234562345673456745678910123".getBytes(StandardCharsets.UTF_8);test(decompressed);}diff --git a/lucene/core/src/test/org/apache/lucene/document/TestBinaryDocument.java b/lucene/core/src/test/org/apache/lucene/document/TestBinaryDocument.javaindex c001f82306b..5819adcc1ca 100644--- a/lucene/core/src/test/org/apache/lucene/document/TestBinaryDocument.java+++ b/lucene/core/src/test/org/apache/lucene/document/TestBinaryDocument.java@@ -1,5 +1,7 @@package org.apache.lucene.document;+import java.nio.charset.StandardCharsets;+import org.apache.lucene.index.IndexReader;import org.apache.lucene.index.IndexableField;import org.apache.lucene.index.RandomIndexWriter;@@ -38,7 +40,7 @@ public class TestBinaryDocument extends LuceneTestCase {{FieldType ft = new FieldType();ft.setStored(true);- StoredField binaryFldStored = new StoredField("binaryStored", binaryValStored.getBytes("UTF-8"));+ StoredField binaryFldStored = new StoredField("binaryStored", binaryValStored.getBytes(StandardCharsets.UTF_8));Field stringFldStored = new Field("stringStored", binaryValStored, ft);Document doc = new Document();@@ -63,7 +65,7 @@ public class TestBinaryDocument extends LuceneTestCase {/** fetch the binary stored field and compare it's content with the original one */BytesRef bytes = docFromReader.getBinaryValue("binaryStored");assertNotNull(bytes);- String binaryFldStoredTest = new String(bytes.bytes, bytes.offset, bytes.length, "UTF-8");+ String binaryFldStoredTest = new String(bytes.bytes, bytes.offset, bytes.length, StandardCharsets.UTF_8);assertTrue(binaryFldStoredTest.equals(binaryValStored));/** fetch the string field and compare it's content with the original one */@@ -76,7 +78,7 @@ public class TestBinaryDocument extends LuceneTestCase {}public void testCompressionTools() throws Exception {- StoredField binaryFldCompressed = new StoredField("binaryCompressed", CompressionTools.compress(binaryValCompressed.getBytes("UTF-8")));+ StoredField binaryFldCompressed = new StoredField("binaryCompressed", CompressionTools.compress(binaryValCompressed.getBytes(StandardCharsets.UTF_8)));StoredField stringFldCompressed = new StoredField("stringCompressed", CompressionTools.compressString(binaryValCompressed));Document doc = new Document();@@ -95,7 +97,7 @@ public class TestBinaryDocument extends LuceneTestCase {assertTrue(docFromReader != null);/** fetch the binary compressed field and compare it's content with the original one */- String binaryFldCompressedTest = new String(CompressionTools.decompress(docFromReader.getBinaryValue("binaryCompressed")), "UTF-8");+ String binaryFldCompressedTest = new String(CompressionTools.decompress(docFromReader.getBinaryValue("binaryCompressed")), StandardCharsets.UTF_8);assertTrue(binaryFldCompressedTest.equals(binaryValCompressed));assertTrue(CompressionTools.decompressString(docFromReader.getBinaryValue("stringCompressed")).equals(binaryValCompressed));diff --git a/lucene/core/src/test/org/apache/lucene/document/TestDocument.java b/lucene/core/src/test/org/apache/lucene/document/TestDocument.javaindex e9c9e5be9a7..2d5d7592a94 100644--- a/lucene/core/src/test/org/apache/lucene/document/TestDocument.java+++ b/lucene/core/src/test/org/apache/lucene/document/TestDocument.java@@ -19,6 +19,7 @@ package org.apache.lucene.document;import java.io.IOException;import java.io.StringReader;+import java.nio.charset.StandardCharsets;import java.util.List;import org.apache.lucene.analysis.MockTokenizer;@@ -53,8 +54,8 @@ public class TestDocument extends LuceneTestCase {FieldType ft = new FieldType();ft.setStored(true);Field stringFld = new Field("string", binaryVal, ft);- StoredField binaryFld = new StoredField("binary", binaryVal.getBytes("UTF-8"));- StoredField binaryFld2 = new StoredField("binary", binaryVal2.getBytes("UTF-8"));+ StoredField binaryFld = new StoredField("binary", binaryVal.getBytes(StandardCharsets.UTF_8));+ StoredField binaryFld2 = new StoredField("binary", binaryVal2.getBytes(StandardCharsets.UTF_8));doc.add(stringFld);doc.add(binaryFld);diff --git a/lucene/core/src/test/org/apache/lucene/document/TestField.java b/lucene/core/src/test/org/apache/lucene/document/TestField.javaindex 2417c65069b..62be66aa8ce 100644--- a/lucene/core/src/test/org/apache/lucene/document/TestField.java+++ b/lucene/core/src/test/org/apache/lucene/document/TestField.java@@ -18,6 +18,8 @@ package org.apache.lucene.document;*/import java.io.StringReader;+import java.nio.charset.StandardCharsets;+import org.apache.lucene.analysis.CannedTokenStream;import org.apache.lucene.analysis.Token;import org.apache.lucene.util.BytesRef;@@ -184,7 +186,7 @@ public class TestField extends LuceneTestCase {trySetBoost(field);trySetByteValue(field);- field.setBytesValue("fubar".getBytes("UTF-8"));+ field.setBytesValue("fubar".getBytes(StandardCharsets.UTF_8));field.setBytesValue(new BytesRef("baz"));trySetDoubleValue(field);trySetIntValue(field);@@ -203,7 +205,7 @@ public class TestField extends LuceneTestCase {trySetBoost(field);trySetByteValue(field);- field.setBytesValue("fubar".getBytes("UTF-8"));+ field.setBytesValue("fubar".getBytes(StandardCharsets.UTF_8));field.setBytesValue(new BytesRef("baz"));trySetDoubleValue(field);trySetIntValue(field);@@ -294,15 +296,15 @@ public class TestField extends LuceneTestCase {public void testStoredFieldBytes() throws Exception {Field fields[] = new Field[] {- new StoredField("foo", "bar".getBytes("UTF-8")),- new StoredField("foo", "bar".getBytes("UTF-8"), 0, 3),+ new StoredField("foo", "bar".getBytes(StandardCharsets.UTF_8)),+ new StoredField("foo", "bar".getBytes(StandardCharsets.UTF_8), 0, 3),new StoredField("foo", new BytesRef("bar")),};for (Field field : fields) {trySetBoost(field);trySetByteValue(field);- field.setBytesValue("baz".getBytes("UTF-8"));+ field.setBytesValue("baz".getBytes(StandardCharsets.UTF_8));field.setBytesValue(new BytesRef("baz"));trySetDoubleValue(field);trySetIntValue(field);diff --git a/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java b/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.javaindex efd759f5229..43915b11750 100644--- a/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java+++ b/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java@@ -60,6 +60,7 @@ import org.apache.lucene.store.SimpleFSDirectory;import org.apache.lucene.util.Bits;import org.apache.lucene.util.BytesRef;import org.apache.lucene.util.Constants;+import org.apache.lucene.util.IOUtils;import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;import org.apache.lucene.util.StringHelper;@@ -292,10 +293,10 @@ public class TestBackwardsCompatibility extends LuceneTestCase {ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);CheckIndex checker = new CheckIndex(dir);- checker.setInfoStream(new PrintStream(bos, false, "UTF-8"));+ checker.setInfoStream(new PrintStream(bos, false, IOUtils.UTF_8));CheckIndex.Status indexStatus = checker.checkIndex();assertFalse(indexStatus.clean);- assertTrue(bos.toString("UTF-8").contains(IndexFormatTooOldException.class.getName()));+ assertTrue(bos.toString(IOUtils.UTF_8).contains(IndexFormatTooOldException.class.getName()));dir.close();TestUtil.rmDir(oldIndxeDir);diff --git a/lucene/core/src/test/org/apache/lucene/index/TestCheckIndex.java b/lucene/core/src/test/org/apache/lucene/index/TestCheckIndex.javaindex 9d13b1aebbe..67b719e7fea 100644--- a/lucene/core/src/test/org/apache/lucene/index/TestCheckIndex.java+++ b/lucene/core/src/test/org/apache/lucene/index/TestCheckIndex.java@@ -20,9 +20,11 @@ package org.apache.lucene.index;import java.io.IOException;import java.io.ByteArrayOutputStream;import java.io.PrintStream;+import java.nio.charset.StandardCharsets;import java.util.List;import java.util.ArrayList;+import org.apache.lucene.util.IOUtils;import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.store.Directory;import org.apache.lucene.analysis.CannedTokenStream;@@ -54,12 +56,12 @@ public class TestCheckIndex extends LuceneTestCase {ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);CheckIndex checker = new CheckIndex(dir);- checker.setInfoStream(new PrintStream(bos, false, "UTF-8"));+ checker.setInfoStream(new PrintStream(bos, false, IOUtils.UTF_8));if (VERBOSE) checker.setInfoStream(System.out);CheckIndex.Status indexStatus = checker.checkIndex();if (indexStatus.clean == false) {System.out.println("CheckIndex failed");- System.out.println(bos.toString("UTF-8"));+ System.out.println(bos.toString(IOUtils.UTF_8));fail();}diff --git a/lucene/core/src/test/org/apache/lucene/index/TestDoc.java b/lucene/core/src/test/org/apache/lucene/index/TestDoc.javaindex 1ef079e6da2..f12673a531e 100644--- a/lucene/core/src/test/org/apache/lucene/index/TestDoc.java+++ b/lucene/core/src/test/org/apache/lucene/index/TestDoc.java@@ -25,6 +25,7 @@ import java.io.OutputStreamWriter;import java.io.PrintWriter;import java.io.StringWriter;import java.io.Writer;+import java.nio.charset.StandardCharsets;import java.util.Arrays;import java.util.Collection;import java.util.HashSet;@@ -89,7 +90,7 @@ public class TestDoc extends LuceneTestCase {File f = new File(workDir, name);if (f.exists()) f.delete();- fw = new OutputStreamWriter(new FileOutputStream(f), "UTF-8");+ fw = new OutputStreamWriter(new FileOutputStream(f), StandardCharsets.UTF_8);pw = new PrintWriter(fw);pw.println(text);return f;@@ -200,7 +201,7 @@ public class TestDoc extends LuceneTestCase {{File file = new File(workDir, fileName);Document doc = new Document();- InputStreamReader is = new InputStreamReader(new FileInputStream(file), "UTF-8");+ InputStreamReader is = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8);doc.add(new TextField("contents", is));writer.addDocument(doc);writer.commit();diff --git a/lucene/core/src/test/org/apache/lucene/index/TestDocInverterPerFieldErrorInfo.java b/lucene/core/src/test/org/apache/lucene/index/TestDocInverterPerFieldErrorInfo.javaindex 3df1ebc7db4..c2963c97e68 100644--- a/lucene/core/src/test/org/apache/lucene/index/TestDocInverterPerFieldErrorInfo.java+++ b/lucene/core/src/test/org/apache/lucene/index/TestDocInverterPerFieldErrorInfo.java@@ -26,6 +26,7 @@ import org.apache.lucene.document.Document;import org.apache.lucene.document.FieldType;import org.apache.lucene.document.TextField;import org.apache.lucene.store.Directory;+import org.apache.lucene.util.IOUtils;import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.util.PrintStreamInfoStream;import org.junit.Test;@@ -70,7 +71,7 @@ public class TestDocInverterPerFieldErrorInfo extends LuceneTestCase {IndexWriter writer;IndexWriterConfig c = new IndexWriterConfig(TEST_VERSION_CURRENT, new ThrowingAnalyzer());final ByteArrayOutputStream infoBytes = new ByteArrayOutputStream();- PrintStream infoPrintStream = new PrintStream(infoBytes, true, "utf-8");+ PrintStream infoPrintStream = new PrintStream(infoBytes, true, IOUtils.UTF_8);PrintStreamInfoStream printStreamInfoStream = new PrintStreamInfoStream(infoPrintStream);c.setInfoStream(printStreamInfoStream);writer = new IndexWriter(dir, c);@@ -81,7 +82,7 @@ public class TestDocInverterPerFieldErrorInfo extends LuceneTestCase {fail("Failed to fail.");} catch(BadNews badNews) {infoPrintStream.flush();- String infoStream = new String(infoBytes.toByteArray(), "utf-8");+ String infoStream = new String(infoBytes.toByteArray(), IOUtils.UTF_8);assertTrue(infoStream.contains("distinctiveFieldName"));}@@ -95,7 +96,7 @@ public class TestDocInverterPerFieldErrorInfo extends LuceneTestCase {IndexWriter writer;IndexWriterConfig c = new IndexWriterConfig(TEST_VERSION_CURRENT, new ThrowingAnalyzer());final ByteArrayOutputStream infoBytes = new ByteArrayOutputStream();- PrintStream infoPrintStream = new PrintStream(infoBytes, true, "utf-8");+ PrintStream infoPrintStream = new PrintStream(infoBytes, true, IOUtils.UTF_8);PrintStreamInfoStream printStreamInfoStream = new PrintStreamInfoStream(infoPrintStream);c.setInfoStream(printStreamInfoStream);writer = new IndexWriter(dir, c);@@ -107,7 +108,7 @@ public class TestDocInverterPerFieldErrorInfo extends LuceneTestCase {fail("Unwanted exception");}infoPrintStream.flush();- String infoStream = new String(infoBytes.toByteArray(), "utf-8");+ String infoStream = new String(infoBytes.toByteArray(), IOUtils.UTF_8);assertFalse(infoStream.contains("boringFieldName"));writer.close();diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterDelete.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterDelete.javaindex caec565055b..f5e3dbf3e3f 100644--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterDelete.java+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterDelete.java@@ -20,6 +20,7 @@ package org.apache.lucene.index;import java.io.ByteArrayOutputStream;import java.io.IOException;import java.io.PrintStream;+import java.nio.charset.StandardCharsets;import java.util.ArrayList;import java.util.Collections;import java.util.List;@@ -43,6 +44,7 @@ import org.apache.lucene.search.TermQuery;import org.apache.lucene.store.Directory;import org.apache.lucene.store.MockDirectoryWrapper;import org.apache.lucene.store.RAMDirectory;+import org.apache.lucene.util.IOUtils;import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.util.TestUtil;@@ -1173,10 +1175,10 @@ public class TestIndexWriterDelete extends LuceneTestCase {ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);CheckIndex checker = new CheckIndex(dir);- checker.setInfoStream(new PrintStream(bos, false, "UTF-8"), false);+ checker.setInfoStream(new PrintStream(bos, false, IOUtils.UTF_8), false);CheckIndex.Status indexStatus = checker.checkIndex(null);assertTrue(indexStatus.clean);- String s = bos.toString("UTF-8");+ String s = bos.toString(IOUtils.UTF_8);// Segment should have deletions:assertTrue(s.contains("has deletions"));@@ -1185,10 +1187,10 @@ public class TestIndexWriterDelete extends LuceneTestCase {w.close();bos = new ByteArrayOutputStream(1024);- checker.setInfoStream(new PrintStream(bos, false, "UTF-8"), false);+ checker.setInfoStream(new PrintStream(bos, false, IOUtils.UTF_8), false);indexStatus = checker.checkIndex(null);assertTrue(indexStatus.clean);- s = bos.toString("UTF-8");+ s = bos.toString(IOUtils.UTF_8);assertFalse(s.contains("has deletions"));dir.close();}diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterUnicode.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterUnicode.javaindex be3170d8660..1c202cfa7bd 100644--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterUnicode.java+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterUnicode.java@@ -18,6 +18,7 @@ package org.apache.lucene.index;*/import java.io.IOException;+import java.nio.charset.StandardCharsets;import java.util.HashSet;import java.util.Iterator;import java.util.Random;@@ -181,7 +182,7 @@ public class TestIndexWriterUnicode extends LuceneTestCase {UnicodeUtil.UTF16toUTF8(buffer, 0, 20, utf8);if (!hasIllegal) {- byte[] b = new String(buffer, 0, 20).getBytes("UTF-8");+ byte[] b = new String(buffer, 0, 20).getBytes(StandardCharsets.UTF_8);assertEquals(b.length, utf8.length);for(int i=0;i<b.length;i++)assertEquals(b[i], utf8.bytes[i]);@@ -217,13 +218,13 @@ public class TestIndexWriterUnicode extends LuceneTestCase {UnicodeUtil.UTF16toUTF8(chars, 0, len, utf8);String s1 = new String(chars, 0, len);- String s2 = new String(utf8.bytes, 0, utf8.length, "UTF-8");+ String s2 = new String(utf8.bytes, 0, utf8.length, StandardCharsets.UTF_8);assertEquals("codepoint " + ch, s1, s2);UnicodeUtil.UTF8toUTF16(utf8.bytes, 0, utf8.length, utf16);assertEquals("codepoint " + ch, s1, new String(utf16.chars, 0, utf16.length));- byte[] b = s1.getBytes("UTF-8");+ byte[] b = s1.getBytes(StandardCharsets.UTF_8);assertEquals(utf8.length, b.length);for(int j=0;j<utf8.length;j++)assertEquals(utf8.bytes[j], b[j]);diff --git a/lucene/core/src/test/org/apache/lucene/index/TestPayloads.java b/lucene/core/src/test/org/apache/lucene/index/TestPayloads.javaindex 9e21e7cbce9..e6c1591d20a 100644--- a/lucene/core/src/test/org/apache/lucene/index/TestPayloads.java+++ b/lucene/core/src/test/org/apache/lucene/index/TestPayloads.java@@ -20,6 +20,7 @@ package org.apache.lucene.index;import java.io.IOException;import java.io.StringReader;import java.nio.charset.Charset;+import java.nio.charset.StandardCharsets;import java.util.ArrayList;import java.util.HashMap;import java.util.List;@@ -72,7 +73,7 @@ public class TestPayloads extends LuceneTestCase {// enabled in only some documentsd.add(newTextField("f3", "This field has payloads in some docs", Field.Store.NO));// only add payload data for field f2- analyzer.setPayloadData("f2", "somedata".getBytes("UTF-8"), 0, 1);+ analyzer.setPayloadData("f2", "somedata".getBytes(StandardCharsets.UTF_8), 0, 1);writer.addDocument(d);// flushwriter.close();@@ -95,8 +96,8 @@ public class TestPayloads extends LuceneTestCase {d.add(newTextField("f2", "This field has payloads in all docs", Field.Store.NO));d.add(newTextField("f3", "This field has payloads in some docs", Field.Store.NO));// add payload data for field f2 and f3- analyzer.setPayloadData("f2", "somedata".getBytes("UTF-8"), 0, 1);- analyzer.setPayloadData("f3", "somedata".getBytes("UTF-8"), 0, 3);+ analyzer.setPayloadData("f2", "somedata".getBytes(StandardCharsets.UTF_8), 0, 1);+ analyzer.setPayloadData("f3", "somedata".getBytes(StandardCharsets.UTF_8), 0, 3);writer.addDocument(d);// force merge@@ -297,7 +298,8 @@ public class TestPayloads extends LuceneTestCase {}- static final Charset utf8 = Charset.forName("UTF-8");+ static final Charset utf8 = StandardCharsets.UTF_8;+private void generateRandomData(byte[] data) {// this test needs the random data to be valid unicodeString s = TestUtil.randomFixedByteLengthUnicodeString(random(), data.length);diff --git a/lucene/core/src/test/org/apache/lucene/search/TestFieldCache.java b/lucene/core/src/test/org/apache/lucene/search/TestFieldCache.javaindex f78f6f84bf9..e490518412e 100644--- a/lucene/core/src/test/org/apache/lucene/search/TestFieldCache.java+++ b/lucene/core/src/test/org/apache/lucene/search/TestFieldCache.java@@ -60,6 +60,7 @@ import org.apache.lucene.search.FieldCache.Longs;import org.apache.lucene.store.Directory;import org.apache.lucene.util.Bits;import org.apache.lucene.util.BytesRef;+import org.apache.lucene.util.IOUtils;import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.util.NumericUtils;import org.apache.lucene.util.TestUtil;@@ -139,7 +140,7 @@ public class TestFieldCache extends LuceneTestCase {try {FieldCache cache = FieldCache.DEFAULT;ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);- cache.setInfoStream(new PrintStream(bos, false, "UTF-8"));+ cache.setInfoStream(new PrintStream(bos, false, IOUtils.UTF_8));cache.getDoubles(reader, "theDouble", false);cache.getFloats(reader, "theDouble", new FieldCache.FloatParser() {@Override@@ -151,7 +152,7 @@ public class TestFieldCache extends LuceneTestCase {return NumericUtils.sortableIntToFloat((int) NumericUtils.prefixCodedToLong(term));}}, false);- assertTrue(bos.toString("UTF-8").indexOf("WARNING") != -1);+ assertTrue(bos.toString(IOUtils.UTF_8).indexOf("WARNING") != -1);} finally {FieldCache.DEFAULT.purgeAllCaches();}diff --git a/lucene/core/src/test/org/apache/lucene/search/TestPositionIncrement.java b/lucene/core/src/test/org/apache/lucene/search/TestPositionIncrement.javaindex 123b256ba70..1e918d56d3c 100644--- a/lucene/core/src/test/org/apache/lucene/search/TestPositionIncrement.java+++ b/lucene/core/src/test/org/apache/lucene/search/TestPositionIncrement.java@@ -20,6 +20,7 @@ package org.apache.lucene.search;import java.io.IOException;import java.io.Reader;import java.io.StringReader;+import java.nio.charset.StandardCharsets;import java.util.Collection;import org.apache.lucene.analysis.*;@@ -249,7 +250,7 @@ public class TestPositionIncrement extends LuceneTestCase {for (byte[] bytes : payloads) {count++;if (VERBOSE) {- System.out.println(" payload: " + new String(bytes, "UTF-8"));+ System.out.println(" payload: " + new String(bytes, StandardCharsets.UTF_8));}}}@@ -276,7 +277,7 @@ public class TestPositionIncrement extends LuceneTestCase {Collection<byte[]> pls = psu.getPayloadsForQuery(snq);count = pls.size();for (byte[] bytes : pls) {- String s = new String(bytes, "UTF-8");+ String s = new String(bytes, StandardCharsets.UTF_8);//System.out.println(s);sawZero |= s.equals("pos: 0");}diff --git a/lucene/core/src/test/org/apache/lucene/search/spans/TestBasics.java b/lucene/core/src/test/org/apache/lucene/search/spans/TestBasics.javaindex 53314e84b42..d5ca61b430e 100644--- a/lucene/core/src/test/org/apache/lucene/search/spans/TestBasics.java+++ b/lucene/core/src/test/org/apache/lucene/search/spans/TestBasics.java@@ -18,6 +18,7 @@ package org.apache.lucene.search.spans;*/import java.io.IOException;+import java.nio.charset.StandardCharsets;import java.util.ArrayList;import java.util.Collection;import java.util.Collections;@@ -80,7 +81,7 @@ public class TestBasics extends LuceneTestCase {@Overridepublic boolean incrementToken() throws IOException {if (input.incrementToken()) {- payloadAttr.setPayload(new BytesRef(("pos: " + pos).getBytes("UTF-8")));+ payloadAttr.setPayload(new BytesRef(("pos: " + pos).getBytes(StandardCharsets.UTF_8)));pos++;return true;} else {@@ -482,7 +483,7 @@ public class TestBasics extends LuceneTestCase {@Testpublic void testSpanPayloadCheck() throws Exception {SpanTermQuery term1 = new SpanTermQuery(new Term("field", "five"));- BytesRef pay = new BytesRef(("pos: " + 5).getBytes("UTF-8"));+ BytesRef pay = new BytesRef(("pos: " + 5).getBytes(StandardCharsets.UTF_8));SpanQuery query = new SpanPayloadCheckQuery(term1, Collections.singletonList(pay.bytes));checkHits(query, new int[]{1125, 1135, 1145, 1155, 1165, 1175, 1185, 1195, 1225, 1235, 1245, 1255, 1265, 1275, 1285, 1295, 1325, 1335, 1345, 1355, 1365, 1375, 1385, 1395, 1425, 1435, 1445, 1455, 1465, 1475, 1485, 1495, 1525, 1535, 1545, 1555, 1565, 1575, 1585, 1595, 1625, 1635, 1645, 1655, 1665, 1675, 1685, 1695, 1725, 1735, 1745, 1755, 1765, 1775, 1785, 1795, 1825, 1835, 1845, 1855, 1865, 1875, 1885, 1895, 1925, 1935, 1945, 1955, 1965, 1975, 1985, 1995});@@ -497,8 +498,8 @@ public class TestBasics extends LuceneTestCase {clauses[0] = term1;clauses[1] = term2;snq = new SpanNearQuery(clauses, 0, true);- pay = new BytesRef(("pos: " + 0).getBytes("UTF-8"));- pay2 = new BytesRef(("pos: " + 1).getBytes("UTF-8"));+ pay = new BytesRef(("pos: " + 0).getBytes(StandardCharsets.UTF_8));+ pay2 = new BytesRef(("pos: " + 1).getBytes(StandardCharsets.UTF_8));list = new ArrayList<>();list.add(pay.bytes);list.add(pay2.bytes);@@ -510,9 +511,9 @@ public class TestBasics extends LuceneTestCase {clauses[1] = term2;clauses[2] = new SpanTermQuery(new Term("field", "five"));snq = new SpanNearQuery(clauses, 0, true);- pay = new BytesRef(("pos: " + 0).getBytes("UTF-8"));- pay2 = new BytesRef(("pos: " + 1).getBytes("UTF-8"));- BytesRef pay3 = new BytesRef(("pos: " + 2).getBytes("UTF-8"));+ pay = new BytesRef(("pos: " + 0).getBytes(StandardCharsets.UTF_8));+ pay2 = new BytesRef(("pos: " + 1).getBytes(StandardCharsets.UTF_8));+ BytesRef pay3 = new BytesRef(("pos: " + 2).getBytes(StandardCharsets.UTF_8));list = new ArrayList<>();list.add(pay.bytes);list.add(pay2.bytes);@@ -541,10 +542,10 @@ public class TestBasics extends LuceneTestCase {checkHits(query, new int[]{1103, 1203,1303,1403,1503,1603,1703,1803,1903});Collection<byte[]> payloads = new ArrayList<>();- BytesRef pay = new BytesRef(("pos: " + 0).getBytes("UTF-8"));- BytesRef pay2 = new BytesRef(("pos: " + 1).getBytes("UTF-8"));- BytesRef pay3 = new BytesRef(("pos: " + 3).getBytes("UTF-8"));- BytesRef pay4 = new BytesRef(("pos: " + 4).getBytes("UTF-8"));+ BytesRef pay = new BytesRef(("pos: " + 0).getBytes(StandardCharsets.UTF_8));+ BytesRef pay2 = new BytesRef(("pos: " + 1).getBytes(StandardCharsets.UTF_8));+ BytesRef pay3 = new BytesRef(("pos: " + 3).getBytes(StandardCharsets.UTF_8));+ BytesRef pay4 = new BytesRef(("pos: " + 4).getBytes(StandardCharsets.UTF_8));payloads.add(pay.bytes);payloads.add(pay2.bytes);payloads.add(pay3.bytes);diff --git a/lucene/core/src/test/org/apache/lucene/search/spans/TestPayloadSpans.java b/lucene/core/src/test/org/apache/lucene/search/spans/TestPayloadSpans.javaindex 485430b5ed7..ecd16c7d132 100644--- a/lucene/core/src/test/org/apache/lucene/search/spans/TestPayloadSpans.java+++ b/lucene/core/src/test/org/apache/lucene/search/spans/TestPayloadSpans.java@@ -19,6 +19,7 @@ package org.apache.lucene.search.spans;import java.io.IOException;import java.io.Reader;import java.io.StringReader;+import java.nio.charset.StandardCharsets;import java.util.Collection;import java.util.HashSet;import java.util.Set;@@ -276,7 +277,7 @@ public class TestPayloadSpans extends LuceneTestCase {Collection<byte[]> payloads = spans.getPayload();for (final byte [] payload : payloads) {- payloadSet.add(new String(payload, "UTF-8"));+ payloadSet.add(new String(payload, StandardCharsets.UTF_8));}}}@@ -311,7 +312,7 @@ public class TestPayloadSpans extends LuceneTestCase {while (spans.next()) {Collection<byte[]> payloads = spans.getPayload();for (final byte[] payload : payloads) {- payloadSet.add(new String(payload, "UTF-8"));+ payloadSet.add(new String(payload, StandardCharsets.UTF_8));}}}@@ -347,7 +348,7 @@ public class TestPayloadSpans extends LuceneTestCase {Collection<byte[]> payloads = spans.getPayload();for (final byte [] payload : payloads) {- payloadSet.add(new String(payload, "UTF-8"));+ payloadSet.add(new String(payload, StandardCharsets.UTF_8));}}}@@ -382,7 +383,7 @@ public class TestPayloadSpans extends LuceneTestCase {if(VERBOSE) {System.out.println("Num payloads:" + payloads.size());for (final byte [] bytes : payloads) {- System.out.println(new String(bytes, "UTF-8"));+ System.out.println(new String(bytes, StandardCharsets.UTF_8));}}reader.close();@@ -455,7 +456,7 @@ public class TestPayloadSpans extends LuceneTestCase {System.out.println("payloads for span:" + payload.size());for (final byte [] bytes : payload) {System.out.println("doc:" + spans.doc() + " s:" + spans.start() + " e:" + spans.end() + " "- + new String(bytes, "UTF-8"));+ + new String(bytes, StandardCharsets.UTF_8));}}diff --git a/lucene/core/src/test/org/apache/lucene/util/TestOfflineSorter.java b/lucene/core/src/test/org/apache/lucene/util/TestOfflineSorter.javaindex 273f59f446b..fc704cbb714 100644--- a/lucene/core/src/test/org/apache/lucene/util/TestOfflineSorter.java+++ b/lucene/core/src/test/org/apache/lucene/util/TestOfflineSorter.java@@ -21,6 +21,7 @@ import java.io.DataInputStream;import java.io.File;import java.io.FileInputStream;import java.io.IOException;+import java.nio.charset.StandardCharsets;import java.util.ArrayList;import java.util.Arrays;import java.util.Comparator;@@ -60,7 +61,7 @@ public class TestOfflineSorter extends LuceneTestCase {public void testSingleLine() throws Exception {checkSort(new OfflineSorter(), new byte [][] {- "Single line only.".getBytes("UTF-8")+ "Single line only.".getBytes(StandardCharsets.UTF_8)});}diff --git a/lucene/core/src/test/org/apache/lucene/util/automaton/TestDeterminizeLexicon.java b/lucene/core/src/test/org/apache/lucene/util/automaton/TestDeterminizeLexicon.javaindex e435fe6f6ae..be40c6c00f1 100644--- a/lucene/core/src/test/org/apache/lucene/util/automaton/TestDeterminizeLexicon.java+++ b/lucene/core/src/test/org/apache/lucene/util/automaton/TestDeterminizeLexicon.java@@ -17,6 +17,7 @@ package org.apache.lucene.util.automaton;* limitations under the License.*/+import java.nio.charset.StandardCharsets;import java.util.ArrayList;import java.util.Collections;import java.util.List;@@ -56,7 +57,7 @@ public class TestDeterminizeLexicon extends LuceneTestCase {}final ByteRunAutomaton lexByte = new ByteRunAutomaton(lex);for (String s : terms) {- byte bytes[] = s.getBytes("UTF-8");+ byte bytes[] = s.getBytes(StandardCharsets.UTF_8);assertTrue(lexByte.run(bytes, 0, bytes.length));}}diff --git a/lucene/core/src/test/org/apache/lucene/util/automaton/TestUTF32ToUTF8.java b/lucene/core/src/test/org/apache/lucene/util/automaton/TestUTF32ToUTF8.javaindex 68c75a1f8cb..d5faa4dfef9 100644--- a/lucene/core/src/test/org/apache/lucene/util/automaton/TestUTF32ToUTF8.java+++ b/lucene/core/src/test/org/apache/lucene/util/automaton/TestUTF32ToUTF8.java@@ -22,6 +22,7 @@ import org.apache.lucene.util.TestUtil;import org.apache.lucene.util.BytesRef;import org.apache.lucene.util.UnicodeUtil;+import java.nio.charset.StandardCharsets;import java.util.Random;public class TestUTF32ToUTF8 extends LuceneTestCase {@@ -184,7 +185,7 @@ public class TestUTF32ToUTF8 extends LuceneTestCase {assertTrue(cra.run(input));- byte[] bytes = input.getBytes("UTF-8");+ byte[] bytes = input.getBytes(StandardCharsets.UTF_8);assertTrue(bra.run(bytes, 0, bytes.length)); // this one fails!}@@ -197,7 +198,7 @@ public class TestUTF32ToUTF8 extends LuceneTestCase {assertTrue(cra.run(input));- byte[] bytes = input.getBytes("UTF-8");+ byte[] bytes = input.getBytes(StandardCharsets.UTF_8);assertTrue(bra.run(bytes, 0, bytes.length));}@@ -232,7 +233,7 @@ public class TestUTF32ToUTF8 extends LuceneTestCase {throw e;}}- byte bytes[] = string.getBytes("UTF-8");+ byte bytes[] = string.getBytes(StandardCharsets.UTF_8);assertEquals(cra.run(string), bra.run(bytes, 0, bytes.length));}}diff --git a/lucene/core/src/test/org/apache/lucene/util/fst/TestFSTs.java b/lucene/core/src/test/org/apache/lucene/util/fst/TestFSTs.javaindex 0b6d6188a10..27bf2cc5048 100644--- a/lucene/core/src/test/org/apache/lucene/util/fst/TestFSTs.java+++ b/lucene/core/src/test/org/apache/lucene/util/fst/TestFSTs.java@@ -63,6 +63,7 @@ import java.io.InputStreamReader;import java.io.OutputStreamWriter;import java.io.StringWriter;import java.io.Writer;+import java.nio.charset.StandardCharsets;import java.util.ArrayList;import java.util.Arrays;import java.util.Collections;@@ -474,7 +475,7 @@ public class TestFSTs extends LuceneTestCase {protected abstract T getOutput(IntsRef input, int ord) throws IOException;public void run(int limit, boolean verify, boolean verifyByOutput) throws IOException {- BufferedReader is = new BufferedReader(new InputStreamReader(new FileInputStream(wordsFileIn), "UTF-8"), 65536);+ BufferedReader is = new BufferedReader(new InputStreamReader(new FileInputStream(wordsFileIn), StandardCharsets.UTF_8), 65536);try {final IntsRef intsRef = new IntsRef(10);long tStart = System.currentTimeMillis();@@ -517,7 +518,7 @@ public class TestFSTs extends LuceneTestCase {System.out.println(ord + " terms; " + fst.getNodeCount() + " nodes; " + fst.getArcCount() + " arcs; " + fst.getArcWithOutputCount() + " arcs w/ output; tot size " + fst.sizeInBytes());if (fst.getNodeCount() < 100) {- Writer w = new OutputStreamWriter(new FileOutputStream("out.dot"), "UTF-8");+ Writer w = new OutputStreamWriter(new FileOutputStream("out.dot"), StandardCharsets.UTF_8);Util.toDot(fst, w, false, false);w.close();System.out.println("Wrote FST to out.dot");@@ -544,7 +545,7 @@ public class TestFSTs extends LuceneTestCase {while(true) {for(int iter=0;iter<2;iter++) {is.close();- is = new BufferedReader(new InputStreamReader(new FileInputStream(wordsFileIn), "UTF-8"), 65536);+ is = new BufferedReader(new InputStreamReader(new FileInputStream(wordsFileIn), StandardCharsets.UTF_8), 65536);ord = 0;tStart = System.currentTimeMillis();diff --git a/lucene/core/src/test/org/apache/lucene/util/junitcompat/WithNestedTests.java b/lucene/core/src/test/org/apache/lucene/util/junitcompat/WithNestedTests.javaindex 48792f175e6..c2960b3f1e8 100644--- a/lucene/core/src/test/org/apache/lucene/util/junitcompat/WithNestedTests.java+++ b/lucene/core/src/test/org/apache/lucene/util/junitcompat/WithNestedTests.java@@ -20,8 +20,10 @@ package org.apache.lucene.util.junitcompat;import java.io.ByteArrayOutputStream;import java.io.PrintStream;import java.io.UnsupportedEncodingException;+import java.nio.charset.StandardCharsets;import java.util.List;+import org.apache.lucene.util.IOUtils;import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.util.TestRuleIgnoreAfterMaxFailures;import org.apache.lucene.util.TestRuleIgnoreTestSuites;@@ -121,9 +123,9 @@ public abstract class WithNestedTests {try {sysout = new ByteArrayOutputStream();- System.setOut(new PrintStream(sysout, true, "UTF-8"));+ System.setOut(new PrintStream(sysout, true, IOUtils.UTF_8));syserr = new ByteArrayOutputStream();- System.setErr(new PrintStream(syserr, true, "UTF-8"));+ System.setErr(new PrintStream(syserr, true, IOUtils.UTF_8));} catch (UnsupportedEncodingException e) {throw new RuntimeException(e);}@@ -146,20 +148,12 @@ public abstract class WithNestedTests {protected String getSysOut() {Assert.assertTrue(suppressOutputStreams);System.out.flush();- try {- return new String(sysout.toByteArray(), "UTF-8");- } catch (UnsupportedEncodingException e) {- throw new RuntimeException(e);- }+ return new String(sysout.toByteArray(), StandardCharsets.UTF_8);}protected String getSysErr() {Assert.assertTrue(suppressOutputStreams);System.err.flush();- try {- return new String(syserr.toByteArray(), "UTF-8");- } catch (UnsupportedEncodingException e) {- throw new RuntimeException(e);- }+ return new String(syserr.toByteArray(), StandardCharsets.UTF_8);}}diff --git a/lucene/demo/src/java/org/apache/lucene/demo/IndexFiles.java b/lucene/demo/src/java/org/apache/lucene/demo/IndexFiles.javaindex 5f1e48d66e8..cfbfc43a8ab 100644--- a/lucene/demo/src/java/org/apache/lucene/demo/IndexFiles.java+++ b/lucene/demo/src/java/org/apache/lucene/demo/IndexFiles.java@@ -38,6 +38,7 @@ import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStreamReader;+import java.nio.charset.StandardCharsets;import java.util.Date;/** Index all text files under a directory.@@ -191,7 +192,7 @@ public class IndexFiles {// so that the text of the file is tokenized and indexed, but not stored.// Note that FileReader expects the file to be in UTF-8 encoding.// If that's not the case searching for special characters will fail.- doc.add(new TextField("contents", new BufferedReader(new InputStreamReader(fis, "UTF-8"))));+ doc.add(new TextField("contents", new BufferedReader(new InputStreamReader(fis, StandardCharsets.UTF_8))));if (writer.getConfig().getOpenMode() == OpenMode.CREATE) {// New index, so we just add the document (no old document can be there):diff --git a/lucene/demo/src/java/org/apache/lucene/demo/SearchFiles.java b/lucene/demo/src/java/org/apache/lucene/demo/SearchFiles.javaindex 621ecf484c7..95b5975f4ec 100644--- a/lucene/demo/src/java/org/apache/lucene/demo/SearchFiles.java+++ b/lucene/demo/src/java/org/apache/lucene/demo/SearchFiles.java@@ -22,6 +22,7 @@ import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStreamReader;+import java.nio.charset.StandardCharsets;import java.util.Date;import org.apache.lucene.analysis.Analyzer;@@ -95,9 +96,9 @@ public class SearchFiles {BufferedReader in = null;if (queries != null) {- in = new BufferedReader(new InputStreamReader(new FileInputStream(queries), "UTF-8"));+ in = new BufferedReader(new InputStreamReader(new FileInputStream(queries), StandardCharsets.UTF_8));} else {- in = new BufferedReader(new InputStreamReader(System.in, "UTF-8"));+ in = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8));}// :Post-Release-Update-Version.LUCENE_XY:QueryParser parser = new QueryParser(Version.LUCENE_50, field, analyzer);diff --git a/lucene/demo/src/java/org/apache/lucene/demo/xmlparser/FormBasedXmlQueryDemo.java b/lucene/demo/src/java/org/apache/lucene/demo/xmlparser/FormBasedXmlQueryDemo.javaindex bda9d3f1dad..79983eab4f5 100644--- a/lucene/demo/src/java/org/apache/lucene/demo/xmlparser/FormBasedXmlQueryDemo.java+++ b/lucene/demo/src/java/org/apache/lucene/demo/xmlparser/FormBasedXmlQueryDemo.java@@ -21,9 +21,11 @@ import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;+import java.nio.charset.StandardCharsets;import java.util.Enumeration;import java.util.Properties;import java.util.StringTokenizer;+import javax.servlet.RequestDispatcher;import javax.servlet.ServletConfig;import javax.servlet.ServletException;@@ -49,7 +51,6 @@ import org.apache.lucene.search.Query;import org.apache.lucene.search.ScoreDoc;import org.apache.lucene.search.TopDocs;import org.apache.lucene.store.RAMDirectory;-import org.apache.lucene.util.IOUtils;import org.apache.lucene.util.Version;/**@@ -136,7 +137,7 @@ public class FormBasedXmlQueryDemo extends HttpServlet {IndexWriterConfig iwConfig = new IndexWriterConfig(Version.LUCENE_CURRENT, analyzer);IndexWriter writer = new IndexWriter(rd, iwConfig);InputStream dataIn = getServletContext().getResourceAsStream("/WEB-INF/data.tsv");- BufferedReader br = new BufferedReader(new InputStreamReader(dataIn, IOUtils.CHARSET_UTF_8));+ BufferedReader br = new BufferedReader(new InputStreamReader(dataIn, StandardCharsets.UTF_8));String line = br.readLine();final FieldType textNoNorms = new FieldType(TextField.TYPE_STORED);textNoNorms.setOmitNorms(true);diff --git a/lucene/expressions/src/java/org/apache/lucene/expressions/js/JavascriptCompiler.java b/lucene/expressions/src/java/org/apache/lucene/expressions/js/JavascriptCompiler.javaindex 0e3f730bb13..8137057599a 100644--- a/lucene/expressions/src/java/org/apache/lucene/expressions/js/JavascriptCompiler.java+++ b/lucene/expressions/src/java/org/apache/lucene/expressions/js/JavascriptCompiler.java@@ -22,6 +22,7 @@ import java.lang.reflect.Constructor;import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;import java.lang.reflect.Modifier;+import java.nio.charset.StandardCharsets;import java.text.ParseException;import java.util.Arrays;import java.util.Collections;@@ -503,7 +504,7 @@ public class JavascriptCompiler {try {final Properties props = new Properties();try (Reader in = IOUtils.getDecodingReader(JavascriptCompiler.class,- JavascriptCompiler.class.getSimpleName() + ".properties", IOUtils.CHARSET_UTF_8)) {+ JavascriptCompiler.class.getSimpleName() + ".properties", StandardCharsets.UTF_8)) {props.load(in);}for (final String call : props.stringPropertyNames()) {diff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetCounts.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetCounts.javaindex a63a27a6259..6f85c6ab12d 100644--- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetCounts.java+++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetCounts.java@@ -132,8 +132,8 @@ public class TestTaxonomyFacetCounts extends FacetTestCase {// Smoke test PrintTaxonomyStats:ByteArrayOutputStream bos = new ByteArrayOutputStream();- PrintTaxonomyStats.printStats(taxoReader, new PrintStream(bos, false, "UTF-8"), true);- String result = bos.toString("UTF-8");+ PrintTaxonomyStats.printStats(taxoReader, new PrintStream(bos, false, IOUtils.UTF_8), true);+ String result = bos.toString(IOUtils.UTF_8);assertTrue(result.indexOf("/Author: 4 immediate children; 5 total categories") != -1);assertTrue(result.indexOf("/Publish Date: 3 immediate children; 12 total categories") != -1);// Make sure at least a few nodes of the tree came out:diff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/writercache/TestCharBlockArray.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/writercache/TestCharBlockArray.javaindex 799df78cf23..b9e6ca15d96 100644--- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/writercache/TestCharBlockArray.java+++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/writercache/TestCharBlockArray.java@@ -8,11 +8,11 @@ import java.io.FileOutputStream;import java.nio.ByteBuffer;import java.nio.charset.CharsetDecoder;import java.nio.charset.CodingErrorAction;+import java.nio.charset.StandardCharsets;import org.apache.lucene.facet.FacetTestCase;-import org.apache.lucene.util.IOUtils;-import org.apache.lucene.util.TestUtil;import org.apache.lucene.util.TestUtil;+import org.junit.Test;/*@@ -47,7 +47,7 @@ public class TestCharBlockArray extends FacetTestCase {int size = 1 + random().nextInt(50);// This test is turning random bytes into a string,// this is asking for trouble.- CharsetDecoder decoder = IOUtils.CHARSET_UTF_8.newDecoder()+ CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder().onUnmappableCharacter(CodingErrorAction.REPLACE).onMalformedInput(CodingErrorAction.REPLACE);String s = decoder.decode(ByteBuffer.wrap(buffer, 0, size)).toString();@@ -60,7 +60,7 @@ public class TestCharBlockArray extends FacetTestCase {int size = 1 + random().nextInt(50);// This test is turning random bytes into a string,// this is asking for trouble.- CharsetDecoder decoder = IOUtils.CHARSET_UTF_8.newDecoder()+ CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder().onUnmappableCharacter(CodingErrorAction.REPLACE).onMalformedInput(CodingErrorAction.REPLACE);String s = decoder.decode(ByteBuffer.wrap(buffer, 0, size)).toString();@@ -73,7 +73,7 @@ public class TestCharBlockArray extends FacetTestCase {int size = 1 + random().nextInt(50);// This test is turning random bytes into a string,// this is asking for trouble.- CharsetDecoder decoder = IOUtils.CHARSET_UTF_8.newDecoder()+ CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder().onUnmappableCharacter(CodingErrorAction.REPLACE).onMalformedInput(CodingErrorAction.REPLACE);String s = decoder.decode(ByteBuffer.wrap(buffer, 0, size)).toString();diff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/writercache/TestCompactLabelToOrdinal.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/writercache/TestCompactLabelToOrdinal.javaindex eddcb1b492b..dd3fb9f9b9b 100644--- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/writercache/TestCompactLabelToOrdinal.java+++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/writercache/TestCompactLabelToOrdinal.java@@ -4,15 +4,15 @@ import java.io.File;import java.nio.ByteBuffer;import java.nio.charset.CharsetDecoder;import java.nio.charset.CodingErrorAction;+import java.nio.charset.StandardCharsets;import java.util.HashMap;import java.util.Map;import java.util.Random;import org.apache.lucene.facet.FacetTestCase;import org.apache.lucene.facet.taxonomy.FacetLabel;-import org.apache.lucene.util.IOUtils;-import org.apache.lucene.util.TestUtil;import org.apache.lucene.util.TestUtil;+import org.junit.Test;/*@@ -53,7 +53,7 @@ public class TestCompactLabelToOrdinal extends FacetTestCase {// This test is turning random bytes into a string,// this is asking for trouble.- CharsetDecoder decoder = IOUtils.CHARSET_UTF_8.newDecoder()+ CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder().onUnmappableCharacter(CodingErrorAction.REPLACE).onMalformedInput(CodingErrorAction.REPLACE);uniqueValues[i] = decoder.decode(ByteBuffer.wrap(buffer, 0, size)).toString();diff --git a/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java b/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.javaindex 706fcc63161..40c1c28183c 100644--- a/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java+++ b/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java@@ -20,12 +20,14 @@ package org.apache.lucene.search.highlight;import java.io.ByteArrayInputStream;import java.io.IOException;import java.io.Reader;+import java.nio.charset.StandardCharsets;import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.StringTokenizer;+import javax.xml.parsers.DocumentBuilder;import javax.xml.parsers.DocumentBuilderFactory;@@ -1512,7 +1514,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte// now an ugly built of XML parsing to test the snippet is encoded OKDocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();DocumentBuilder db = dbf.newDocumentBuilder();- org.w3c.dom.Document doc = db.parse(new ByteArrayInputStream(xhtml.getBytes("UTF-8")));+ org.w3c.dom.Document doc = db.parse(new ByteArrayInputStream(xhtml.getBytes(StandardCharsets.UTF_8)));Element root = doc.getDocumentElement();NodeList nodes = root.getElementsByTagName("body");Element body = (Element) nodes.item(0);diff --git a/lucene/highlighter/src/test/org/apache/lucene/search/postingshighlight/TestPostingsHighlighter.java b/lucene/highlighter/src/test/org/apache/lucene/search/postingshighlight/TestPostingsHighlighter.javaindex 9bb6f5349cb..7e9d00ff2bb 100644--- a/lucene/highlighter/src/test/org/apache/lucene/search/postingshighlight/TestPostingsHighlighter.java+++ b/lucene/highlighter/src/test/org/apache/lucene/search/postingshighlight/TestPostingsHighlighter.java@@ -20,6 +20,7 @@ package org.apache.lucene.search.postingshighlight;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;+import java.nio.charset.StandardCharsets;import java.text.BreakIterator;import java.util.Arrays;import java.util.Map;@@ -489,7 +490,7 @@ public class TestPostingsHighlighter extends LuceneTestCase {public void testCambridgeMA() throws Exception {BufferedReader r = new BufferedReader(new InputStreamReader(- this.getClass().getResourceAsStream("CambridgeMA.utf8"), "UTF-8"));+ this.getClass().getResourceAsStream("CambridgeMA.utf8"), StandardCharsets.UTF_8));String text = r.readLine();r.close();Directory dir = newDirectory();diff --git a/lucene/memory/src/test/org/apache/lucene/index/memory/MemoryIndexTest.java b/lucene/memory/src/test/org/apache/lucene/index/memory/MemoryIndexTest.javaindex 093c0c36dc6..74318c81ecc 100644--- a/lucene/memory/src/test/org/apache/lucene/index/memory/MemoryIndexTest.java+++ b/lucene/memory/src/test/org/apache/lucene/index/memory/MemoryIndexTest.java@@ -21,6 +21,7 @@ import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;+import java.nio.charset.StandardCharsets;import java.util.HashSet;import java.util.Set;@@ -100,7 +101,7 @@ public class MemoryIndexTest extends BaseTokenStreamTestCase {private Set<String> readQueries(String resource) throws IOException {Set<String> queries = new HashSet<>();InputStream stream = getClass().getResourceAsStream(resource);- BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));+ BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8));String line = null;while ((line = reader.readLine()) != null) {line = line.trim();diff --git a/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestParser.java b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestParser.javaindex eaa71db5fe0..36e8b7e1b28 100644--- a/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestParser.java+++ b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestParser.java@@ -45,6 +45,7 @@ import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;+import java.nio.charset.StandardCharsets;import java.util.List;@@ -63,7 +64,7 @@ public class TestParser extends LuceneTestCase {builder = new CorePlusExtensionsParser("contents", analyzer);BufferedReader d = new BufferedReader(new InputStreamReader(- TestParser.class.getResourceAsStream("reuters21578.txt"), "US-ASCII"));+ TestParser.class.getResourceAsStream("reuters21578.txt"), StandardCharsets.US_ASCII));dir = newDirectory();IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer));String line = d.readLine();diff --git a/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/builders/TestNumericRangeFilterBuilder.java b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/builders/TestNumericRangeFilterBuilder.javaindex 727d5e10eac..3d05367f071 100644--- a/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/builders/TestNumericRangeFilterBuilder.java+++ b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/builders/TestNumericRangeFilterBuilder.java@@ -33,9 +33,11 @@ import org.xml.sax.SAXException;import javax.xml.parsers.DocumentBuilder;import javax.xml.parsers.DocumentBuilderFactory;import javax.xml.parsers.ParserConfigurationException;+import java.io.ByteArrayInputStream;import java.io.IOException;import java.io.InputStream;+import java.nio.charset.StandardCharsets;public class TestNumericRangeFilterBuilder extends LuceneTestCase {@@ -203,7 +205,7 @@ public class TestNumericRangeFilterBuilder extends LuceneTestCase {private static Document getDocumentFromString(String str)throws SAXException, IOException, ParserConfigurationException {- InputStream is = new ByteArrayInputStream(str.getBytes("UTF-8"));+ InputStream is = new ByteArrayInputStream(str.getBytes(StandardCharsets.UTF_8));DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();factory.setNamespaceAware(true);DocumentBuilder builder = factory.newDocumentBuilder();diff --git a/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/builders/TestNumericRangeQueryBuilder.java b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/builders/TestNumericRangeQueryBuilder.javaindex 4ffee9d222a..53a7f09a4b2 100644--- a/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/builders/TestNumericRangeQueryBuilder.java+++ b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/builders/TestNumericRangeQueryBuilder.java@@ -27,9 +27,11 @@ import org.xml.sax.SAXException;import javax.xml.parsers.DocumentBuilder;import javax.xml.parsers.DocumentBuilderFactory;import javax.xml.parsers.ParserConfigurationException;+import java.io.ByteArrayInputStream;import java.io.IOException;import java.io.InputStream;+import java.nio.charset.StandardCharsets;public class TestNumericRangeQueryBuilder extends LuceneTestCase {@@ -166,7 +168,7 @@ public class TestNumericRangeQueryBuilder extends LuceneTestCase {private static Document getDocumentFromString(String str)throws SAXException, IOException, ParserConfigurationException {- InputStream is = new ByteArrayInputStream(str.getBytes("UTF-8"));+ InputStream is = new ByteArrayInputStream(str.getBytes(StandardCharsets.UTF_8));DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();factory.setNamespaceAware(true);DocumentBuilder builder = factory.newDocumentBuilder();diff --git a/lucene/sandbox/src/test/org/apache/lucene/sandbox/queries/TestSlowFuzzyQuery2.java b/lucene/sandbox/src/test/org/apache/lucene/sandbox/queries/TestSlowFuzzyQuery2.javaindex c93c14a057c..178d3dac89e 100644--- a/lucene/sandbox/src/test/org/apache/lucene/sandbox/queries/TestSlowFuzzyQuery2.java+++ b/lucene/sandbox/src/test/org/apache/lucene/sandbox/queries/TestSlowFuzzyQuery2.java@@ -20,6 +20,7 @@ package org.apache.lucene.sandbox.queries;import java.io.BufferedReader;import java.io.InputStream;import java.io.InputStreamReader;+import java.nio.charset.StandardCharsets;import org.apache.lucene.analysis.MockAnalyzer;import org.apache.lucene.analysis.MockTokenizer;@@ -83,7 +84,7 @@ public class TestSlowFuzzyQuery2 extends LuceneTestCase {System.out.println("TEST: codePointTable=" + codePointTable);}InputStream stream = getClass().getResourceAsStream("fuzzyTestData.txt");- BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));+ BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8));int bits = Integer.parseInt(reader.readLine());int terms = (int) Math.pow(2, bits);diff --git a/lucene/suggest/src/java/org/apache/lucene/search/spell/PlainTextDictionary.java b/lucene/suggest/src/java/org/apache/lucene/search/spell/PlainTextDictionary.javaindex 5e77021af79..91f9db6328c 100644--- a/lucene/suggest/src/java/org/apache/lucene/search/spell/PlainTextDictionary.java+++ b/lucene/suggest/src/java/org/apache/lucene/search/spell/PlainTextDictionary.java@@ -22,6 +22,7 @@ import java.io.File;import java.io.IOException;import java.io.InputStream;import java.io.Reader;+import java.nio.charset.StandardCharsets;import org.apache.lucene.search.suggest.InputIterator;import org.apache.lucene.util.BytesRef;@@ -47,7 +48,7 @@ public class PlainTextDictionary implements Dictionary {* NOTE: content is treated as UTF-8*/public PlainTextDictionary(File file) throws IOException {- in = new BufferedReader(IOUtils.getDecodingReader(file, IOUtils.CHARSET_UTF_8));+ in = new BufferedReader(IOUtils.getDecodingReader(file, StandardCharsets.UTF_8));}/**@@ -56,7 +57,7 @@ public class PlainTextDictionary implements Dictionary {* NOTE: content is treated as UTF-8*/public PlainTextDictionary(InputStream dictFile) {- in = new BufferedReader(IOUtils.getDecodingReader(dictFile, IOUtils.CHARSET_UTF_8));+ in = new BufferedReader(IOUtils.getDecodingReader(dictFile, StandardCharsets.UTF_8));}/**diff --git a/lucene/suggest/src/java/org/apache/lucene/search/suggest/FileDictionary.java b/lucene/suggest/src/java/org/apache/lucene/search/suggest/FileDictionary.javaindex 1d24c2c9d8c..5006cb4e8d9 100644--- a/lucene/suggest/src/java/org/apache/lucene/search/suggest/FileDictionary.java+++ b/lucene/suggest/src/java/org/apache/lucene/search/suggest/FileDictionary.java@@ -19,6 +19,7 @@ package org.apache.lucene.search.suggest;import java.io.*;+import java.nio.charset.StandardCharsets;import java.util.Set;import org.apache.lucene.search.spell.Dictionary;@@ -102,7 +103,7 @@ public class FileDictionary implements Dictionary {* NOTE: content is treated as UTF-8*/public FileDictionary(InputStream dictFile, String fieldDelimiter) {- in = new BufferedReader(IOUtils.getDecodingReader(dictFile, IOUtils.CHARSET_UTF_8));+ in = new BufferedReader(IOUtils.getDecodingReader(dictFile, StandardCharsets.UTF_8));this.fieldDelimiter = fieldDelimiter;}diff --git a/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/FuzzySuggester.java b/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/FuzzySuggester.javaindex 63a26e20245..458d59d5ba9 100644--- a/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/FuzzySuggester.java+++ b/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/FuzzySuggester.java@@ -17,6 +17,7 @@ package org.apache.lucene.search.suggest.analyzing;*/import java.io.IOException;+import java.nio.charset.StandardCharsets;import java.util.Arrays;import java.util.List;import java.util.Set;@@ -192,7 +193,7 @@ public final class FuzzySuggester extends AnalyzingSuggester {Automaton levA = convertAutomaton(toLevenshteinAutomata(lookupAutomaton));/*- Writer w = new OutputStreamWriter(new FileOutputStream("out.dot"), "UTF-8");+ Writer w = new OutputStreamWriter(new FileOutputStream("out.dot"), StandardCharsets.UTF_8);w.write(levA.toDot());w.close();System.out.println("Wrote LevA to out.dot");diff --git a/lucene/suggest/src/java/org/apache/lucene/search/suggest/jaspell/JaspellTernarySearchTrie.java b/lucene/suggest/src/java/org/apache/lucene/search/suggest/jaspell/JaspellTernarySearchTrie.javaindex 2bffc11db35..d3e106cd19f 100644--- a/lucene/suggest/src/java/org/apache/lucene/search/suggest/jaspell/JaspellTernarySearchTrie.java+++ b/lucene/suggest/src/java/org/apache/lucene/search/suggest/jaspell/JaspellTernarySearchTrie.java@@ -33,7 +33,7 @@ import java.io.BufferedReader;import java.io.File;import java.io.FileInputStream;import java.io.IOException;-import java.io.InputStreamReader;+import java.nio.charset.StandardCharsets;import java.util.List;import java.util.Locale;import java.util.Vector;@@ -224,15 +224,13 @@ public class JaspellTernarySearchTrie {BufferedReader in;if (compression)in = new BufferedReader(IOUtils.getDecodingReader(new GZIPInputStream(- new FileInputStream(file)), IOUtils.CHARSET_UTF_8));+ new FileInputStream(file)), StandardCharsets.UTF_8));else in = new BufferedReader(IOUtils.getDecodingReader((new FileInputStream(- file)), IOUtils.CHARSET_UTF_8));+ file)), StandardCharsets.UTF_8));String word;int pos;Float occur, one = new Float(1);- int numWords = 0;while ((word = in.readLine()) != null) {- numWords++;pos = word.indexOf("\t");occur = one;if (pos != -1) {diff --git a/lucene/suggest/src/test/org/apache/lucene/search/suggest/FileDictionaryTest.java b/lucene/suggest/src/test/org/apache/lucene/search/suggest/FileDictionaryTest.javaindex 2d880f587a5..29f7387fca7 100644--- a/lucene/suggest/src/test/org/apache/lucene/search/suggest/FileDictionaryTest.java+++ b/lucene/suggest/src/test/org/apache/lucene/search/suggest/FileDictionaryTest.java@@ -3,6 +3,7 @@ package org.apache.lucene.search.suggest;import java.io.ByteArrayInputStream;import java.io.IOException;import java.io.InputStream;+import java.nio.charset.StandardCharsets;import java.util.AbstractMap.SimpleEntry;import java.util.ArrayList;import java.util.List;@@ -74,7 +75,7 @@ public class FileDictionaryTest extends LuceneTestCase {@Testpublic void testFileWithTerm() throws IOException {Map.Entry<List<List<String>>,String> fileInput = generateFileInput(atLeast(100), FileDictionary.DEFAULT_FIELD_DELIMITER, false, false);- InputStream inputReader = new ByteArrayInputStream(fileInput.getValue().getBytes("UTF-8"));+ InputStream inputReader = new ByteArrayInputStream(fileInput.getValue().getBytes(StandardCharsets.UTF_8));FileDictionary dictionary = new FileDictionary(inputReader);List<List<String>> entries = fileInput.getKey();InputIterator inputIter = dictionary.getEntryIterator();@@ -96,7 +97,7 @@ public class FileDictionaryTest extends LuceneTestCase {@Testpublic void testFileWithWeight() throws IOException {Map.Entry<List<List<String>>,String> fileInput = generateFileInput(atLeast(100), FileDictionary.DEFAULT_FIELD_DELIMITER, true, false);- InputStream inputReader = new ByteArrayInputStream(fileInput.getValue().getBytes("UTF-8"));+ InputStream inputReader = new ByteArrayInputStream(fileInput.getValue().getBytes(StandardCharsets.UTF_8));FileDictionary dictionary = new FileDictionary(inputReader);List<List<String>> entries = fileInput.getKey();InputIterator inputIter = dictionary.getEntryIterator();@@ -118,7 +119,7 @@ public class FileDictionaryTest extends LuceneTestCase {@Testpublic void testFileWithWeightAndPayload() throws IOException {Map.Entry<List<List<String>>,String> fileInput = generateFileInput(atLeast(100), FileDictionary.DEFAULT_FIELD_DELIMITER, true, true);- InputStream inputReader = new ByteArrayInputStream(fileInput.getValue().getBytes("UTF-8"));+ InputStream inputReader = new ByteArrayInputStream(fileInput.getValue().getBytes(StandardCharsets.UTF_8));FileDictionary dictionary = new FileDictionary(inputReader);List<List<String>> entries = fileInput.getKey();InputIterator inputIter = dictionary.getEntryIterator();@@ -144,7 +145,7 @@ public class FileDictionaryTest extends LuceneTestCase {@Testpublic void testFileWithOneEntry() throws IOException {Map.Entry<List<List<String>>,String> fileInput = generateFileInput(1, FileDictionary.DEFAULT_FIELD_DELIMITER, true, true);- InputStream inputReader = new ByteArrayInputStream(fileInput.getValue().getBytes("UTF-8"));+ InputStream inputReader = new ByteArrayInputStream(fileInput.getValue().getBytes(StandardCharsets.UTF_8));FileDictionary dictionary = new FileDictionary(inputReader);List<List<String>> entries = fileInput.getKey();InputIterator inputIter = dictionary.getEntryIterator();@@ -171,7 +172,7 @@ public class FileDictionaryTest extends LuceneTestCase {@Testpublic void testFileWithDifferentDelimiter() throws IOException {Map.Entry<List<List<String>>,String> fileInput = generateFileInput(atLeast(100), " , ", true, true);- InputStream inputReader = new ByteArrayInputStream(fileInput.getValue().getBytes("UTF-8"));+ InputStream inputReader = new ByteArrayInputStream(fileInput.getValue().getBytes(StandardCharsets.UTF_8));FileDictionary dictionary = new FileDictionary(inputReader, " , ");List<List<String>> entries = fileInput.getKey();InputIterator inputIter = dictionary.getEntryIterator();diff --git a/lucene/suggest/src/test/org/apache/lucene/search/suggest/LookupBenchmarkTest.java b/lucene/suggest/src/test/org/apache/lucene/search/suggest/LookupBenchmarkTest.javaindex 7d99824d8b9..693f880f41c 100644--- a/lucene/suggest/src/test/org/apache/lucene/search/suggest/LookupBenchmarkTest.java+++ b/lucene/suggest/src/test/org/apache/lucene/search/suggest/LookupBenchmarkTest.java@@ -22,6 +22,7 @@ import java.io.InputStreamReader;import java.lang.reflect.Constructor;import java.net.URL;import java.nio.charset.Charset;+import java.nio.charset.StandardCharsets;import java.util.ArrayList;import java.util.Arrays;import java.util.Collections;@@ -92,7 +93,7 @@ public class LookupBenchmarkTest extends LuceneTestCase {LookupBenchmarkTest.benchmarkInput = input;}- static final Charset UTF_8 = Charset.forName("UTF-8");+ static final Charset UTF_8 = StandardCharsets.UTF_8;/*** Collect the multilingual input for benchmarks/ tests.diff --git a/lucene/suggest/src/test/org/apache/lucene/search/suggest/fst/FSTCompletionTest.java b/lucene/suggest/src/test/org/apache/lucene/search/suggest/fst/FSTCompletionTest.javaindex 1b027948ce8..acade2e764e 100644--- a/lucene/suggest/src/test/org/apache/lucene/search/suggest/fst/FSTCompletionTest.java+++ b/lucene/suggest/src/test/org/apache/lucene/search/suggest/fst/FSTCompletionTest.java@@ -17,6 +17,7 @@ package org.apache.lucene.search.suggest.fst;* limitations under the License.*/+import java.nio.charset.StandardCharsets;import java.util.*;import org.apache.lucene.search.suggest.Lookup.LookupResult;@@ -144,7 +145,7 @@ public class FSTCompletionTest extends LuceneTestCase {public void testThreeByte() throws Exception {String key = new String(new byte[] {- (byte) 0xF0, (byte) 0xA4, (byte) 0xAD, (byte) 0xA2}, "UTF-8");+ (byte) 0xF0, (byte) 0xA4, (byte) 0xAD, (byte) 0xA2}, StandardCharsets.UTF_8);FSTCompletionBuilder builder = new FSTCompletionBuilder();builder.add(new BytesRef(key), 0);diff --git a/lucene/suggest/src/test/org/apache/lucene/search/suggest/fst/LargeInputFST.java b/lucene/suggest/src/test/org/apache/lucene/search/suggest/fst/LargeInputFST.javaindex 0cb6c668d02..d55e8febb64 100644--- a/lucene/suggest/src/test/org/apache/lucene/search/suggest/fst/LargeInputFST.java+++ b/lucene/suggest/src/test/org/apache/lucene/search/suggest/fst/LargeInputFST.java@@ -23,6 +23,7 @@ import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStreamReader;+import java.nio.charset.StandardCharsets;import org.apache.lucene.util.BytesRef;import org.apache.lucene.util.OfflineSorter;@@ -43,7 +44,7 @@ public class LargeInputFST {BufferedReader reader = new BufferedReader(new InputStreamReader(- new FileInputStream(input), "UTF-8"));+ new FileInputStream(input), StandardCharsets.UTF_8));BytesRef scratch = new BytesRef();String line;diff --git a/lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.javaindex 668b7e7eb27..caf76609c3a 100644--- a/lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java+++ b/lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java@@ -25,6 +25,7 @@ import java.io.Reader;import java.io.StringReader;import java.io.StringWriter;import java.io.Writer;+import java.nio.charset.StandardCharsets;import java.util.*;import java.util.concurrent.CountDownLatch;@@ -892,7 +893,7 @@ public abstract class BaseTokenStreamTestCase extends LuceneTestCase {}protected void toDotFile(Analyzer a, String inputText, String localFileName) throws IOException {- Writer w = new OutputStreamWriter(new FileOutputStream(localFileName), "UTF-8");+ Writer w = new OutputStreamWriter(new FileOutputStream(localFileName), StandardCharsets.UTF_8);final TokenStream ts = a.tokenStream("field", inputText);ts.reset();new TokenStreamToDot(inputText, ts, new PrintWriter(w)).toDot();diff --git a/lucene/test-framework/src/java/org/apache/lucene/analysis/MockPayloadAnalyzer.java b/lucene/test-framework/src/java/org/apache/lucene/analysis/MockPayloadAnalyzer.javaindex b144f935040..09393ef6d69 100644--- a/lucene/test-framework/src/java/org/apache/lucene/analysis/MockPayloadAnalyzer.java+++ b/lucene/test-framework/src/java/org/apache/lucene/analysis/MockPayloadAnalyzer.java@@ -24,6 +24,7 @@ import org.apache.lucene.util.BytesRef;import java.io.IOException;import java.io.Reader;+import java.nio.charset.StandardCharsets;/**@@ -68,7 +69,7 @@ final class MockPayloadFilter extends TokenFilter {@Overridepublic boolean incrementToken() throws IOException {if (input.incrementToken()) {- payloadAttr.setPayload(new BytesRef(("pos: " + pos).getBytes("UTF-8")));+ payloadAttr.setPayload(new BytesRef(("pos: " + pos).getBytes(StandardCharsets.UTF_8)));int posIncr;if (pos == 0 || i % 2 == 1) {posIncr = 1;diff --git a/lucene/test-framework/src/java/org/apache/lucene/analysis/VocabularyAssert.java b/lucene/test-framework/src/java/org/apache/lucene/analysis/VocabularyAssert.javaindex 659831856c3..cdcacc587bf 100644--- a/lucene/test-framework/src/java/org/apache/lucene/analysis/VocabularyAssert.java+++ b/lucene/test-framework/src/java/org/apache/lucene/analysis/VocabularyAssert.java@@ -22,6 +22,7 @@ import java.io.File;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;+import java.nio.charset.StandardCharsets;import java.util.zip.ZipFile;import org.apache.lucene.analysis.Analyzer;@@ -34,9 +35,9 @@ public class VocabularyAssert {public static void assertVocabulary(Analyzer a, InputStream voc, InputStream out)throws IOException {BufferedReader vocReader = new BufferedReader(- new InputStreamReader(voc, "UTF-8"));+ new InputStreamReader(voc, StandardCharsets.UTF_8));BufferedReader outputReader = new BufferedReader(- new InputStreamReader(out, "UTF-8"));+ new InputStreamReader(out, StandardCharsets.UTF_8));String inputWord = null;while ((inputWord = vocReader.readLine()) != null) {String expectedWord = outputReader.readLine();@@ -49,7 +50,7 @@ public class VocabularyAssert {public static void assertVocabulary(Analyzer a, InputStream vocOut)throws IOException {BufferedReader vocReader = new BufferedReader(- new InputStreamReader(vocOut, "UTF-8"));+ new InputStreamReader(vocOut, StandardCharsets.UTF_8));String inputLine = null;while ((inputLine = vocReader.readLine()) != null) {if (inputLine.startsWith("#") || inputLine.trim().length() == 0)diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/BaseStoredFieldsFormatTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/index/BaseStoredFieldsFormatTestCase.javaindex a2d9234e0ff..25559c927a0 100644--- a/lucene/test-framework/src/java/org/apache/lucene/index/BaseStoredFieldsFormatTestCase.java+++ b/lucene/test-framework/src/java/org/apache/lucene/index/BaseStoredFieldsFormatTestCase.java@@ -18,6 +18,7 @@ package org.apache.lucene.index;*/import java.io.IOException;+import java.nio.charset.StandardCharsets;import java.util.ArrayList;import java.util.Arrays;import java.util.Collections;@@ -351,7 +352,7 @@ public abstract class BaseStoredFieldsFormatTestCase extends LuceneTestCase {ft.freeze();final String string = TestUtil.randomSimpleString(random(), 50);- final byte[] bytes = string.getBytes("UTF-8");+ final byte[] bytes = string.getBytes(StandardCharsets.UTF_8);final long l = random().nextBoolean() ? random().nextInt(42) : random().nextLong();final int i = random().nextBoolean() ? random().nextInt(42) : random().nextInt();final float f = random().nextFloat();diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/LineFileDocs.java b/lucene/test-framework/src/java/org/apache/lucene/util/LineFileDocs.javaindex 33d9d1d6917..4cc95bb0f3d 100644--- a/lucene/test-framework/src/java/org/apache/lucene/util/LineFileDocs.java+++ b/lucene/test-framework/src/java/org/apache/lucene/util/LineFileDocs.java@@ -29,6 +29,7 @@ import java.nio.channels.Channels;import java.nio.channels.FileChannel;import java.nio.charset.CharsetDecoder;import java.nio.charset.CodingErrorAction;+import java.nio.charset.StandardCharsets;import java.util.Random;import java.util.concurrent.atomic.AtomicInteger;import java.util.zip.GZIPInputStream;@@ -133,7 +134,7 @@ public class LineFileDocs implements Closeable {} while (b >= 0 && b != 13 && b != 10);}- CharsetDecoder decoder = IOUtils.CHARSET_UTF_8.newDecoder()+ CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder().onMalformedInput(CodingErrorAction.REPORT).onUnmappableCharacter(CodingErrorAction.REPORT);reader = new BufferedReader(new InputStreamReader(is, decoder), BUFFER_SIZE);diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java b/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.javaindex e7718da3eda..db6e24df4d8 100644--- a/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java+++ b/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java@@ -217,15 +217,15 @@ public final class TestUtil {ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);CheckIndex checker = new CheckIndex(dir);checker.setCrossCheckTermVectors(crossCheckTermVectors);- checker.setInfoStream(new PrintStream(bos, false, "UTF-8"), false);+ checker.setInfoStream(new PrintStream(bos, false, IOUtils.UTF_8), false);CheckIndex.Status indexStatus = checker.checkIndex(null);if (indexStatus == null || indexStatus.clean == false) {System.out.println("CheckIndex failed");- System.out.println(bos.toString("UTF-8"));+ System.out.println(bos.toString(IOUtils.UTF_8));throw new RuntimeException("CheckIndex failed");} else {if (LuceneTestCase.INFOSTREAM) {- System.out.println(bos.toString("UTF-8"));+ System.out.println(bos.toString(IOUtils.UTF_8));}return indexStatus;}@@ -241,7 +241,7 @@ public final class TestUtil {public static void checkReader(AtomicReader reader, boolean crossCheckTermVectors) throws IOException {ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);- PrintStream infoStream = new PrintStream(bos, false, "UTF-8");+ PrintStream infoStream = new PrintStream(bos, false, IOUtils.UTF_8);FieldNormStatus fieldNormStatus = CheckIndex.testFieldNorms(reader, infoStream);TermIndexStatus termIndexStatus = CheckIndex.testPostings(reader, infoStream);@@ -255,11 +255,11 @@ public final class TestUtil {termVectorStatus.error != null ||docValuesStatus.error != null) {System.out.println("CheckReader failed");- System.out.println(bos.toString("UTF-8"));+ System.out.println(bos.toString(IOUtils.UTF_8));throw new RuntimeException("CheckReader failed");} else {if (LuceneTestCase.INFOSTREAM) {- System.out.println(bos.toString("UTF-8"));+ System.out.println(bos.toString(IOUtils.UTF_8));}}}diff --git a/lucene/tools/src/java/org/apache/lucene/dependencies/GetMavenDependenciesTask.java b/lucene/tools/src/java/org/apache/lucene/dependencies/GetMavenDependenciesTask.javaindex 33402d03414..dc3f6926331 100644--- a/lucene/tools/src/java/org/apache/lucene/dependencies/GetMavenDependenciesTask.java+++ b/lucene/tools/src/java/org/apache/lucene/dependencies/GetMavenDependenciesTask.java@@ -41,6 +41,7 @@ import java.io.Reader;import java.io.UnsupportedEncodingException;import java.io.Writer;import java.nio.charset.Charset;+import java.nio.charset.StandardCharsets;import java.util.ArrayList;import java.util.Arrays;import java.util.Collection;@@ -58,6 +59,7 @@ import java.util.TreeMap;import java.util.TreeSet;import java.util.regex.Matcher;import java.util.regex.Pattern;+import javax.xml.parsers.DocumentBuilder;import javax.xml.parsers.DocumentBuilderFactory;import javax.xml.parsers.ParserConfigurationException;@@ -200,7 +202,7 @@ public class GetMavenDependenciesTask extends Task {Writer writer = null;try {FileOutputStream outputStream = new FileOutputStream(mavenDependenciesFiltersFile);- writer = new OutputStreamWriter(outputStream, "ISO-8859-1");+ writer = new OutputStreamWriter(outputStream, StandardCharsets.ISO_8859_1);allProperties.store(writer, null);} catch (FileNotFoundException e) {throw new BuildException("Can't find file: '" + mavenDependenciesFiltersFile.getPath() + "'", e);@@ -808,7 +810,7 @@ public class GetMavenDependenciesTask extends Task {throw new BuildException("Properties file does not exist: " + file.getPath());}// Properties files are encoded as Latin-1- final Reader reader = new InputStreamReader(stream, Charset.forName("ISO-8859-1"));+ final Reader reader = new InputStreamReader(stream, StandardCharsets.ISO_8859_1);final Properties properties = new Properties();try {properties.load(reader);diff --git a/lucene/tools/src/java/org/apache/lucene/validation/LibVersionsCheckTask.java b/lucene/tools/src/java/org/apache/lucene/validation/LibVersionsCheckTask.javaindex 7741fb6e971..9777df9a965 100644--- a/lucene/tools/src/java/org/apache/lucene/validation/LibVersionsCheckTask.java+++ b/lucene/tools/src/java/org/apache/lucene/validation/LibVersionsCheckTask.java@@ -33,6 +33,7 @@ import org.xml.sax.helpers.DefaultHandler;import org.xml.sax.helpers.XMLReaderFactory;import javax.xml.parsers.ParserConfigurationException;+import java.io.BufferedReader;import java.io.File;import java.io.FileInputStream;@@ -44,6 +45,7 @@ import java.io.Reader;import java.nio.charset.Charset;import java.nio.charset.CharsetDecoder;import java.nio.charset.CodingErrorAction;+import java.nio.charset.StandardCharsets;import java.util.Iterator;import java.util.LinkedHashMap;import java.util.Locale;@@ -188,7 +190,7 @@ public class LibVersionsCheckTask extends Task {+ centralizedVersionsFile.getPath());}// Properties files are encoded as Latin-1- final Reader reader = new InputStreamReader(stream, Charset.forName("ISO-8859-1"));+ final Reader reader = new InputStreamReader(stream, StandardCharsets.ISO_8859_1);final BufferedReader bufferedReader = new BufferedReader(reader);String line = null;diff --git a/lucene/tools/src/java/org/apache/lucene/validation/LicenseCheckTask.java b/lucene/tools/src/java/org/apache/lucene/validation/LicenseCheckTask.javaindex 7ee4a6a598e..c3a8d0ccefd 100644--- a/lucene/tools/src/java/org/apache/lucene/validation/LicenseCheckTask.java+++ b/lucene/tools/src/java/org/apache/lucene/validation/LicenseCheckTask.java@@ -22,14 +22,13 @@ import java.io.FileInputStream;import java.io.BufferedReader;import java.io.InputStreamReader;import java.io.IOException;-+import java.nio.charset.StandardCharsets;import java.util.ArrayList;import java.util.Iterator;import java.util.LinkedHashMap;import java.util.List;import java.util.Locale;import java.util.Map;-import java.security.DigestInputStream;import java.security.MessageDigest;import java.security.NoSuchAlgorithmException;@@ -302,7 +301,7 @@ outer:BufferedReader reader = null;try {reader = new BufferedReader(new InputStreamReader- (new FileInputStream(f), "UTF-8"));+ (new FileInputStream(f), StandardCharsets.UTF_8));try {String checksum = reader.readLine();if (null == checksum || 0 == checksum.length()) {diff --git a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/SimplePropertiesWriter.java b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/SimplePropertiesWriter.javaindex 73e6fb1c6fb..7857ab90cf7 100644--- a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/SimplePropertiesWriter.java+++ b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/SimplePropertiesWriter.java@@ -26,6 +26,7 @@ import java.io.InputStream;import java.io.InputStreamReader;import java.io.OutputStreamWriter;import java.io.Writer;+import java.nio.charset.StandardCharsets;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Date;@@ -192,7 +193,7 @@ public class SimplePropertiesWriter extends DIHProperties {filePath += File.separator;}filePath += filename;- propOutput = new OutputStreamWriter(new FileOutputStream(filePath), IOUtils.CHARSET_UTF_8);+ propOutput = new OutputStreamWriter(new FileOutputStream(filePath), StandardCharsets.UTF_8);existingProps.store(propOutput, null);log.info("Wrote last indexed time to " + filename);} catch (Exception e) {@@ -214,7 +215,7 @@ public class SimplePropertiesWriter extends DIHProperties {}filePath += filename;propInput = new FileInputStream(filePath);- props.load(new InputStreamReader(propInput, IOUtils.CHARSET_UTF_8));+ props.load(new InputStreamReader(propInput, StandardCharsets.UTF_8));log.info("Read " + filename);} catch (Exception e) {log.warn("Unable to read: " + filename);diff --git a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/ZKPropertiesWriter.java b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/ZKPropertiesWriter.javaindex d839f277605..16381d38700 100644--- a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/ZKPropertiesWriter.java+++ b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/ZKPropertiesWriter.java@@ -18,10 +18,10 @@ package org.apache.solr.handler.dataimport;import java.io.StringReader;import java.io.StringWriter;+import java.nio.charset.StandardCharsets;import java.util.Map;import java.util.Properties;-import org.apache.lucene.util.IOUtils;import org.apache.solr.common.cloud.SolrZkClient;import org.apache.zookeeper.KeeperException.NodeExistsException;import org.slf4j.Logger;@@ -67,7 +67,7 @@ public class ZKPropertiesWriter extends SimplePropertiesWriter {StringWriter output = new StringWriter();try {existing.store(output, null);- byte[] bytes = output.toString().getBytes(IOUtils.CHARSET_UTF_8);+ byte[] bytes = output.toString().getBytes(StandardCharsets.UTF_8);if (!zkClient.exists(path, false)) {try {zkClient.makePath(path, false);diff --git a/solr/contrib/extraction/src/java/org/apache/solr/handler/extraction/RegexRulesPasswordProvider.java b/solr/contrib/extraction/src/java/org/apache/solr/handler/extraction/RegexRulesPasswordProvider.javaindex 35b8f3c8c6e..8e30d1a880e 100644--- a/solr/contrib/extraction/src/java/org/apache/solr/handler/extraction/RegexRulesPasswordProvider.java+++ b/solr/contrib/extraction/src/java/org/apache/solr/handler/extraction/RegexRulesPasswordProvider.java@@ -20,6 +20,7 @@ package org.apache.solr.handler.extraction;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;+import java.nio.charset.StandardCharsets;import java.util.LinkedHashMap;import java.util.Map.Entry;import java.util.regex.Pattern;@@ -73,7 +74,7 @@ public class RegexRulesPasswordProvider implements PasswordProvider {*/public static LinkedHashMap<Pattern,String> parseRulesFile(InputStream is) {LinkedHashMap<Pattern,String> rules = new LinkedHashMap<>();- BufferedReader br = new BufferedReader(IOUtils.getDecodingReader(is, IOUtils.CHARSET_UTF_8));+ BufferedReader br = new BufferedReader(IOUtils.getDecodingReader(is, StandardCharsets.UTF_8));String line;try {int linenum = 0;diff --git a/solr/contrib/velocity/src/java/org/apache/solr/response/VelocityResponseWriter.java b/solr/contrib/velocity/src/java/org/apache/solr/response/VelocityResponseWriter.javaindex 413d708f079..3318713045a 100644--- a/solr/contrib/velocity/src/java/org/apache/solr/response/VelocityResponseWriter.java+++ b/solr/contrib/velocity/src/java/org/apache/solr/response/VelocityResponseWriter.java@@ -17,21 +17,29 @@package org.apache.solr.response;-import org.apache.lucene.util.IOUtils;+import java.io.IOException;+import java.io.InputStream;+import java.io.InputStreamReader;+import java.io.StringWriter;+import java.io.Writer;+import java.nio.charset.StandardCharsets;+import java.util.Properties;+import org.apache.solr.client.solrj.SolrResponse;import org.apache.solr.client.solrj.response.QueryResponse;import org.apache.solr.client.solrj.response.SolrResponseBase;-import org.apache.solr.common.SolrException;import org.apache.solr.common.util.NamedList;import org.apache.solr.request.SolrQueryRequest;import org.apache.velocity.Template;import org.apache.velocity.VelocityContext;import org.apache.velocity.app.VelocityEngine;import org.apache.velocity.runtime.RuntimeConstants;-import org.apache.velocity.tools.generic.*;--import java.io.*;-import java.util.Properties;+import org.apache.velocity.tools.generic.ComparisonDateTool;+import org.apache.velocity.tools.generic.EscapeTool;+import org.apache.velocity.tools.generic.ListTool;+import org.apache.velocity.tools.generic.MathTool;+import org.apache.velocity.tools.generic.NumberTool;+import org.apache.velocity.tools.generic.SortTool;public class VelocityResponseWriter implements QueryResponseWriter {@@ -132,7 +140,7 @@ public class VelocityResponseWriter implements QueryResponseWriter {try {is = resourceLoader.getResourceStream(propFile);Properties props = new Properties();- props.load(new InputStreamReader(is, IOUtils.CHARSET_UTF_8));+ props.load(new InputStreamReader(is, StandardCharsets.UTF_8));engine.init(props);}finally {diff --git a/solr/core/src/java/org/apache/solr/cloud/SolrZkServer.java b/solr/core/src/java/org/apache/solr/cloud/SolrZkServer.javaindex dc4e76132d2..8a00887bce7 100644--- a/solr/core/src/java/org/apache/solr/cloud/SolrZkServer.java+++ b/solr/core/src/java/org/apache/solr/cloud/SolrZkServer.java@@ -25,11 +25,11 @@ import java.io.InputStreamReader;import java.net.InetAddress;import java.net.InetSocketAddress;import java.net.UnknownHostException;+import java.nio.charset.StandardCharsets;import java.util.Map;import java.util.Properties;import java.util.Map.Entry;-import org.apache.lucene.util.IOUtils;import org.apache.solr.common.SolrException;import org.apache.zookeeper.server.ServerConfig;import org.apache.zookeeper.server.ZooKeeperServerMain;@@ -179,7 +179,7 @@ class SolrZkServerProps extends QuorumPeerConfig {Properties cfg = new Properties();FileInputStream in = new FileInputStream(configFile);try {- cfg.load(new InputStreamReader(in, IOUtils.CHARSET_UTF_8));+ cfg.load(new InputStreamReader(in, StandardCharsets.UTF_8));} finally {in.close();}@@ -461,7 +461,7 @@ class SolrZkServerProps extends QuorumPeerConfig {+ " file is missing");}- BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(myIdFile), IOUtils.CHARSET_UTF_8));+ BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(myIdFile), StandardCharsets.UTF_8));String myIdString;try {myIdString = br.readLine();diff --git a/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java b/solr/core/src/java/org/apache/solr/cloud/ZkCLI.javaindex 4190aa3f9a4..ef5c469e894 100644--- a/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java+++ b/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java@@ -20,10 +20,12 @@ import org.apache.zookeeper.data.ACL;import org.xml.sax.SAXException;import javax.xml.parsers.ParserConfigurationException;+import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;+import java.nio.charset.StandardCharsets;import java.util.List;import java.util.concurrent.TimeoutException;@@ -253,7 +255,7 @@ public class ZkCLI {System.out.println("-" + PUT + " requires two args - the path to create and the data string");System.exit(1);}- zkClient.create(arglist.get(0).toString(), arglist.get(1).toString().getBytes("UTF-8"),+ zkClient.create(arglist.get(0).toString(), arglist.get(1).toString().getBytes(StandardCharsets.UTF_8),acl, CreateMode.PERSISTENT, true);} else if (line.getOptionValue(CMD).equals(PUT_FILE)) {List arglist = line.getArgList();@@ -276,7 +278,7 @@ public class ZkCLI {System.exit(1);}byte [] data = zkClient.getData(arglist.get(0).toString(), null, null, true);- System.out.println(new String(data, "UTF-8"));+ System.out.println(new String(data, StandardCharsets.UTF_8));} else if (line.getOptionValue(CMD).equals(GET_FILE)) {List arglist = line.getArgList();if (arglist.size() != 2) {diff --git a/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java b/solr/core/src/java/org/apache/solr/core/CoreDescriptor.javaindex b9776fdfa17..df5f9b1227d 100644--- a/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java+++ b/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java@@ -31,6 +31,7 @@ import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStreamReader;+import java.nio.charset.StandardCharsets;import java.util.Locale;import java.util.Properties;@@ -213,7 +214,7 @@ public class CoreDescriptor {try {in = new FileInputStream(propertiesFile);Properties externalProps = new Properties();- externalProps.load(new InputStreamReader(in, "UTF-8"));+ externalProps.load(new InputStreamReader(in, StandardCharsets.UTF_8));coreProperties.putAll(externalProps);} catch (IOException e) {String message = String.format(Locale.ROOT, "Could not load properties from %s: %s:",diff --git a/solr/core/src/java/org/apache/solr/core/SolrCore.java b/solr/core/src/java/org/apache/solr/core/SolrCore.javaindex 3109fd1be6c..32a021aa755 100644--- a/solr/core/src/java/org/apache/solr/core/SolrCore.java+++ b/solr/core/src/java/org/apache/solr/core/SolrCore.java@@ -99,6 +99,7 @@ import org.slf4j.LoggerFactory;import org.xml.sax.SAXException;import javax.xml.parsers.ParserConfigurationException;+import java.io.Closeable;import java.io.File;import java.io.FileNotFoundException;@@ -108,6 +109,7 @@ import java.io.InputStreamReader;import java.io.Writer;import java.lang.reflect.Constructor;import java.net.URL;+import java.nio.charset.StandardCharsets;import java.nio.file.NoSuchFileException;import java.util.ArrayList;import java.util.Arrays;@@ -274,7 +276,7 @@ public final class SolrCore implements SolrInfoMBean, Closeable {if (input != null) {final InputStream is = new PropertiesInputStream(input);try {- p.load(new InputStreamReader(is, "UTF-8"));+ p.load(new InputStreamReader(is, StandardCharsets.UTF_8));String s = p.getProperty("index");if (s != null && s.trim().length() > 0) {diff --git a/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java b/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.javaindex bb375a9acbc..bc95767e5c8 100644--- a/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java+++ b/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java@@ -48,6 +48,7 @@ import javax.naming.Context;import javax.naming.InitialContext;import javax.naming.NamingException;import javax.naming.NoInitialContextException;+import java.io.Closeable;import java.io.File;import java.io.FileFilter;@@ -61,6 +62,7 @@ import java.net.URL;import java.net.URLClassLoader;import java.nio.charset.CharacterCodingException;import java.nio.charset.Charset;+import java.nio.charset.StandardCharsets;import java.util.ArrayList;import java.util.Collections;import java.util.HashMap;@@ -93,7 +95,7 @@ public class SolrResourceLoader implements ResourceLoader,Closeableprivate final List<SolrCoreAware> waitingForCore = Collections.synchronizedList(new ArrayList<SolrCoreAware>());private final List<SolrInfoMBean> infoMBeans = Collections.synchronizedList(new ArrayList<SolrInfoMBean>());private final List<ResourceLoaderAware> waitingForResources = Collections.synchronizedList(new ArrayList<ResourceLoaderAware>());- private static final Charset UTF_8 = Charset.forName("UTF-8");+ private static final Charset UTF_8 = StandardCharsets.UTF_8;//TODO: Solr5. Remove this completely when you obsolete putting <core> tags in solr.xml (See Solr-4196)private final Properties coreProperties;diff --git a/solr/core/src/java/org/apache/solr/core/SolrXMLSerializer.java b/solr/core/src/java/org/apache/solr/core/SolrXMLSerializer.javaindex c1cd720b80c..6b751a4db8a 100644--- a/solr/core/src/java/org/apache/solr/core/SolrXMLSerializer.java+++ b/solr/core/src/java/org/apache/solr/core/SolrXMLSerializer.java@@ -28,6 +28,7 @@ import javax.xml.transform.Transformer;import javax.xml.transform.TransformerFactory;import javax.xml.transform.dom.DOMSource;import javax.xml.transform.stream.StreamResult;+import java.io.BufferedWriter;import java.io.File;import java.io.FileInputStream;@@ -37,6 +38,7 @@ import java.io.OutputStreamWriter;import java.io.StringWriter;import java.io.Writer;import java.nio.channels.FileChannel;+import java.nio.charset.StandardCharsets;import java.util.List;import java.util.Map;import java.util.Properties;@@ -169,7 +171,7 @@ public class SolrXMLSerializer {tmpFile = File.createTempFile("solr", ".xml", file.getParentFile());java.io.FileOutputStream out = new java.io.FileOutputStream(tmpFile);- Writer writer = new BufferedWriter(new OutputStreamWriter(out, "UTF-8"));+ Writer writer = new BufferedWriter(new OutputStreamWriter(out, StandardCharsets.UTF_8));try {persist(writer, solrXMLDef);} finally {diff --git a/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java b/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.javaindex 5da16a4a8ce..5298a4c9c5b 100644--- a/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java+++ b/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java@@ -26,6 +26,7 @@ import java.io.OutputStream;import java.io.Writer;import java.nio.ByteBuffer;import java.nio.channels.FileChannel;+import java.nio.charset.StandardCharsets;import java.nio.file.NoSuchFileException;import java.util.ArrayList;import java.util.Arrays;@@ -81,8 +82,6 @@ import org.apache.solr.util.plugin.SolrCoreAware;import org.slf4j.Logger;import org.slf4j.LoggerFactory;-import static org.apache.lucene.util.IOUtils.CHARSET_UTF_8;-/*** <p> A Handler which provides a REST API for replication and serves replication requests from Slaves. <p/> </p>* <p>When running on the master, it provides the following commands <ol> <li>Get the current replicable index version@@ -823,7 +822,7 @@ public class ReplicationHandler extends RequestHandlerBase implements SolrCoreAwtry {final InputStream is = new PropertiesInputStream(input);Properties props = new Properties();- props.load(new InputStreamReader(is, CHARSET_UTF_8));+ props.load(new InputStreamReader(is, StandardCharsets.UTF_8));return props;} finally {input.close();diff --git a/solr/core/src/java/org/apache/solr/handler/SnapPuller.java b/solr/core/src/java/org/apache/solr/handler/SnapPuller.javaindex 3b2caf07771..65da7932737 100644--- a/solr/core/src/java/org/apache/solr/handler/SnapPuller.java+++ b/solr/core/src/java/org/apache/solr/handler/SnapPuller.java@@ -26,6 +26,7 @@ import java.io.OutputStreamWriter;import java.io.Writer;import java.nio.ByteBuffer;import java.nio.channels.FileChannel;+import java.nio.charset.StandardCharsets;import java.nio.file.NoSuchFileException;import java.text.SimpleDateFormat;import java.util.ArrayList;@@ -90,7 +91,6 @@ import org.eclipse.jetty.util.log.Log;import org.slf4j.Logger;import org.slf4j.LoggerFactory;-import static org.apache.lucene.util.IOUtils.CHARSET_UTF_8;import static org.apache.solr.handler.ReplicationHandler.ALIAS;import static org.apache.solr.handler.ReplicationHandler.CHECKSUM;import static org.apache.solr.handler.ReplicationHandler.CMD_DETAILS;@@ -604,7 +604,7 @@ public class SnapPuller {}final IndexOutput out = dir.createOutput(REPLICATION_PROPERTIES, DirectoryFactory.IOCONTEXT_NO_CACHE);- Writer outFile = new OutputStreamWriter(new PropertiesOutputStream(out), CHARSET_UTF_8);+ Writer outFile = new OutputStreamWriter(new PropertiesOutputStream(out), StandardCharsets.UTF_8);try {props.store(outFile, "Replication details");dir.sync(Collections.singleton(REPLICATION_PROPERTIES));@@ -945,7 +945,7 @@ public class SnapPuller {final InputStream is = new PropertiesInputStream(input);try {- p.load(new InputStreamReader(is, CHARSET_UTF_8));+ p.load(new InputStreamReader(is, StandardCharsets.UTF_8));} catch (Exception e) {LOG.error("Unable to load " + SnapPuller.INDEX_PROPERTIES, e);} finally {@@ -961,7 +961,7 @@ public class SnapPuller {p.put("index", tmpIdxDirName);Writer os = null;try {- os = new OutputStreamWriter(new PropertiesOutputStream(out), CHARSET_UTF_8);+ os = new OutputStreamWriter(new PropertiesOutputStream(out), StandardCharsets.UTF_8);p.store(os, SnapPuller.INDEX_PROPERTIES);dir.sync(Collections.singleton(INDEX_PROPERTIES));} catch (Exception e) {diff --git a/solr/core/src/java/org/apache/solr/internal/csv/writer/CSVConfigGuesser.java b/solr/core/src/java/org/apache/solr/internal/csv/writer/CSVConfigGuesser.javaindex 3f8096c63a4..50f598bac7f 100644--- a/solr/core/src/java/org/apache/solr/internal/csv/writer/CSVConfigGuesser.java+++ b/solr/core/src/java/org/apache/solr/internal/csv/writer/CSVConfigGuesser.java@@ -21,8 +21,7 @@ package org.apache.solr.internal.csv.writer;import java.io.BufferedReader;import java.io.InputStream;import java.io.InputStreamReader;--import org.apache.lucene.util.IOUtils;+import java.nio.charset.StandardCharsets;/*** Tries to guess a config based on an InputStream.@@ -76,7 +75,7 @@ public class CSVConfigGuesser {public CSVConfig guess() {try {// tralalal- BufferedReader bIn = new BufferedReader(new InputStreamReader(getInputStream(), IOUtils.CHARSET_UTF_8));+ BufferedReader bIn = new BufferedReader(new InputStreamReader(getInputStream(), StandardCharsets.UTF_8));String[] lines = new String[10];String line = null;int counter = 0;diff --git a/solr/core/src/java/org/apache/solr/rest/BaseSolrResource.java b/solr/core/src/java/org/apache/solr/rest/BaseSolrResource.javaindex e22f1da79c5..845a5c1b4b0 100644--- a/solr/core/src/java/org/apache/solr/rest/BaseSolrResource.java+++ b/solr/core/src/java/org/apache/solr/rest/BaseSolrResource.java@@ -45,13 +45,14 @@ import java.io.UnsupportedEncodingException;import java.io.Writer;import java.net.URLDecoder;import java.nio.charset.Charset;+import java.nio.charset.StandardCharsets;/*** Base class of all Solr Restlet server resource classes.*/public abstract class BaseSolrResource extends ServerResource {- protected static final Charset UTF8 = Charset.forName("UTF-8");+ protected static final Charset UTF8 = StandardCharsets.UTF_8;protected static final String SHOW_DEFAULTS = "showDefaults";private SolrCore solrCore;diff --git a/solr/core/src/java/org/apache/solr/rest/ManagedResourceStorage.java b/solr/core/src/java/org/apache/solr/rest/ManagedResourceStorage.javaindex e4218ca2348..e10b8a29c3e 100644--- a/solr/core/src/java/org/apache/solr/rest/ManagedResourceStorage.java+++ b/solr/core/src/java/org/apache/solr/rest/ManagedResourceStorage.java@@ -29,6 +29,7 @@ import java.io.OutputStream;import java.io.OutputStreamWriter;import java.io.Reader;import java.nio.charset.Charset;+import java.nio.charset.StandardCharsets;import java.util.HashMap;import java.util.Locale;import java.util.Map;@@ -419,7 +420,7 @@ public abstract class ManagedResourceStorage {public static final Logger log = LoggerFactory.getLogger(ManagedResourceStorage.class);- public static final Charset UTF_8 = Charset.forName("UTF-8");+ public static final Charset UTF_8 = StandardCharsets.UTF_8;protected StorageIO storageIO;protected SolrResourceLoader loader;diff --git a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.javaindex fc44e39c32a..43a312744b3 100644--- a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java+++ b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java@@ -33,11 +33,13 @@ import org.w3c.dom.Document;import org.xml.sax.InputSource;import javax.xml.xpath.XPath;+import java.io.File;import java.io.FileOutputStream;import java.io.IOException;import java.io.OutputStreamWriter;import java.io.StringWriter;+import java.nio.charset.StandardCharsets;import java.util.Arrays;import java.util.Collection;import java.util.Collections;@@ -92,7 +94,7 @@ public final class ManagedIndexSchema extends IndexSchema {}}final FileOutputStream out = new FileOutputStream(managedSchemaFile);- writer = new OutputStreamWriter(out, "UTF-8");+ writer = new OutputStreamWriter(out, StandardCharsets.UTF_8);persist(writer);log.info("Upgraded to managed schema at " + managedSchemaFile.getPath());} catch (IOException e) {@@ -132,7 +134,7 @@ public final class ManagedIndexSchema extends IndexSchema {StringWriter writer = new StringWriter();persist(writer);- final byte[] data = writer.toString().getBytes("UTF-8");+ final byte[] data = writer.toString().getBytes(StandardCharsets.UTF_8);if (createOnly) {try {zkClient.create(managedSchemaPath, data, CreateMode.PERSISTENT, true);diff --git a/solr/core/src/java/org/apache/solr/schema/OpenExchangeRatesOrgProvider.java b/solr/core/src/java/org/apache/solr/schema/OpenExchangeRatesOrgProvider.javaindex c82266c391b..e6927cefef4 100644--- a/solr/core/src/java/org/apache/solr/schema/OpenExchangeRatesOrgProvider.java+++ b/solr/core/src/java/org/apache/solr/schema/OpenExchangeRatesOrgProvider.java@@ -20,13 +20,13 @@ import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.net.URL;+import java.nio.charset.StandardCharsets;import java.util.HashMap;import java.util.Map;import java.util.Set;import org.noggit.JSONParser;import org.apache.lucene.analysis.util.ResourceLoader;-import org.apache.lucene.util.IOUtils;import org.apache.solr.common.SolrException;import org.apache.solr.common.SolrException.ErrorCode;import org.slf4j.Logger;@@ -202,7 +202,7 @@ public class OpenExchangeRatesOrgProvider implements ExchangeRateProvider {private JSONParser parser;public OpenExchangeRates(InputStream ratesStream) throws IOException {- parser = new JSONParser(new InputStreamReader(ratesStream, IOUtils.CHARSET_UTF_8));+ parser = new JSONParser(new InputStreamReader(ratesStream, StandardCharsets.UTF_8));rates = new HashMap<>();int ev;diff --git a/solr/core/src/java/org/apache/solr/search/function/FileFloatSource.java b/solr/core/src/java/org/apache/solr/search/function/FileFloatSource.javaindex a2c1acc2e75..0f8c14c40a6 100644--- a/solr/core/src/java/org/apache/solr/search/function/FileFloatSource.java+++ b/solr/core/src/java/org/apache/solr/search/function/FileFloatSource.java@@ -22,7 +22,6 @@ import org.apache.lucene.queries.function.ValueSource;import org.apache.lucene.queries.function.docvalues.FloatDocValues;import org.apache.lucene.search.DocIdSetIterator;import org.apache.lucene.util.BytesRef;-import org.apache.lucene.util.IOUtils;import org.apache.solr.core.SolrCore;import org.apache.solr.handler.RequestHandlerBase;import org.apache.solr.handler.RequestHandlerUtils;@@ -39,6 +38,7 @@ import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;+import java.nio.charset.StandardCharsets;import java.util.*;/**@@ -252,7 +252,7 @@ public class FileFloatSource extends ValueSource {return vals;}- BufferedReader r = new BufferedReader(new InputStreamReader(is, IOUtils.CHARSET_UTF_8));+ BufferedReader r = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));String idName = ffs.keyField.getName();FieldType idType = ffs.keyField.getType();diff --git a/solr/core/src/java/org/apache/solr/servlet/LoadAdminUiServlet.java b/solr/core/src/java/org/apache/solr/servlet/LoadAdminUiServlet.javaindex beb95aa92a4..196e9f3fb25 100644--- a/solr/core/src/java/org/apache/solr/servlet/LoadAdminUiServlet.java+++ b/solr/core/src/java/org/apache/solr/servlet/LoadAdminUiServlet.java@@ -21,6 +21,7 @@ import java.io.InputStream;import java.io.IOException;import java.io.OutputStreamWriter;import java.io.Writer;+import java.nio.charset.StandardCharsets;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;@@ -51,7 +52,7 @@ public final class LoadAdminUiServlet extends HttpServlet {try {response.setCharacterEncoding("UTF-8");response.setContentType("text/html");- Writer out = new OutputStreamWriter(response.getOutputStream(), "UTF-8");+ Writer out = new OutputStreamWriter(response.getOutputStream(), StandardCharsets.UTF_8);String html = IOUtils.toString(in, "UTF-8");Package pack = SolrCore.class.getPackage();diff --git a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.javaindex ad1fa3755b1..cb7a50aed8f 100644--- a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java+++ b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java@@ -81,6 +81,7 @@ import javax.servlet.ServletRequest;import javax.servlet.ServletResponse;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;+import java.io.ByteArrayInputStream;import java.io.IOException;import java.io.InputStream;@@ -89,6 +90,7 @@ import java.io.OutputStreamWriter;import java.io.Writer;import java.net.URL;import java.nio.charset.Charset;+import java.nio.charset.StandardCharsets;import java.util.ArrayList;import java.util.Collection;import java.util.Collections;@@ -119,7 +121,7 @@ public class SolrDispatchFilter implements Filterprotected String abortErrorMessage = null;protected final HttpClient httpClient = HttpClientUtil.createClient(new ModifiableSolrParams());- private static final Charset UTF8 = Charset.forName("UTF-8");+ private static final Charset UTF8 = StandardCharsets.UTF_8;public SolrDispatchFilter() {try {diff --git a/solr/core/src/java/org/apache/solr/servlet/SolrRequestParsers.java b/solr/core/src/java/org/apache/solr/servlet/SolrRequestParsers.javaindex f4eccf47cd0..f3fa91d78c8 100644--- a/solr/core/src/java/org/apache/solr/servlet/SolrRequestParsers.java+++ b/solr/core/src/java/org/apache/solr/servlet/SolrRequestParsers.java@@ -27,6 +27,7 @@ import java.nio.charset.CharacterCodingException;import java.nio.charset.Charset;import java.nio.charset.CharsetDecoder;import java.nio.charset.CodingErrorAction;+import java.nio.charset.StandardCharsets;import java.util.ArrayList;import java.util.Arrays;import java.util.Collection;@@ -244,7 +245,7 @@ public class SolrRequestParsers}}};- parseFormDataContent(in, Long.MAX_VALUE, IOUtils.CHARSET_UTF_8, map, true);+ parseFormDataContent(in, Long.MAX_VALUE, StandardCharsets.UTF_8, map, true);} catch (IOException ioe) {throw new SolrException(ErrorCode.BAD_REQUEST, ioe);}@@ -598,7 +599,7 @@ public class SolrRequestParsers// get query String from request body, using the charset given in content-type:final String cs = ContentStreamBase.getCharsetFromContentType(req.getContentType());- final Charset charset = (cs == null) ? IOUtils.CHARSET_UTF_8 : Charset.forName(cs);+ final Charset charset = (cs == null) ? StandardCharsets.UTF_8 : Charset.forName(cs);InputStream in = null;try {in = req.getInputStream();diff --git a/solr/core/src/java/org/apache/solr/servlet/ZookeeperInfoServlet.java b/solr/core/src/java/org/apache/solr/servlet/ZookeeperInfoServlet.javaindex 917b5cd9c44..710160fbb8a 100644--- a/solr/core/src/java/org/apache/solr/servlet/ZookeeperInfoServlet.java+++ b/solr/core/src/java/org/apache/solr/servlet/ZookeeperInfoServlet.java@@ -18,10 +18,10 @@package org.apache.solr.servlet;import java.io.IOException;-import java.io.BufferedWriter;import java.io.OutputStreamWriter;import java.io.Writer;import java.net.URLEncoder;+import java.nio.charset.StandardCharsets;import java.util.Date;import java.util.List;@@ -31,9 +31,6 @@ import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.lucene.util.BytesRef;-import org.apache.lucene.util.IOUtils;-import org.noggit.CharArr;-import org.noggit.JSONWriter;import org.apache.solr.cloud.ZkController;import org.apache.solr.common.SolrException;import org.apache.solr.common.cloud.SolrZkClient;@@ -42,6 +39,8 @@ import org.apache.solr.core.CoreContainer;import org.apache.solr.util.FastWriter;import org.apache.zookeeper.KeeperException;import org.apache.zookeeper.data.Stat;+import org.noggit.CharArr;+import org.noggit.JSONWriter;import org.slf4j.Logger;import org.slf4j.LoggerFactory;@@ -96,7 +95,7 @@ public final class ZookeeperInfoServlet extends HttpServlet {response.setCharacterEncoding("UTF-8");response.setContentType("application/json");- Writer out = new FastWriter(new OutputStreamWriter(response.getOutputStream(), IOUtils.CHARSET_UTF_8));+ Writer out = new FastWriter(new OutputStreamWriter(response.getOutputStream(), StandardCharsets.UTF_8));ZKPrinter printer = new ZKPrinter(response, out, cores.getZkController(), addr);printer.detail = detail;diff --git a/solr/core/src/java/org/apache/solr/spelling/suggest/FileDictionaryFactory.java b/solr/core/src/java/org/apache/solr/spelling/suggest/FileDictionaryFactory.javaindex 986fe7ec64e..07ecb4334c2 100644--- a/solr/core/src/java/org/apache/solr/spelling/suggest/FileDictionaryFactory.java+++ b/solr/core/src/java/org/apache/solr/spelling/suggest/FileDictionaryFactory.java@@ -19,10 +19,10 @@ package org.apache.solr.spelling.suggest;import java.io.IOException;import java.io.InputStreamReader;+import java.nio.charset.StandardCharsets;import org.apache.lucene.search.spell.Dictionary;import org.apache.lucene.search.suggest.FileDictionary;-import org.apache.lucene.util.IOUtils;import org.apache.solr.core.SolrCore;import org.apache.solr.search.SolrIndexSearcher;@@ -53,7 +53,7 @@ public class FileDictionaryFactory extends DictionaryFactory {try {return new FileDictionary(new InputStreamReader(- core.getResourceLoader().openResource(sourceLocation), IOUtils.CHARSET_UTF_8), fieldDelimiter);+ core.getResourceLoader().openResource(sourceLocation), StandardCharsets.UTF_8), fieldDelimiter);} catch (IOException e) {throw new RuntimeException();}diff --git a/solr/core/src/java/org/apache/solr/spelling/suggest/Suggester.java b/solr/core/src/java/org/apache/solr/spelling/suggest/Suggester.javaindex 521bb94398f..8c1293a3680 100644--- a/solr/core/src/java/org/apache/solr/spelling/suggest/Suggester.java+++ b/solr/core/src/java/org/apache/solr/spelling/suggest/Suggester.java@@ -23,6 +23,7 @@ import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStreamReader;import java.io.UnsupportedEncodingException;+import java.nio.charset.StandardCharsets;import java.util.Collections;import java.util.List;@@ -131,7 +132,7 @@ public class Suggester extends SolrSpellChecker {} else {try {dictionary = new FileDictionary(new InputStreamReader(- core.getResourceLoader().openResource(sourceLocation), IOUtils.CHARSET_UTF_8));+ core.getResourceLoader().openResource(sourceLocation), StandardCharsets.UTF_8));} catch (UnsupportedEncodingException e) {// should not happenLOG.error("should not happen", e);diff --git a/solr/core/src/java/org/apache/solr/spelling/suggest/fst/FreeTextLookupFactory.java b/solr/core/src/java/org/apache/solr/spelling/suggest/fst/FreeTextLookupFactory.javaindex 2ec64523753..730a2ba417d 100644--- a/solr/core/src/java/org/apache/solr/spelling/suggest/fst/FreeTextLookupFactory.java+++ b/solr/core/src/java/org/apache/solr/spelling/suggest/fst/FreeTextLookupFactory.java@@ -1,9 +1,10 @@package org.apache.solr.spelling.suggest.fst;+import java.nio.charset.StandardCharsets;+import org.apache.lucene.analysis.Analyzer;import org.apache.lucene.search.suggest.Lookup;import org.apache.lucene.search.suggest.analyzing.FreeTextSuggester;-import org.apache.lucene.util.IOUtils;import org.apache.solr.common.util.NamedList;import org.apache.solr.core.SolrCore;import org.apache.solr.schema.FieldType;@@ -71,7 +72,7 @@ public class FreeTextLookupFactory extends LookupFactory {: FreeTextSuggester.DEFAULT_GRAMS;byte separator = (params.get(SEPARATOR) != null)- ? params.get(SEPARATOR).toString().getBytes(IOUtils.CHARSET_UTF_8)[0]+ ? params.get(SEPARATOR).toString().getBytes(StandardCharsets.UTF_8)[0]: FreeTextSuggester.DEFAULT_SEPARATOR;return new FreeTextSuggester(indexAnalyzer, queryAnalyzer, grams, separator);diff --git a/solr/core/src/java/org/apache/solr/update/processor/MD5Signature.java b/solr/core/src/java/org/apache/solr/update/processor/MD5Signature.javaindex be849308c7b..02a0e2b223e 100644--- a/solr/core/src/java/org/apache/solr/update/processor/MD5Signature.java+++ b/solr/core/src/java/org/apache/solr/update/processor/MD5Signature.java@@ -17,6 +17,7 @@ package org.apache.solr.update.processor;*/import java.io.UnsupportedEncodingException;+import java.nio.charset.StandardCharsets;import java.security.MessageDigest;import java.security.NoSuchAlgorithmException;@@ -44,13 +45,7 @@ public class MD5Signature extends Signature {@Overridepublic void add(String content) {- try {- digester.update(content.getBytes("UTF-8"));- } catch (UnsupportedEncodingException e) {- // won't happen- log.error("UTF-8 not supported", e);- throw new RuntimeException(e);- }+ digester.update(content.getBytes(StandardCharsets.UTF_8));}@Overridediff --git a/solr/core/src/java/org/apache/solr/update/processor/StatelessScriptUpdateProcessorFactory.java b/solr/core/src/java/org/apache/solr/update/processor/StatelessScriptUpdateProcessorFactory.javaindex f330e63c34b..c634ec47ea1 100644--- a/solr/core/src/java/org/apache/solr/update/processor/StatelessScriptUpdateProcessorFactory.java+++ b/solr/core/src/java/org/apache/solr/update/processor/StatelessScriptUpdateProcessorFactory.java@@ -27,7 +27,6 @@ import org.apache.solr.request.LocalSolrQueryRequest;import org.apache.solr.response.SolrQueryResponse;import org.apache.solr.update.*;import org.apache.solr.util.plugin.SolrCoreAware;-import org.apache.commons.lang.StringUtils;import org.apache.commons.io.IOUtils;import org.apache.commons.io.FilenameUtils;@@ -41,6 +40,7 @@ import javax.script.ScriptException;import java.io.IOException;import java.io.InputStream;import java.io.Reader;+import java.nio.charset.StandardCharsets;import java.util.Set;import java.util.LinkedHashSet;import java.util.ArrayList;@@ -494,7 +494,7 @@ public class StatelessScriptUpdateProcessorFactory extends UpdateRequestProcessopublic Reader openReader(SolrResourceLoader resourceLoader) throws IOException {InputStream input = resourceLoader.openResource(fileName);return org.apache.lucene.util.IOUtils.getDecodingReader- (input, org.apache.lucene.util.IOUtils.CHARSET_UTF_8);+ (input, StandardCharsets.UTF_8);}}}diff --git a/solr/core/src/test/org/apache/solr/TestSolrCoreProperties.java b/solr/core/src/test/org/apache/solr/TestSolrCoreProperties.javaindex 2ebeca3225b..b063728a398 100644--- a/solr/core/src/test/org/apache/solr/TestSolrCoreProperties.java+++ b/solr/core/src/test/org/apache/solr/TestSolrCoreProperties.java@@ -26,12 +26,11 @@ import org.apache.lucene.util.IOUtils;import org.apache.solr.client.solrj.response.QueryResponse;import org.apache.solr.common.params.SolrParams;import org.apache.solr.common.util.NamedList;-import org.apache.commons.io.FileUtils;-import org.junit.BeforeClass;import java.io.*;+import java.nio.charset.StandardCharsets;import java.util.Properties;@@ -68,7 +67,7 @@ public class TestSolrCoreProperties extends SolrJettyTestBase {Properties p = new Properties();p.setProperty("foo.foo1", "f1");p.setProperty("foo.foo2", "f2");- Writer fos = new OutputStreamWriter(new FileOutputStream(new File(confDir, "solrcore.properties")), IOUtils.CHARSET_UTF_8);+ Writer fos = new OutputStreamWriter(new FileOutputStream(new File(confDir, "solrcore.properties")), StandardCharsets.UTF_8);p.store(fos, null);IOUtils.close(fos);diff --git a/solr/core/src/test/org/apache/solr/core/CoreContainerCoreInitFailuresTest.java b/solr/core/src/test/org/apache/solr/core/CoreContainerCoreInitFailuresTest.javaindex 3a9e9802ddb..18b68d8b0b9 100644--- a/solr/core/src/test/org/apache/solr/core/CoreContainerCoreInitFailuresTest.java+++ b/solr/core/src/test/org/apache/solr/core/CoreContainerCoreInitFailuresTest.java@@ -66,7 +66,7 @@ public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {// solr.xmlFile solrXml = new File(solrHome, "solr.xml");- FileUtils.write(solrXml, EMPTY_SOLR_XML, IOUtils.CHARSET_UTF_8.toString());+ FileUtils.write(solrXml, EMPTY_SOLR_XML, IOUtils.UTF_8);// ----// init the CoreContainer@@ -141,7 +141,7 @@ public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {// start with two collections: one valid, and one brokenFile solrXml = new File(solrHome, "solr.xml");- FileUtils.write(solrXml, BAD_SOLR_XML, IOUtils.CHARSET_UTF_8.toString());+ FileUtils.write(solrXml, BAD_SOLR_XML, IOUtils.UTF_8);// our "ok" collectionFileUtils.copyFile(getFile("solr/collection1/conf/solrconfig-defaults.xml"),@@ -280,7 +280,7 @@ public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {FileUtils.write(FileUtils.getFile(solrHome, "col_bad", "conf", "solrconfig.xml"),"This is giberish, not valid XML <",- IOUtils.CHARSET_UTF_8.toString());+ IOUtils.UTF_8);try {ignoreException(Pattern.quote("SAX"));diff --git a/solr/core/src/test/org/apache/solr/core/TestArbitraryIndexDir.java b/solr/core/src/test/org/apache/solr/core/TestArbitraryIndexDir.javaindex 9be2dca2a85..e050fc50577 100644--- a/solr/core/src/test/org/apache/solr/core/TestArbitraryIndexDir.java+++ b/solr/core/src/test/org/apache/solr/core/TestArbitraryIndexDir.java@@ -21,6 +21,7 @@ import java.io.FileOutputStream;import java.io.IOException;import java.io.OutputStreamWriter;import java.io.Writer;+import java.nio.charset.StandardCharsets;import java.util.Properties;import javax.xml.parsers.ParserConfigurationException;@@ -33,7 +34,6 @@ import org.apache.lucene.index.IndexWriter;import org.apache.lucene.index.IndexWriterConfig;import org.apache.lucene.store.Directory;import org.apache.lucene.util.IOUtils;-import org.apache.lucene.util.Version;import org.apache.solr.common.SolrException;import org.apache.solr.common.params.CommonParams;import org.apache.solr.handler.SnapPuller;@@ -105,7 +105,7 @@ public class TestArbitraryIndexDir extends AbstractSolrTestCase{p.put("index", newDir.getName());Writer os = null;try {- os = new OutputStreamWriter(new FileOutputStream(idxprops), IOUtils.CHARSET_UTF_8);+ os = new OutputStreamWriter(new FileOutputStream(idxprops), StandardCharsets.UTF_8);p.store(os, "index properties");} catch (Exception e) {throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,diff --git a/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java b/solr/core/src/test/org/apache/solr/core/TestCoreContainer.javaindex c65512f74f0..4a1cdf2d296 100644--- a/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java+++ b/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java@@ -18,7 +18,6 @@package org.apache.solr.core;import org.apache.commons.io.FileUtils;-import org.apache.lucene.util.IOUtils;import org.apache.lucene.util.TestUtil;import org.apache.solr.SolrTestCaseJ4;import org.apache.solr.handler.admin.CollectionsHandler;@@ -30,11 +29,13 @@ import org.junit.Test;import org.xml.sax.SAXException;import javax.xml.parsers.ParserConfigurationException;+import java.io.BufferedWriter;import java.io.File;import java.io.FileOutputStream;import java.io.IOException;import java.io.OutputStreamWriter;+import java.nio.charset.StandardCharsets;import java.util.ArrayList;import java.util.List;import java.util.jar.JarEntry;@@ -205,7 +206,7 @@ public class TestCoreContainer extends SolrTestCaseJ4 {assertTrue("Failed to mkdirs workDir", solrHomeDirectory.mkdirs());try {File solrXmlFile = new File(solrHomeDirectory, "solr.xml");- BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(solrXmlFile), IOUtils.CHARSET_UTF_8));+ BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(solrXmlFile), StandardCharsets.UTF_8));out.write(xmlFile);out.close();} catch (IOException e) {diff --git a/solr/core/src/test/org/apache/solr/core/TestCoreDiscovery.java b/solr/core/src/test/org/apache/solr/core/TestCoreDiscovery.javaindex 27deef4616c..70c24fcc02b 100644--- a/solr/core/src/test/org/apache/solr/core/TestCoreDiscovery.java+++ b/solr/core/src/test/org/apache/solr/core/TestCoreDiscovery.java@@ -29,6 +29,7 @@ import java.io.File;import java.io.FileOutputStream;import java.io.OutputStreamWriter;import java.io.Writer;+import java.nio.charset.StandardCharsets;import java.util.Properties;public class TestCoreDiscovery extends SolrTestCaseJ4 {@@ -52,7 +53,7 @@ public class TestCoreDiscovery extends SolrTestCaseJ4 {xmlStr = xmlStr.replace("<solr>", "<solr> <str name=\"coreRootDirectory\">" + alternateCoreDir + "</str> ");}File tmpFile = new File(solrHomeDirectory, ConfigSolr.SOLR_XML_FILE);- FileUtils.write(tmpFile, xmlStr, IOUtils.CHARSET_UTF_8.toString());+ FileUtils.write(tmpFile, xmlStr, IOUtils.UTF_8);}@@ -80,7 +81,7 @@ public class TestCoreDiscovery extends SolrTestCaseJ4 {private void addCoreWithProps(Properties stockProps, File propFile) throws Exception {if (!propFile.getParentFile().exists()) propFile.getParentFile().mkdirs();- Writer out = new OutputStreamWriter(new FileOutputStream(propFile), IOUtils.CHARSET_UTF_8);+ Writer out = new OutputStreamWriter(new FileOutputStream(propFile), StandardCharsets.UTF_8);try {stockProps.store(out, null);} finally {diff --git a/solr/core/src/test/org/apache/solr/core/TestSolrXmlPersistence.java b/solr/core/src/test/org/apache/solr/core/TestSolrXmlPersistence.javaindex fb21d6d8667..4be8a004732 100644--- a/solr/core/src/test/org/apache/solr/core/TestSolrXmlPersistence.java+++ b/solr/core/src/test/org/apache/solr/core/TestSolrXmlPersistence.java@@ -68,7 +68,7 @@ public class TestSolrXmlPersistence extends SolrTestCaseJ4 {}File solrXml = new File(solrHomeDirectory, "solr.xml");- FileUtils.write(solrXml, solrXmlString, IOUtils.CHARSET_UTF_8.toString());+ FileUtils.write(solrXml, solrXmlString, IOUtils.UTF_8);final CoreContainer cores = createCoreContainer(solrHomeDirectory.getAbsolutePath(), solrXmlString);return cores;diff --git a/solr/core/src/test/org/apache/solr/handler/DocumentAnalysisRequestHandlerTest.java b/solr/core/src/test/org/apache/solr/handler/DocumentAnalysisRequestHandlerTest.javaindex 5d909131449..c68fb718d79 100644--- a/solr/core/src/test/org/apache/solr/handler/DocumentAnalysisRequestHandlerTest.java+++ b/solr/core/src/test/org/apache/solr/handler/DocumentAnalysisRequestHandlerTest.java@@ -37,6 +37,7 @@ import java.io.ByteArrayInputStream;import java.io.InputStream;import java.io.IOException;import java.io.Reader;+import java.nio.charset.StandardCharsets;/*** A test for {@link DocumentAnalysisRequestHandler}.@@ -145,7 +146,7 @@ public class DocumentAnalysisRequestHandlerTest extends AnalysisRequestHandlerTe" <field name=\"id\">Müller</field>\r\n" +" </doc>" +"</docs>"- ).getBytes("ISO-8859-1");+ ).getBytes(StandardCharsets.ISO_8859_1);// we declare a content stream without charset:final ContentStream cs = new ByteStream(xmlBytes, "application/xml");@@ -177,7 +178,7 @@ public class DocumentAnalysisRequestHandlerTest extends AnalysisRequestHandlerTe" <field name=\"id\">Müller</field>\r\n" +" </doc>" +"</docs>"- ).getBytes("ISO-8859-1");+ ).getBytes(StandardCharsets.ISO_8859_1);// we declare a content stream with charset:final ContentStream cs = new ByteStream(xmlBytes, "application/xml; charset=ISO-8859-1");diff --git a/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminCreateDiscoverTest.java b/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminCreateDiscoverTest.javaindex 9f2d0bacf10..532245db27f 100644--- a/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminCreateDiscoverTest.java+++ b/solr/core/src/test/org/apache/solr/handler/admin/CoreAdminCreateDiscoverTest.java@@ -18,7 +18,6 @@package org.apache.solr.handler.admin;import org.apache.commons.io.FileUtils;-import org.apache.lucene.util.IOUtils;import org.apache.solr.SolrTestCaseJ4;import org.apache.solr.common.SolrException;import org.apache.solr.common.params.CoreAdminParams;@@ -33,6 +32,7 @@ import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStreamReader;+import java.nio.charset.StandardCharsets;import java.util.Properties;public class CoreAdminCreateDiscoverTest extends SolrTestCaseJ4 {@@ -115,7 +115,7 @@ public class CoreAdminCreateDiscoverTest extends SolrTestCaseJ4 {File propFile = new File(solrHomeDirectory, coreSysProps + "/" + CorePropertiesLocator.PROPERTIES_FILENAME);FileInputStream is = new FileInputStream(propFile);try {- props.load(new InputStreamReader(is, IOUtils.CHARSET_UTF_8));+ props.load(new InputStreamReader(is, StandardCharsets.UTF_8));} finally {org.apache.commons.io.IOUtils.closeQuietly(is);}@@ -257,7 +257,7 @@ public class CoreAdminCreateDiscoverTest extends SolrTestCaseJ4 {File propFile = new File(solrHomeDirectory, coreNormal + "/" + CorePropertiesLocator.PROPERTIES_FILENAME);FileInputStream is = new FileInputStream(propFile);try {- props.load(new InputStreamReader(is, IOUtils.CHARSET_UTF_8));+ props.load(new InputStreamReader(is, StandardCharsets.UTF_8));} finally {org.apache.commons.io.IOUtils.closeQuietly(is);}diff --git a/solr/core/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java b/solr/core/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.javaindex 6c398f385be..3347621843a 100644--- a/solr/core/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java+++ b/solr/core/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java@@ -19,7 +19,6 @@ package org.apache.solr.handler.component;import org.apache.lucene.index.IndexReader;import org.apache.lucene.util.BytesRef;-import org.apache.lucene.util.IOUtils;import org.apache.solr.SolrTestCaseJ4;import org.apache.solr.common.params.CommonParams;import org.apache.solr.common.params.GroupParams;@@ -38,6 +37,7 @@ import java.io.File;import java.io.FileOutputStream;import java.io.OutputStreamWriter;import java.io.PrintWriter;+import java.nio.charset.StandardCharsets;import java.util.HashMap;import java.util.Map;@@ -674,7 +674,7 @@ public class QueryElevationComponentTest extends SolrTestCaseJ4 {// write a test file to boost some docsprivate void writeFile(File file, String query, String... ids) throws Exception {- PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), IOUtils.CHARSET_UTF_8));+ PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8));out.println("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");out.println("<elevate>");out.println("<query text=\"" + query + "\">");diff --git a/solr/core/src/test/org/apache/solr/servlet/SolrRequestParserTest.java b/solr/core/src/test/org/apache/solr/servlet/SolrRequestParserTest.javaindex 2ee9f764d64..26e682b456f 100644--- a/solr/core/src/test/org/apache/solr/servlet/SolrRequestParserTest.java+++ b/solr/core/src/test/org/apache/solr/servlet/SolrRequestParserTest.java@@ -25,6 +25,7 @@ import java.io.ByteArrayInputStream;import java.net.HttpURLConnection;import java.net.SocketTimeoutException;import java.net.URL;+import java.nio.charset.StandardCharsets;import java.util.ArrayList;import java.util.Collections;import java.util.HashMap;@@ -207,7 +208,7 @@ public class SolrRequestParserTest extends SolrTestCaseJ4 {public void testStandardParseParamsAndFillStreams() throws Exception{final String getParams = "qt=%C3%BC&dup=foo", postParams = "q=hello&d%75p=bar";- final byte[] postBytes = postParams.getBytes("US-ASCII");+ final byte[] postBytes = postParams.getBytes(StandardCharsets.US_ASCII);// Set up the expected behaviorfinal String[] ct = new String[] {@@ -246,7 +247,7 @@ public class SolrRequestParserTest extends SolrTestCaseJ4 {public void testStandardParseParamsAndFillStreamsISO88591() throws Exception{final String getParams = "qt=%FC&dup=foo&ie=iso-8859-1&dup=%FC", postParams = "qt2=%FC&q=hello&d%75p=bar";- final byte[] postBytes = postParams.getBytes("US-ASCII");+ final byte[] postBytes = postParams.getBytes(StandardCharsets.US_ASCII);final String contentType = "application/x-www-form-urlencoded; charset=iso-8859-1";// Set up the expected behavior@@ -291,7 +292,7 @@ public class SolrRequestParserTest extends SolrTestCaseJ4 {expect(request.getContentLength()).andReturn(-1).anyTimes();expect(request.getQueryString()).andReturn(null).anyTimes();expect(request.getInputStream()).andReturn(new ServletInputStream() {- private final ByteArrayInputStream in = new ByteArrayInputStream(large.toString().getBytes("US-ASCII"));+ private final ByteArrayInputStream in = new ByteArrayInputStream(large.toString().getBytes(StandardCharsets.US_ASCII));@Override public int read() { return in.read(); }});replay(request);diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrServer.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrServer.javaindex dadc235773e..bd9d10cc39a 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrServer.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrServer.java@@ -19,6 +19,7 @@ package org.apache.solr.client.solrj.impl;import java.io.IOException;import java.io.OutputStream;+import java.nio.charset.StandardCharsets;import java.util.LinkedList;import java.util.Locale;import java.util.Queue;@@ -172,7 +173,7 @@ public class ConcurrentUpdateSolrServer extends SolrServer {public void writeTo(OutputStream out) throws IOException {try {if (isXml) {- out.write("<stream>".getBytes("UTF-8")); // can be anything+ out.write("<stream>".getBytes(StandardCharsets.UTF_8)); // can be anything}UpdateRequest req = updateRequest;while (req != null) {@@ -206,7 +207,7 @@ public class ConcurrentUpdateSolrServer extends SolrServer {req = queue.poll(pollQueueTime, TimeUnit.MILLISECONDS);}if (isXml) {- out.write("</stream>".getBytes("UTF-8"));+ out.write("</stream>".getBytes(StandardCharsets.UTF_8));}} catch (InterruptedException e) {diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.javaindex 040b20c829a..f0ecb991368 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java@@ -21,6 +21,7 @@ import java.io.InputStream;import java.net.ConnectException;import java.net.SocketTimeoutException;import java.nio.charset.Charset;+import java.nio.charset.StandardCharsets;import java.util.Collection;import java.util.Collections;import java.util.Iterator;@@ -78,7 +79,7 @@ import org.slf4j.Logger;import org.slf4j.LoggerFactory;public class HttpSolrServer extends SolrServer {- private static final String UTF_8 = "UTF-8";+ private static final String UTF_8 = StandardCharsets.UTF_8.name();private static final String DEFAULT_PATH = "/select";private static final long serialVersionUID = -946812319974801896L;diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java b/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.javaindex a2873e0c9c4..d8ea26859ed 100644--- a/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java@@ -22,6 +22,7 @@ import java.io.IOException;import java.io.StringReader;import java.io.StringWriter;import java.io.UnsupportedEncodingException;+import java.nio.charset.StandardCharsets;import java.util.List;import java.util.concurrent.atomic.AtomicLong;@@ -505,22 +506,17 @@ public class SolrZkClient {}string.append(dent + path + " (" + children.size() + ")" + NEWL);if (data != null) {- try {- String dataString = new String(data, "UTF-8");- if ((!path.endsWith(".txt") && !path.endsWith(".xml")) || path.endsWith(ZkStateReader.CLUSTER_STATE)) {- if (path.endsWith(".xml")) {- // this is the cluster state in xml format - lets pretty print- dataString = prettyPrint(dataString);- }-- string.append(dent + "DATA:\n" + dent + " "- + dataString.replaceAll("\n", "\n" + dent + " ") + NEWL);- } else {- string.append(dent + "DATA: ...supressed..." + NEWL);+ String dataString = new String(data, StandardCharsets.UTF_8);+ if ((!path.endsWith(".txt") && !path.endsWith(".xml")) || path.endsWith(ZkStateReader.CLUSTER_STATE)) {+ if (path.endsWith(".xml")) {+ // this is the cluster state in xml format - lets pretty print+ dataString = prettyPrint(dataString);}- } catch (UnsupportedEncodingException e) {- // can't happen - UTF-8- throw new RuntimeException(e);++ string.append(dent + "DATA:\n" + dent + " "+ + dataString.replaceAll("\n", "\n" + dent + " ") + NEWL);+ } else {+ string.append(dent + "DATA: ...supressed..." + NEWL);}}diff --git a/solr/solrj/src/java/org/apache/solr/common/util/ContentStreamBase.java b/solr/solrj/src/java/org/apache/solr/common/util/ContentStreamBase.javaindex d531b0faf33..34238b5f928 100644--- a/solr/solrj/src/java/org/apache/solr/common/util/ContentStreamBase.java+++ b/solr/solrj/src/java/org/apache/solr/common/util/ContentStreamBase.java@@ -27,6 +27,7 @@ import java.io.Reader;import java.io.StringReader;import java.net.URL;import java.net.URLConnection;+import java.nio.charset.StandardCharsets;import java.util.Locale;/**@@ -37,7 +38,7 @@ import java.util.Locale;*/public abstract class ContentStreamBase implements ContentStream{- public static final String DEFAULT_CHARSET = "utf-8";+ public static final String DEFAULT_CHARSET = StandardCharsets.UTF_8.name();protected String name;protected String sourceInfo;diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.javaindex 700d25da6f0..8ccc3e5d5ba 100644--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java@@ -314,7 +314,7 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {if (xmlStr == null) {xmlStr = "<solr></solr>";}- FileUtils.write(tmpFile, xmlStr, IOUtils.CHARSET_UTF_8.toString());+ FileUtils.write(tmpFile, xmlStr, IOUtils.UTF_8);SolrResourceLoader loader = new SolrResourceLoader(solrHome.getAbsolutePath());h = new TestHarness(loader, ConfigSolr.fromFile(loader, new File(solrHome, "solr.xml")));diff --git a/solr/test-framework/src/java/org/apache/solr/analysis/StringMockSolrResourceLoader.java b/solr/test-framework/src/java/org/apache/solr/analysis/StringMockSolrResourceLoader.javaindex 1df75eaacbc..bd2cec16d66 100644--- a/solr/test-framework/src/java/org/apache/solr/analysis/StringMockSolrResourceLoader.java+++ b/solr/test-framework/src/java/org/apache/solr/analysis/StringMockSolrResourceLoader.java@@ -20,6 +20,7 @@ package org.apache.solr.analysis;import java.io.ByteArrayInputStream;import java.io.IOException;import java.io.InputStream;+import java.nio.charset.StandardCharsets;import org.apache.lucene.analysis.util.ResourceLoader;@@ -51,6 +52,6 @@ class StringMockSolrResourceLoader implements ResourceLoader {@Overridepublic InputStream openResource(String resource) throws IOException {- return new ByteArrayInputStream(text.getBytes("UTF-8"));+ return new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8));}}diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/ZkTestServer.java b/solr/test-framework/src/java/org/apache/solr/cloud/ZkTestServer.javaindex c3cc399dd87..9a044a24477 100644--- a/solr/test-framework/src/java/org/apache/solr/cloud/ZkTestServer.java+++ b/solr/test-framework/src/java/org/apache/solr/cloud/ZkTestServer.java@@ -26,6 +26,7 @@ import java.net.InetAddress;import java.net.InetSocketAddress;import java.net.Socket;import java.net.UnknownHostException;+import java.nio.charset.StandardCharsets;import java.util.ArrayList;import java.util.List;@@ -314,7 +315,7 @@ public class ZkTestServer {BufferedReader reader = null;try {OutputStream outstream = sock.getOutputStream();- outstream.write(cmd.getBytes("US-ASCII"));+ outstream.write(cmd.getBytes(StandardCharsets.US_ASCII));outstream.flush();// this replicates NC - close the output stream before readingsock.shutdownOutput();