Skip to content

Commit c1affcf

Browse files
committed
Rename ESBytesRef to XBytesRef
1 parent 240fbdb commit c1affcf

File tree

9 files changed

+20
-16
lines changed

9 files changed

+20
-16
lines changed

libs/x-content/impl/src/main/java/org/elasticsearch/xcontent/provider/json/ESJsonFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public class ESJsonFactory extends JsonFactory {
2626

2727
@Override
2828
protected JsonParser _createParser(byte[] data, int offset, int len, IOContext ctxt) throws IOException {
29-
3029
if (len > 0
3130
&& Feature.CHARSET_DETECTION.enabledIn(_factoryFeatures)
3231
&& Feature.CANONICALIZE_FIELD_NAMES.enabledIn(_factoryFeatures)) {
@@ -35,6 +34,7 @@ protected JsonParser _createParser(byte[] data, int offset, int len, IOContext c
3534
if (encoding == JsonEncoding.UTF8) {
3635
boolean invalidBom = false;
3736
int ptr = offset;
37+
// Skip over the BOM if present
3838
if ((data[ptr] & 0xFF) == 0xEF) {
3939
if (len < 3) {
4040
invalidBom = true;

libs/x-content/impl/src/main/java/org/elasticsearch/xcontent/provider/json/ESJsonFactoryBuilder.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
public class ESJsonFactoryBuilder extends JsonFactoryBuilder {
1616
@Override
1717
public JsonFactory build() {
18-
// 28-Dec-2017, tatu: No special settings beyond base class ones, so:
1918
return new ESJsonFactory(this);
2019
}
2120
}

libs/x-content/impl/src/main/java/org/elasticsearch/xcontent/provider/json/ESUTF8StreamJsonParser.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import com.fasterxml.jackson.core.json.UTF8StreamJsonParser;
1717
import com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer;
1818

19-
import org.elasticsearch.xcontent.ESBytesRef;
19+
import org.elasticsearch.xcontent.XBytesRef;
2020

2121
import java.io.IOException;
2222
import java.io.InputStream;
@@ -44,17 +44,17 @@ public ESUTF8StreamJsonParser(
4444
* This is only a best-effort attempt; if there is some reason the bytes cannot be retrieved, this method will return null.
4545
* Currently, this is only implemented for ascii-only strings that do not contain escaped characters.
4646
*/
47-
public ESBytesRef getValueAsByteRef() throws IOException {
47+
public XBytesRef getValueAsByteRef() throws IOException {
4848
if (_currToken == JsonToken.VALUE_STRING && _tokenIncomplete) {
4949
if (stringEnd > 0) {
50-
return new ESBytesRef(_inputBuffer, _inputPtr, stringEnd - 1);
50+
return new XBytesRef(_inputBuffer, _inputPtr, stringEnd - 1);
5151
}
5252
return _finishAndReturnByteRef();
5353
}
5454
return null;
5555
}
5656

57-
protected ESBytesRef _finishAndReturnByteRef() throws IOException {
57+
protected XBytesRef _finishAndReturnByteRef() throws IOException {
5858
int ptr = _inputPtr;
5959
if (ptr >= _inputEnd) {
6060
_loadMoreGuaranteed();
@@ -70,7 +70,7 @@ protected ESBytesRef _finishAndReturnByteRef() throws IOException {
7070
if (codes[c] != 0) {
7171
if (c == INT_QUOTE) {
7272
stringEnd = ptr + 1;
73-
return new ESBytesRef(inputBuffer, startPtr, ptr);
73+
return new XBytesRef(inputBuffer, startPtr, ptr);
7474
}
7575
return null;
7676
}

libs/x-content/impl/src/main/java/org/elasticsearch/xcontent/provider/json/JsonXContentParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import com.fasterxml.jackson.core.io.JsonEOFException;
1919

2020
import org.elasticsearch.core.IOUtils;
21-
import org.elasticsearch.xcontent.ESBytesRef;
21+
import org.elasticsearch.xcontent.XBytesRef;
2222
import org.elasticsearch.xcontent.XContentEOFException;
2323
import org.elasticsearch.xcontent.XContentLocation;
2424
import org.elasticsearch.xcontent.XContentParseException;
@@ -117,7 +117,7 @@ public String text() throws IOException {
117117
}
118118

119119
@Override
120-
public ESBytesRef textRefOrNull() throws IOException {
120+
public XBytesRef textRefOrNull() throws IOException {
121121
if (currentToken().isValue() == false) {
122122
return null;
123123
}

libs/x-content/src/main/java/org/elasticsearch/xcontent/FilterXContentParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public String textOrNull() throws IOException {
101101
}
102102

103103
@Override
104-
public ESBytesRef textRefOrNull() throws IOException {
104+
public XBytesRef textRefOrNull() throws IOException {
105105
return delegate().textRefOrNull();
106106
}
107107

libs/x-content/src/main/java/org/elasticsearch/xcontent/ESBytesRef.java renamed to libs/x-content/src/main/java/org/elasticsearch/xcontent/XBytesRef.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99

1010
package org.elasticsearch.xcontent;
1111

12-
public record ESBytesRef(byte[] bytes, int start, int end) {}
12+
public record XBytesRef(byte[] bytes, int start, int end) {}

libs/x-content/src/main/java/org/elasticsearch/xcontent/XContentParser.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,12 @@ <T> Map<String, T> map(Supplier<Map<String, T>> mapFactory, CheckedFunction<XCon
109109

110110
String textOrNull() throws IOException;
111111

112-
default ESBytesRef textRefOrNull() throws IOException {
112+
/**
113+
* Returns a {@link XBytesRef} containing UTF-8 bytes, if possible.
114+
* This is only a best-effort attempt; if there is some reason the bytes cannot be retrieved, this method will return null.
115+
* In this case, use {@link #textOrNull()} to get the string-encoded value.
116+
*/
117+
default XBytesRef textRefOrNull() throws IOException {
113118
return null;
114119
}
115120

server/src/main/java/org/elasticsearch/index/mapper/CompletionFieldMapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
import org.elasticsearch.search.suggest.completion.context.ContextMapping;
3131
import org.elasticsearch.search.suggest.completion.context.ContextMappings;
3232
import org.elasticsearch.xcontent.DeprecationHandler;
33-
import org.elasticsearch.xcontent.ESBytesRef;
3433
import org.elasticsearch.xcontent.FilterXContentParser;
3534
import org.elasticsearch.xcontent.NamedXContentRegistry;
3635
import org.elasticsearch.xcontent.ToXContent;
36+
import org.elasticsearch.xcontent.XBytesRef;
3737
import org.elasticsearch.xcontent.XContentLocation;
3838
import org.elasticsearch.xcontent.XContentParser;
3939
import org.elasticsearch.xcontent.XContentParser.NumberType;
@@ -709,7 +709,7 @@ public Token currentToken() {
709709
}
710710

711711
@Override
712-
public ESBytesRef textRefOrNull() throws IOException {
712+
public XBytesRef textRefOrNull() throws IOException {
713713
if (parsingObject == false) {
714714
return null;
715715
}

server/src/main/java/org/elasticsearch/index/mapper/DotExpandingXContentParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
package org.elasticsearch.index.mapper;
1111

1212
import org.elasticsearch.core.CheckedFunction;
13-
import org.elasticsearch.xcontent.ESBytesRef;
1413
import org.elasticsearch.xcontent.FilterXContentParser;
1514
import org.elasticsearch.xcontent.FilterXContentParserWrapper;
15+
import org.elasticsearch.xcontent.XBytesRef;
1616
import org.elasticsearch.xcontent.XContentLocation;
1717
import org.elasticsearch.xcontent.XContentParser;
1818
import org.elasticsearch.xcontent.XContentSubParser;
@@ -381,7 +381,7 @@ public void skipChildren() throws IOException {
381381
}
382382

383383
@Override
384-
public ESBytesRef textRefOrNull() throws IOException {
384+
public XBytesRef textRefOrNull() throws IOException {
385385
if (state == State.EXPANDING_START_OBJECT) {
386386
throw new IllegalStateException("Can't get text on a " + currentToken() + " at " + getTokenLocation());
387387
}

0 commit comments

Comments
 (0)