lucene 4: XContentParser now has bytesOrNull and returns bytesref directly

This commit is contained in:
Simon Willnauer 2012-10-28 09:58:35 +01:00 committed by Shay Banon
parent 479f1784e8
commit c1a9c802f1
2 changed files with 28 additions and 0 deletions

View File

@ -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();

View File

@ -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 {