mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 18:35:25 +00:00
lucene 4: XContentParser now has bytesOrNull and returns bytesref directly
This commit is contained in:
parent
479f1784e8
commit
c1a9c802f1
@ -23,6 +23,8 @@ import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -128,6 +130,10 @@ public interface XContentParser extends Closeable {
|
||||
String text() throws IOException;
|
||||
|
||||
String textOrNull() throws IOException;
|
||||
|
||||
BytesRef bytesOrNull(BytesRef spare) throws IOException;
|
||||
|
||||
BytesRef bytes(BytesRef spare) throws IOException;
|
||||
|
||||
boolean hasTextCharacters();
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package org.elasticsearch.common.xcontent.support;
|
||||
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.elasticsearch.common.Booleans;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
@ -105,6 +106,27 @@ public abstract class AbstractXContentParser implements XContentParser {
|
||||
}
|
||||
return text();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public BytesRef bytesOrNull(BytesRef spare) throws IOException {
|
||||
if (currentToken() == Token.VALUE_NULL) {
|
||||
return null;
|
||||
}
|
||||
return bytes(spare);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BytesRef bytes(BytesRef spare) throws IOException {
|
||||
// LUCENE 4 UPGRADE: we can possibly make this more efficient for now I just forward to text
|
||||
if (spare == null) {
|
||||
return new BytesRef(text());
|
||||
} else {
|
||||
spare.copyChars(text());
|
||||
return spare;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> map() throws IOException {
|
||||
|
Loading…
x
Reference in New Issue
Block a user