diff --git a/modules/percolator/src/main/java/org/elasticsearch/percolator/PercolateQueryBuilder.java b/modules/percolator/src/main/java/org/elasticsearch/percolator/PercolateQueryBuilder.java index a655184f89e7c..6ba8394e1e598 100644 --- a/modules/percolator/src/main/java/org/elasticsearch/percolator/PercolateQueryBuilder.java +++ b/modules/percolator/src/main/java/org/elasticsearch/percolator/PercolateQueryBuilder.java @@ -274,7 +274,7 @@ public PercolateQueryBuilder(String field, String documentType, String indexedDo } if (documents.isEmpty() == false) { if (in.getVersion().onOrAfter(Version.V_5_3_0)) { - documentXContentType = XContentType.readFrom(in); + documentXContentType = in.readEnum(XContentType.class); } else { documentXContentType = XContentFactory.xContentType(documents.iterator().next()); } @@ -331,7 +331,7 @@ protected void doWriteTo(StreamOutput out) throws IOException { out.writeOptionalBytesReference(doc); } if (documents.isEmpty() == false && out.getVersion().onOrAfter(Version.V_5_3_0)) { - documentXContentType.writeTo(out); + out.writeEnum(documentXContentType); } } diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/storedscripts/PutStoredScriptRequest.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/storedscripts/PutStoredScriptRequest.java index e3392df885075..5ab5c49d0c791 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/storedscripts/PutStoredScriptRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/storedscripts/PutStoredScriptRequest.java @@ -123,7 +123,7 @@ public void readFrom(StreamInput in) throws IOException { id = in.readOptionalString(); content = in.readBytesReference(); if (in.getVersion().onOrAfter(Version.V_5_3_0)) { - xContentType = XContentType.readFrom(in); + xContentType = in.readEnum(XContentType.class); } else { xContentType = XContentFactory.xContentType(content); } @@ -145,7 +145,7 @@ public void writeTo(StreamOutput out) throws IOException { out.writeOptionalString(id); out.writeBytesReference(content); if (out.getVersion().onOrAfter(Version.V_5_3_0)) { - xContentType.writeTo(out); + out.writeEnum(xContentType); } if (out.getVersion().onOrAfter(Version.V_6_0_0_alpha2)) { out.writeOptionalString(context); diff --git a/server/src/main/java/org/elasticsearch/action/index/IndexRequest.java b/server/src/main/java/org/elasticsearch/action/index/IndexRequest.java index 46d51ee0b40e4..f2ddca1955878 100644 --- a/server/src/main/java/org/elasticsearch/action/index/IndexRequest.java +++ b/server/src/main/java/org/elasticsearch/action/index/IndexRequest.java @@ -542,7 +542,11 @@ public void readFrom(StreamInput in) throws IOException { pipeline = in.readOptionalString(); isRetry = in.readBoolean(); autoGeneratedTimestamp = in.readLong(); - contentType = in.readOptionalWriteable(XContentType::readFrom); + if (in.readBoolean()) { + contentType = in.readEnum(XContentType.class); + } else { + contentType = null; + } } @Override @@ -566,7 +570,12 @@ public void writeTo(StreamOutput out) throws IOException { out.writeOptionalString(pipeline); out.writeBoolean(isRetry); out.writeLong(autoGeneratedTimestamp); - out.writeOptionalWriteable(contentType); + if (contentType != null) { + out.writeBoolean(true); + out.writeEnum(contentType); + } else { + out.writeBoolean(false); + } } @Override diff --git a/server/src/main/java/org/elasticsearch/action/ingest/PutPipelineRequest.java b/server/src/main/java/org/elasticsearch/action/ingest/PutPipelineRequest.java index 394349ca01691..10b19ed8cfa17 100644 --- a/server/src/main/java/org/elasticsearch/action/ingest/PutPipelineRequest.java +++ b/server/src/main/java/org/elasticsearch/action/ingest/PutPipelineRequest.java @@ -81,7 +81,7 @@ public void readFrom(StreamInput in) throws IOException { id = in.readString(); source = in.readBytesReference(); if (in.getVersion().onOrAfter(Version.V_5_3_0)) { - xContentType = XContentType.readFrom(in); + xContentType = in.readEnum(XContentType.class); } else { xContentType = XContentFactory.xContentType(source); } @@ -93,7 +93,7 @@ public void writeTo(StreamOutput out) throws IOException { out.writeString(id); out.writeBytesReference(source); if (out.getVersion().onOrAfter(Version.V_5_3_0)) { - xContentType.writeTo(out); + out.writeEnum(xContentType); } } } diff --git a/server/src/main/java/org/elasticsearch/action/ingest/SimulatePipelineRequest.java b/server/src/main/java/org/elasticsearch/action/ingest/SimulatePipelineRequest.java index 170f0bc8518cf..428df00a68e9c 100644 --- a/server/src/main/java/org/elasticsearch/action/ingest/SimulatePipelineRequest.java +++ b/server/src/main/java/org/elasticsearch/action/ingest/SimulatePipelineRequest.java @@ -76,7 +76,7 @@ public SimulatePipelineRequest(BytesReference source, XContentType xContentType) verbose = in.readBoolean(); source = in.readBytesReference(); if (in.getVersion().onOrAfter(Version.V_5_3_0)) { - xContentType = XContentType.readFrom(in); + xContentType = in.readEnum(XContentType.class); } else { xContentType = XContentFactory.xContentType(source); } @@ -123,7 +123,7 @@ public void writeTo(StreamOutput out) throws IOException { out.writeBoolean(verbose); out.writeBytesReference(source); if (out.getVersion().onOrAfter(Version.V_5_3_0)) { - xContentType.writeTo(out); + out.writeEnum(xContentType); } } diff --git a/server/src/main/java/org/elasticsearch/action/termvectors/TermVectorsRequest.java b/server/src/main/java/org/elasticsearch/action/termvectors/TermVectorsRequest.java index 9a26e63f1afd4..3aa7b832f1f4e 100644 --- a/server/src/main/java/org/elasticsearch/action/termvectors/TermVectorsRequest.java +++ b/server/src/main/java/org/elasticsearch/action/termvectors/TermVectorsRequest.java @@ -516,7 +516,7 @@ public void readFrom(StreamInput in) throws IOException { if (in.readBoolean()) { doc = in.readBytesReference(); if (in.getVersion().onOrAfter(Version.V_5_3_0)) { - xContentType = XContentType.readFrom(in); + xContentType = in.readEnum(XContentType.class); } else { xContentType = XContentFactory.xContentType(doc); } @@ -561,7 +561,7 @@ public void writeTo(StreamOutput out) throws IOException { if (doc != null) { out.writeBytesReference(doc); if (out.getVersion().onOrAfter(Version.V_5_3_0)) { - xContentType.writeTo(out); + out.writeEnum(xContentType); } } out.writeOptionalString(routing); 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..a9037b74ce9ed 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,9 @@ package org.elasticsearch.common.xcontent; -import org.apache.lucene.util.BytesRef; -import org.elasticsearch.common.lease.Releasable; - +import java.io.Closeable; import java.io.IOException; +import java.nio.CharBuffer; import java.util.List; import java.util.Map; @@ -37,7 +36,7 @@ * NamedXContentRegistry.EMPTY, ParserField."{\"key\" : \"value\"}"); * */ -public interface XContentParser extends Releasable { +public interface XContentParser extends Closeable { enum Token { START_OBJECT { @@ -144,17 +143,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 +243,6 @@ enum NumberType { * * these methods write UTF-8 encoded strings and must be read through: *