From 2d1d6503a4d034acd89e5fe31f03e39513976056 Mon Sep 17 00:00:00 2001 From: Lee Hinman Date: Wed, 7 Mar 2018 10:09:56 -0700 Subject: [PATCH 1/3] Remove BytesRef usage from XContentParser and its subclasses (#28792) * Remove BytesRef usage from XContentParser and its subclasses This removes all the BytesRef usage from XContentParser in favor of directly returning a CharBuffer (this was originally what was returned, it was just immediately wraped in a BytesRef). Relates to #28504 * Rename method after Ryan's feedback --- .../common/xcontent/XContentBuilder.java | 4 +-- .../common/xcontent/XContentParser.java | 14 +++----- .../xcontent/json/JsonXContentParser.java | 10 +++--- .../support/AbstractXContentParser.java | 7 ++-- .../index/query/AbstractQueryBuilder.java | 19 +++++++---- .../index/query/BaseTermQueryBuilder.java | 6 ++-- .../index/query/FuzzyQueryBuilder.java | 12 +++---- .../index/query/RangeQueryBuilder.java | 24 +++++++------- .../index/query/SpanTermQueryBuilder.java | 6 ++-- .../index/query/TermQueryBuilder.java | 6 ++-- .../index/query/TermsQueryBuilder.java | 16 ++++++---- .../index/query/TypeQueryBuilder.java | 32 ++++++++++--------- .../ParsedSignificantStringTerms.java | 10 +++++- .../bucket/terms/ParsedStringTerms.java | 10 +++++- .../common/xcontent/BaseXContentTestCase.java | 4 +-- .../cbor/CborXContentParserTests.java | 2 +- 16 files changed, 100 insertions(+), 82 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java b/server/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java index 9274bfbf345ae..e673c2a4b7ca2 100644 --- a/server/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java +++ b/server/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java @@ -593,7 +593,7 @@ public XContentBuilder field(String name, BytesRef value) throws IOException { /** * Writes the binary content of the given {@link BytesRef} as UTF-8 bytes. * - * Use {@link XContentParser#utf8Bytes()} to read the value back + * Use {@link XContentParser#charBuffer()} to read the value back */ public XContentBuilder utf8Field(String name, BytesRef value) throws IOException { return field(name).utf8Value(value); @@ -615,7 +615,7 @@ public XContentBuilder binaryValue(BytesRef value) throws IOException { /** * Writes the binary content of the given {@link BytesRef} as UTF-8 bytes. * - * Use {@link XContentParser#utf8Bytes()} to read the value back + * Use {@link XContentParser#charBuffer()} to read the value back */ public XContentBuilder utf8Value(BytesRef value) throws IOException { if (value == null) { diff --git a/server/src/main/java/org/elasticsearch/common/xcontent/XContentParser.java b/server/src/main/java/org/elasticsearch/common/xcontent/XContentParser.java index dbeb678f3afad..61272e46b2873 100644 --- a/server/src/main/java/org/elasticsearch/common/xcontent/XContentParser.java +++ b/server/src/main/java/org/elasticsearch/common/xcontent/XContentParser.java @@ -19,10 +19,10 @@ package org.elasticsearch.common.xcontent; -import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.lease.Releasable; import java.io.IOException; +import java.nio.CharBuffer; import java.util.List; import java.util.Map; @@ -144,17 +144,13 @@ enum NumberType { String textOrNull() throws IOException; - /** - * Returns a BytesRef holding UTF-8 bytes or null if a null value is {@link Token#VALUE_NULL}. - * This method should be used to read text only binary content should be read through {@link #binaryValue()} - */ - BytesRef utf8BytesOrNull() throws IOException; + CharBuffer charBufferOrNull() throws IOException; /** - * Returns a BytesRef holding UTF-8 bytes. + * Returns a {@link CharBuffer} holding UTF-8 bytes. * This method should be used to read text only binary content should be read through {@link #binaryValue()} */ - BytesRef utf8Bytes() throws IOException; + CharBuffer charBuffer() throws IOException; Object objectText() throws IOException; @@ -248,8 +244,6 @@ enum NumberType { * * these methods write UTF-8 encoded strings and must be read through: *