Skip to content

Commit 18be4c0

Browse files
committed
Remove FastStringReader in favor of vanilla StringReader (#28944)
This allows us to remove another dependency in the decoupling of the XContent code. Rather than move this class over or decouple it, it can simply be removed. Relates tangentially to #28504
1 parent 7396fba commit 18be4c0

File tree

14 files changed

+24
-235
lines changed

14 files changed

+24
-235
lines changed

buildSrc/src/main/resources/forbidden/es-server-signatures.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ java.util.concurrent.Executors#privilegedThreadFactory()
2929
java.lang.Character#codePointBefore(char[],int) @ Implicit start offset is error-prone when the char[] is a buffer and the first chars are random chars
3030
java.lang.Character#codePointAt(char[],int) @ Implicit end offset is error-prone when the char[] is a buffer and the last chars are random chars
3131

32-
java.io.StringReader#<init>(java.lang.String) @ Use FastStringReader instead
33-
3432
@defaultMessage Reference management is tricky, leave it to SearcherManager
3533
org.apache.lucene.index.IndexReader#decRef()
3634
org.apache.lucene.index.IndexReader#incRef()

modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MustacheScriptEngine.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
import com.github.mustachejava.Mustache;
2222
import com.github.mustachejava.MustacheFactory;
2323

24+
import java.io.StringReader;
2425
import org.apache.logging.log4j.Logger;
2526
import org.apache.logging.log4j.message.ParameterizedMessage;
2627
import org.apache.logging.log4j.util.Supplier;
2728
import org.elasticsearch.SpecialPermission;
28-
import org.elasticsearch.common.io.FastStringReader;
2929
import org.elasticsearch.common.logging.ESLoggerFactory;
3030
import org.elasticsearch.script.GeneralScriptException;
3131
import org.elasticsearch.script.Script;
@@ -65,7 +65,7 @@ public <T> T compile(String templateName, String templateSource, ScriptContext<T
6565
throw new IllegalArgumentException("mustache engine does not know how to handle context [" + context.name + "]");
6666
}
6767
final MustacheFactory factory = createMustacheFactory(options);
68-
Reader reader = new FastStringReader(templateSource);
68+
Reader reader = new StringReader(templateSource);
6969
Mustache template = factory.compile(reader, "query-template");
7070
TemplateScript.Factory compiled = params -> new MustacheExecutableScript(template, params);
7171
return context.factoryClazz.cast(compiled);

server/src/main/java/org/elasticsearch/action/admin/indices/analyze/TransportAnalyzeAction.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import org.elasticsearch.common.UUIDs;
4242
import org.elasticsearch.common.collect.Tuple;
4343
import org.elasticsearch.common.inject.Inject;
44-
import org.elasticsearch.common.io.FastStringReader;
4544
import org.elasticsearch.common.settings.Settings;
4645
import org.elasticsearch.env.Environment;
4746
import org.elasticsearch.index.IndexService;
@@ -66,6 +65,7 @@
6665

6766
import java.io.IOException;
6867
import java.io.Reader;
68+
import java.io.StringReader;
6969
import java.util.ArrayList;
7070
import java.util.HashSet;
7171
import java.util.List;
@@ -315,12 +315,12 @@ private static DetailAnalyzeResponse detailAnalyze(AnalyzeRequest request, Analy
315315
for (int textIndex = 0; textIndex < request.text().length; textIndex++) {
316316
String charFilteredSource = request.text()[textIndex];
317317

318-
Reader reader = new FastStringReader(charFilteredSource);
318+
Reader reader = new StringReader(charFilteredSource);
319319
if (charFilterFactories != null) {
320320

321321
for (int charFilterIndex = 0; charFilterIndex < charFilterFactories.length; charFilterIndex++) {
322322
reader = charFilterFactories[charFilterIndex].create(reader);
323-
Reader readerForWriteOut = new FastStringReader(charFilteredSource);
323+
Reader readerForWriteOut = new StringReader(charFilteredSource);
324324
readerForWriteOut = charFilterFactories[charFilterIndex].create(readerForWriteOut);
325325
charFilteredSource = writeCharStream(readerForWriteOut);
326326
charFiltersTexts[charFilterIndex][textIndex] = charFilteredSource;
@@ -380,7 +380,7 @@ private static DetailAnalyzeResponse detailAnalyze(AnalyzeRequest request, Analy
380380
}
381381

382382
private static TokenStream createStackedTokenStream(String source, CharFilterFactory[] charFilterFactories, TokenizerFactory tokenizerFactory, TokenFilterFactory[] tokenFilterFactories, int current) {
383-
Reader reader = new FastStringReader(source);
383+
Reader reader = new StringReader(source);
384384
for (CharFilterFactory charFilterFactory : charFilterFactories) {
385385
reader = charFilterFactory.create(reader);
386386
}

server/src/main/java/org/elasticsearch/common/Strings.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
import org.elasticsearch.ElasticsearchException;
2424
import org.elasticsearch.ExceptionsHelper;
2525
import org.elasticsearch.common.bytes.BytesReference;
26-
import org.elasticsearch.common.io.FastStringReader;
2726
import org.elasticsearch.common.util.CollectionUtils;
2827
import org.elasticsearch.common.xcontent.ToXContent;
2928
import org.elasticsearch.common.xcontent.XContentBuilder;
3029
import org.elasticsearch.common.xcontent.json.JsonXContent;
3130

3231
import java.io.BufferedReader;
3332
import java.io.IOException;
33+
import java.io.StringReader;
3434
import java.util.ArrayList;
3535
import java.util.Arrays;
3636
import java.util.Collection;
@@ -51,7 +51,7 @@ public class Strings {
5151
public static final String[] EMPTY_ARRAY = new String[0];
5252

5353
public static void spaceify(int spaces, String from, StringBuilder to) throws Exception {
54-
try (BufferedReader reader = new BufferedReader(new FastStringReader(from))) {
54+
try (BufferedReader reader = new BufferedReader(new StringReader(from))) {
5555
String line;
5656
while ((line = reader.readLine()) != null) {
5757
for (int i = 0; i < spaces; i++) {

server/src/main/java/org/elasticsearch/common/geo/parsers/GeoWKTParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.elasticsearch.ElasticsearchParseException;
2323
import org.elasticsearch.common.geo.GeoShapeType;
2424

25+
import java.io.StringReader;
2526
import org.elasticsearch.common.geo.builders.CoordinatesBuilder;
2627
import org.elasticsearch.common.geo.builders.EnvelopeBuilder;
2728
import org.elasticsearch.common.geo.builders.GeometryCollectionBuilder;
@@ -32,7 +33,6 @@
3233
import org.elasticsearch.common.geo.builders.PointBuilder;
3334
import org.elasticsearch.common.geo.builders.PolygonBuilder;
3435
import org.elasticsearch.common.geo.builders.ShapeBuilder;
35-
import org.elasticsearch.common.io.FastStringReader;
3636
import org.elasticsearch.common.logging.Loggers;
3737
import org.elasticsearch.common.xcontent.XContentParser;
3838

@@ -69,7 +69,7 @@ public static ShapeBuilder parse(XContentParser parser)
6969
/** throws an exception if the parsed geometry type does not match the expected shape type */
7070
public static ShapeBuilder parseExpectedType(XContentParser parser, final GeoShapeType shapeType)
7171
throws IOException, ElasticsearchParseException {
72-
FastStringReader reader = new FastStringReader(parser.text());
72+
StringReader reader = new StringReader(parser.text());
7373
try {
7474
// setup the tokenizer; configured to read words w/o numbers
7575
StreamTokenizer tokenizer = new StreamTokenizer(reader);

server/src/main/java/org/elasticsearch/common/io/FastStringReader.java

Lines changed: 0 additions & 208 deletions
This file was deleted.

server/src/main/java/org/elasticsearch/common/lucene/search/MoreLikeThisQuery.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
import org.apache.lucene.search.similarities.TFIDFSimilarity;
3636
import org.apache.lucene.util.BytesRef;
3737
import org.elasticsearch.common.Strings;
38-
import org.elasticsearch.common.io.FastStringReader;
3938

4039
import java.io.IOException;
4140
import java.io.Reader;
41+
import java.io.StringReader;
4242
import java.util.Arrays;
4343
import java.util.HashSet;
4444
import java.util.List;
@@ -166,7 +166,7 @@ private Query createQuery(XMoreLikeThis mlt) throws IOException {
166166
if (this.likeText != null) {
167167
Reader[] readers = new Reader[likeText.length];
168168
for (int i = 0; i < readers.length; i++) {
169-
readers[i] = new FastStringReader(likeText[i]);
169+
readers[i] = new StringReader(likeText[i]);
170170
}
171171
//LUCENE 4 UPGRADE this mapps the 3.6 behavior (only use the first field)
172172
Query mltQuery = mlt.like(moreLikeFields[0], readers);

server/src/main/java/org/elasticsearch/common/lucene/search/XMoreLikeThis.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@
5858
import org.apache.lucene.util.CharsRefBuilder;
5959
import org.apache.lucene.util.PriorityQueue;
6060
import org.elasticsearch.common.Nullable;
61-
import org.elasticsearch.common.io.FastStringReader;
6261

6362
import java.io.IOException;
6463
import java.io.Reader;
64+
import java.io.StringReader;
6565
import java.util.ArrayList;
6666
import java.util.Collection;
6767
import java.util.HashMap;
@@ -815,7 +815,7 @@ private PriorityQueue<ScoreTerm> retrieveTerms(int docNum) throws IOException {
815815
for (IndexableField field : fields) {
816816
final String stringValue = field.stringValue();
817817
if (stringValue != null) {
818-
addTermFrequencies(new FastStringReader(stringValue), termFreqMap, fieldName);
818+
addTermFrequencies(new StringReader(stringValue), termFreqMap, fieldName);
819819
}
820820
}
821821
} else {

server/src/main/java/org/elasticsearch/common/xcontent/cbor/CborXContent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import com.fasterxml.jackson.core.JsonParser;
2525
import com.fasterxml.jackson.dataformat.cbor.CBORFactory;
2626
import org.elasticsearch.ElasticsearchParseException;
27-
import org.elasticsearch.common.io.FastStringReader;
2827
import org.elasticsearch.common.xcontent.DeprecationHandler;
2928
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
3029
import org.elasticsearch.common.xcontent.XContent;
@@ -37,6 +36,7 @@
3736
import java.io.InputStream;
3837
import java.io.OutputStream;
3938
import java.io.Reader;
39+
import java.io.StringReader;
4040
import java.util.Set;
4141

4242
/**
@@ -81,7 +81,7 @@ public XContentGenerator createGenerator(OutputStream os, Set<String> includes,
8181
@Override
8282
public XContentParser createParser(NamedXContentRegistry xContentRegistry,
8383
DeprecationHandler deprecationHandler, String content) throws IOException {
84-
return new CborXContentParser(xContentRegistry, deprecationHandler, cborFactory.createParser(new FastStringReader(content)));
84+
return new CborXContentParser(xContentRegistry, deprecationHandler, cborFactory.createParser(new StringReader(content)));
8585
}
8686

8787
@Override

0 commit comments

Comments
 (0)