public final class XContentBuilder extends java.lang.Object implements Releasable, java.io.Flushable
Modifier and Type | Field and Description |
---|---|
static org.joda.time.format.DateTimeFormatter |
DEFAULT_DATE_PRINTER |
Constructor and Description |
---|
XContentBuilder(XContent xContent,
java.io.OutputStream bos)
Constructs a new builder using the provided XContent and an OutputStream.
|
XContentBuilder(XContent xContent,
java.io.OutputStream bos,
java.util.Set<java.lang.String> includes)
Constructs a new builder using the provided XContent, an OutputStream and
some filters.
|
XContentBuilder(XContent xContent,
java.io.OutputStream os,
java.util.Set<java.lang.String> includes,
java.util.Set<java.lang.String> excludes)
Creates a new builder using the provided XContent, output stream and some inclusive and/or exclusive filters.
|
Modifier and Type | Method and Description |
---|---|
XContentBuilder |
array(java.lang.String name,
boolean[] values) |
XContentBuilder |
array(java.lang.String name,
double[] values) |
XContentBuilder |
array(java.lang.String name,
float[] values) |
XContentBuilder |
array(java.lang.String name,
int[] values) |
XContentBuilder |
array(java.lang.String name,
long[] values) |
XContentBuilder |
array(java.lang.String name,
java.lang.Object... values) |
XContentBuilder |
array(java.lang.String name,
short[] values) |
XContentBuilder |
array(java.lang.String name,
java.lang.String... values) |
XContentBuilder |
binaryValue(org.apache.lucene.util.BytesRef value)
Writes the binary content of the given
BytesRef . |
static XContentBuilder |
builder(XContent xContent)
Create a new
XContentBuilder using the given XContent content. |
static XContentBuilder |
builder(XContent xContent,
java.util.Set<java.lang.String> includes,
java.util.Set<java.lang.String> excludes)
Create a new
XContentBuilder using the given XContent content and some inclusive and/or exclusive filters. |
BytesReference |
bytes() |
XContentBuilder |
byteSizeField(java.lang.String rawFieldName,
java.lang.String readableFieldName,
ByteSizeValue byteSizeValue) |
XContentBuilder |
byteSizeField(java.lang.String rawFieldName,
java.lang.String readableFieldName,
long rawSize) |
void |
close() |
XContentType |
contentType() |
XContentBuilder |
copyCurrentStructure(XContentParser parser) |
XContentBuilder |
dateField(java.lang.String name,
java.lang.String readableName,
long value) |
XContentBuilder |
endArray() |
XContentBuilder |
endObject() |
XContentBuilder |
field(java.lang.String name) |
XContentBuilder |
field(java.lang.String name,
boolean value) |
XContentBuilder |
field(java.lang.String name,
java.lang.Boolean value) |
XContentBuilder |
field(java.lang.String name,
byte value) |
XContentBuilder |
field(java.lang.String name,
java.lang.Byte value) |
XContentBuilder |
field(java.lang.String name,
byte[] value) |
XContentBuilder |
field(java.lang.String name,
byte[] value,
int offset,
int length) |
XContentBuilder |
field(java.lang.String name,
org.apache.lucene.util.BytesRef value)
Writes the binary content of the given
BytesRef . |
XContentBuilder |
field(java.lang.String name,
BytesReference value)
Writes the binary content of the given
BytesReference . |
XContentBuilder |
field(java.lang.String name,
java.util.Date value) |
XContentBuilder |
field(java.lang.String name,
java.util.Date value,
org.joda.time.format.DateTimeFormatter formatter) |
XContentBuilder |
field(java.lang.String name,
double value) |
XContentBuilder |
field(java.lang.String name,
java.lang.Double value) |
XContentBuilder |
field(java.lang.String name,
float value) |
XContentBuilder |
field(java.lang.String name,
java.lang.Float value) |
XContentBuilder |
field(java.lang.String name,
GeoPoint value) |
XContentBuilder |
field(java.lang.String name,
int value) |
XContentBuilder |
field(java.lang.String name,
java.lang.Integer value) |
XContentBuilder |
field(java.lang.String name,
java.lang.Iterable<?> values) |
XContentBuilder |
field(java.lang.String name,
long value) |
XContentBuilder |
field(java.lang.String name,
java.lang.Long value) |
XContentBuilder |
field(java.lang.String name,
java.util.Map<java.lang.String,java.lang.Object> values) |
XContentBuilder |
field(java.lang.String name,
java.lang.Object value) |
XContentBuilder |
field(java.lang.String name,
org.joda.time.ReadableInstant value) |
XContentBuilder |
field(java.lang.String name,
org.joda.time.ReadableInstant value,
org.joda.time.format.DateTimeFormatter formatter) |
XContentBuilder |
field(java.lang.String name,
short value) |
XContentBuilder |
field(java.lang.String name,
java.lang.Short value) |
XContentBuilder |
field(java.lang.String name,
java.lang.String value) |
XContentBuilder |
field(java.lang.String name,
Text value) |
XContentBuilder |
field(java.lang.String name,
ToXContent value) |
XContentBuilder |
field(java.lang.String name,
ToXContent value,
ToXContent.Params params) |
void |
flush() |
XContentGenerator |
generator() |
boolean |
humanReadable() |
XContentBuilder |
humanReadable(boolean humanReadable)
Set the "human readable" flag.
|
boolean |
isPrettyPrint() |
XContentBuilder |
latlon(double lat,
double lon) |
XContentBuilder |
latlon(java.lang.String name,
double lat,
double lon) |
XContentBuilder |
lfAtEnd()
Indicate that the current
XContentBuilder must write a line feed ("\n")
at the end of the built object. |
XContentBuilder |
map(java.util.Map<java.lang.String,?> values) |
XContentBuilder |
nullField(java.lang.String name) |
XContentBuilder |
nullValue() |
XContentBuilder |
percentageField(java.lang.String rawFieldName,
java.lang.String readableFieldName,
double percentage) |
XContentBuilder |
prettyPrint() |
XContentBuilder |
rawField(java.lang.String name,
BytesReference value)
Deprecated.
use
rawField(String name, BytesReference, XContentType) to avoid content type auto-detection |
XContentBuilder |
rawField(java.lang.String name,
BytesReference value,
XContentType contentType)
Writes a raw field with the given bytes as the value
|
XContentBuilder |
rawField(java.lang.String name,
java.io.InputStream value)
Deprecated.
use
rawField(String, InputStream, XContentType) to avoid content type auto-detection |
XContentBuilder |
rawField(java.lang.String name,
java.io.InputStream value,
XContentType contentType)
Writes a raw field with the value taken from the bytes in the stream
|
XContentBuilder |
rawValue(BytesReference value)
Deprecated.
use
rawValue(BytesReference, XContentType) to avoid content type auto-detection |
XContentBuilder |
rawValue(BytesReference value,
XContentType contentType)
Writes a value with the source coming directly from the bytes
|
XContentBuilder |
startArray() |
XContentBuilder |
startArray(java.lang.String name) |
XContentBuilder |
startObject() |
XContentBuilder |
startObject(java.lang.String name) |
java.lang.String |
string()
Returns a string representation of the builder (only applicable for text based xcontent).
|
XContentBuilder |
timeValueField(java.lang.String rawFieldName,
java.lang.String readableFieldName,
long rawTime) |
XContentBuilder |
timeValueField(java.lang.String rawFieldName,
java.lang.String readableFieldName,
long rawTime,
java.util.concurrent.TimeUnit timeUnit) |
XContentBuilder |
timeValueField(java.lang.String rawFieldName,
java.lang.String readableFieldName,
TimeValue timeValue) |
XContentBuilder |
utf8Field(java.lang.String name,
org.apache.lucene.util.BytesRef value)
Writes the binary content of the given
BytesRef as UTF-8 bytes. |
XContentBuilder |
utf8Value(org.apache.lucene.util.BytesRef value)
Writes the binary content of the given
BytesRef as UTF-8 bytes. |
XContentBuilder |
value(boolean value) |
XContentBuilder |
value(java.lang.Boolean value) |
XContentBuilder |
value(byte value) |
XContentBuilder |
value(java.lang.Byte value) |
XContentBuilder |
value(byte[] value) |
XContentBuilder |
value(byte[] value,
int offset,
int length) |
XContentBuilder |
value(BytesReference value)
Writes the binary content of the given
BytesReference . |
XContentBuilder |
value(java.util.Date value) |
XContentBuilder |
value(java.util.Date value,
org.joda.time.format.DateTimeFormatter formatter) |
XContentBuilder |
value(double value) |
XContentBuilder |
value(java.lang.Double value) |
XContentBuilder |
value(float value) |
XContentBuilder |
value(java.lang.Float value) |
XContentBuilder |
value(GeoPoint value) |
XContentBuilder |
value(int value) |
XContentBuilder |
value(java.lang.Integer value) |
XContentBuilder |
value(long value) |
XContentBuilder |
value(java.lang.Long value) |
XContentBuilder |
value(java.lang.Object value) |
XContentBuilder |
value(java.nio.file.Path value) |
XContentBuilder |
value(org.joda.time.ReadableInstant value) |
XContentBuilder |
value(org.joda.time.ReadableInstant value,
org.joda.time.format.DateTimeFormatter formatter) |
XContentBuilder |
value(short value) |
XContentBuilder |
value(java.lang.Short value) |
XContentBuilder |
value(java.lang.String value) |
XContentBuilder |
value(Text value) |
public static final org.joda.time.format.DateTimeFormatter DEFAULT_DATE_PRINTER
public XContentBuilder(XContent xContent, java.io.OutputStream bos) throws java.io.IOException
close()
when the builder is done with.java.io.IOException
public XContentBuilder(XContent xContent, java.io.OutputStream bos, java.util.Set<java.lang.String> includes) throws java.io.IOException
close()
when the builder is done with.java.io.IOException
public XContentBuilder(XContent xContent, java.io.OutputStream os, java.util.Set<java.lang.String> includes, java.util.Set<java.lang.String> excludes) throws java.io.IOException
Make sure to call close()
when the builder is done with.
os
- the output streamincludes
- the inclusive filters: only fields and objects that match the inclusive filters will be written to the output.excludes
- the exclusive filters: only fields and objects that don't match the exclusive filters will be written to the output.java.io.IOException
public static XContentBuilder builder(XContent xContent) throws java.io.IOException
XContentBuilder
using the given XContent
content.
The builder uses an internal BytesStreamOutput
output stream to build the content.
xContent
- the XContent
XContentBuilder
java.io.IOException
- if an IOException
occurs while building the contentpublic static XContentBuilder builder(XContent xContent, java.util.Set<java.lang.String> includes, java.util.Set<java.lang.String> excludes) throws java.io.IOException
XContentBuilder
using the given XContent
content and some inclusive and/or exclusive filters.
The builder uses an internal BytesStreamOutput
output stream to build the content. When both exclusive and
inclusive filters are provided, the underlying builder will first use exclusion filters to remove fields and then will check the
remaining fields against the inclusive filters.
xContent
- the XContent
includes
- the inclusive filters: only fields and objects that match the inclusive filters will be written to the output.excludes
- the exclusive filters: only fields and objects that don't match the exclusive filters will be written to the output.java.io.IOException
- if an IOException
occurs while building the contentpublic XContentType contentType()
public XContentBuilder prettyPrint()
public boolean isPrettyPrint()
public XContentBuilder lfAtEnd()
XContentBuilder
must write a line feed ("\n")
at the end of the built object.
This only applies for JSON XContent type. It has no effect for other types.
public XContentBuilder humanReadable(boolean humanReadable)
public boolean humanReadable()
public XContentBuilder startObject() throws java.io.IOException
java.io.IOException
public XContentBuilder startObject(java.lang.String name) throws java.io.IOException
java.io.IOException
public XContentBuilder endObject() throws java.io.IOException
java.io.IOException
public XContentBuilder startArray() throws java.io.IOException
java.io.IOException
public XContentBuilder startArray(java.lang.String name) throws java.io.IOException
java.io.IOException
public XContentBuilder endArray() throws java.io.IOException
java.io.IOException
public XContentBuilder field(java.lang.String name) throws java.io.IOException
java.io.IOException
public XContentBuilder nullField(java.lang.String name) throws java.io.IOException
java.io.IOException
public XContentBuilder nullValue() throws java.io.IOException
java.io.IOException
public XContentBuilder field(java.lang.String name, java.lang.Boolean value) throws java.io.IOException
java.io.IOException
public XContentBuilder field(java.lang.String name, boolean value) throws java.io.IOException
java.io.IOException
public XContentBuilder array(java.lang.String name, boolean[] values) throws java.io.IOException
java.io.IOException
public XContentBuilder value(java.lang.Boolean value) throws java.io.IOException
java.io.IOException
public XContentBuilder value(boolean value) throws java.io.IOException
java.io.IOException
public XContentBuilder field(java.lang.String name, java.lang.Byte value) throws java.io.IOException
java.io.IOException
public XContentBuilder field(java.lang.String name, byte value) throws java.io.IOException
java.io.IOException
public XContentBuilder value(java.lang.Byte value) throws java.io.IOException
java.io.IOException
public XContentBuilder value(byte value) throws java.io.IOException
java.io.IOException
public XContentBuilder field(java.lang.String name, java.lang.Double value) throws java.io.IOException
java.io.IOException
public XContentBuilder field(java.lang.String name, double value) throws java.io.IOException
java.io.IOException
public XContentBuilder array(java.lang.String name, double[] values) throws java.io.IOException
java.io.IOException
public XContentBuilder value(java.lang.Double value) throws java.io.IOException
java.io.IOException
public XContentBuilder value(double value) throws java.io.IOException
java.io.IOException
public XContentBuilder field(java.lang.String name, java.lang.Float value) throws java.io.IOException
java.io.IOException
public XContentBuilder field(java.lang.String name, float value) throws java.io.IOException
java.io.IOException
public XContentBuilder array(java.lang.String name, float[] values) throws java.io.IOException
java.io.IOException
public XContentBuilder value(java.lang.Float value) throws java.io.IOException
java.io.IOException
public XContentBuilder value(float value) throws java.io.IOException
java.io.IOException
public XContentBuilder field(java.lang.String name, java.lang.Integer value) throws java.io.IOException
java.io.IOException
public XContentBuilder field(java.lang.String name, int value) throws java.io.IOException
java.io.IOException
public XContentBuilder array(java.lang.String name, int[] values) throws java.io.IOException
java.io.IOException
public XContentBuilder value(java.lang.Integer value) throws java.io.IOException
java.io.IOException
public XContentBuilder value(int value) throws java.io.IOException
java.io.IOException
public XContentBuilder field(java.lang.String name, java.lang.Long value) throws java.io.IOException
java.io.IOException
public XContentBuilder field(java.lang.String name, long value) throws java.io.IOException
java.io.IOException
public XContentBuilder array(java.lang.String name, long[] values) throws java.io.IOException
java.io.IOException
public XContentBuilder value(java.lang.Long value) throws java.io.IOException
java.io.IOException
public XContentBuilder value(long value) throws java.io.IOException
java.io.IOException
public XContentBuilder field(java.lang.String name, java.lang.Short value) throws java.io.IOException
java.io.IOException
public XContentBuilder field(java.lang.String name, short value) throws java.io.IOException
java.io.IOException
public XContentBuilder array(java.lang.String name, short[] values) throws java.io.IOException
java.io.IOException
public XContentBuilder value(java.lang.Short value) throws java.io.IOException
java.io.IOException
public XContentBuilder value(short value) throws java.io.IOException
java.io.IOException
public XContentBuilder field(java.lang.String name, java.lang.String value) throws java.io.IOException
java.io.IOException
public XContentBuilder array(java.lang.String name, java.lang.String... values) throws java.io.IOException
java.io.IOException
public XContentBuilder value(java.lang.String value) throws java.io.IOException
java.io.IOException
public XContentBuilder field(java.lang.String name, byte[] value) throws java.io.IOException
java.io.IOException
public XContentBuilder value(byte[] value) throws java.io.IOException
java.io.IOException
public XContentBuilder field(java.lang.String name, byte[] value, int offset, int length) throws java.io.IOException
java.io.IOException
public XContentBuilder value(byte[] value, int offset, int length) throws java.io.IOException
java.io.IOException
public XContentBuilder field(java.lang.String name, org.apache.lucene.util.BytesRef value) throws java.io.IOException
BytesRef
.
Use XContentParser.binaryValue()
to read the value backjava.io.IOException
public XContentBuilder utf8Field(java.lang.String name, org.apache.lucene.util.BytesRef value) throws java.io.IOException
BytesRef
as UTF-8 bytes.
Use XContentParser.utf8Bytes()
to read the value backjava.io.IOException
public XContentBuilder binaryValue(org.apache.lucene.util.BytesRef value) throws java.io.IOException
BytesRef
.
Use XContentParser.binaryValue()
to read the value backjava.io.IOException
public XContentBuilder utf8Value(org.apache.lucene.util.BytesRef value) throws java.io.IOException
BytesRef
as UTF-8 bytes.
Use XContentParser.utf8Bytes()
to read the value backjava.io.IOException
public XContentBuilder field(java.lang.String name, BytesReference value) throws java.io.IOException
BytesReference
.
Use XContentParser.binaryValue()
to read the value backjava.io.IOException
public XContentBuilder value(BytesReference value) throws java.io.IOException
BytesReference
.
Use XContentParser.binaryValue()
to read the value backjava.io.IOException
public XContentBuilder field(java.lang.String name, Text value) throws java.io.IOException
java.io.IOException
public XContentBuilder value(Text value) throws java.io.IOException
java.io.IOException
public XContentBuilder field(java.lang.String name, org.joda.time.ReadableInstant value) throws java.io.IOException
java.io.IOException
public XContentBuilder field(java.lang.String name, org.joda.time.ReadableInstant value, org.joda.time.format.DateTimeFormatter formatter) throws java.io.IOException
java.io.IOException
public XContentBuilder value(org.joda.time.ReadableInstant value) throws java.io.IOException
java.io.IOException
public XContentBuilder value(org.joda.time.ReadableInstant value, org.joda.time.format.DateTimeFormatter formatter) throws java.io.IOException
java.io.IOException
public XContentBuilder field(java.lang.String name, java.util.Date value) throws java.io.IOException
java.io.IOException
public XContentBuilder field(java.lang.String name, java.util.Date value, org.joda.time.format.DateTimeFormatter formatter) throws java.io.IOException
java.io.IOException
public XContentBuilder value(java.util.Date value) throws java.io.IOException
java.io.IOException
public XContentBuilder value(java.util.Date value, org.joda.time.format.DateTimeFormatter formatter) throws java.io.IOException
java.io.IOException
public XContentBuilder dateField(java.lang.String name, java.lang.String readableName, long value) throws java.io.IOException
java.io.IOException
public XContentBuilder field(java.lang.String name, GeoPoint value) throws java.io.IOException
java.io.IOException
public XContentBuilder value(GeoPoint value) throws java.io.IOException
java.io.IOException
public XContentBuilder latlon(java.lang.String name, double lat, double lon) throws java.io.IOException
java.io.IOException
public XContentBuilder latlon(double lat, double lon) throws java.io.IOException
java.io.IOException
public XContentBuilder value(java.nio.file.Path value) throws java.io.IOException
java.io.IOException
public XContentBuilder field(java.lang.String name, java.lang.Object value) throws java.io.IOException
java.io.IOException
public XContentBuilder array(java.lang.String name, java.lang.Object... values) throws java.io.IOException
java.io.IOException
public XContentBuilder value(java.lang.Object value) throws java.io.IOException
java.io.IOException
public XContentBuilder field(java.lang.String name, ToXContent value) throws java.io.IOException
java.io.IOException
public XContentBuilder field(java.lang.String name, ToXContent value, ToXContent.Params params) throws java.io.IOException
java.io.IOException
public XContentBuilder field(java.lang.String name, java.util.Map<java.lang.String,java.lang.Object> values) throws java.io.IOException
java.io.IOException
public XContentBuilder map(java.util.Map<java.lang.String,?> values) throws java.io.IOException
java.io.IOException
public XContentBuilder field(java.lang.String name, java.lang.Iterable<?> values) throws java.io.IOException
java.io.IOException
public XContentBuilder timeValueField(java.lang.String rawFieldName, java.lang.String readableFieldName, TimeValue timeValue) throws java.io.IOException
java.io.IOException
public XContentBuilder timeValueField(java.lang.String rawFieldName, java.lang.String readableFieldName, long rawTime) throws java.io.IOException
java.io.IOException
public XContentBuilder timeValueField(java.lang.String rawFieldName, java.lang.String readableFieldName, long rawTime, java.util.concurrent.TimeUnit timeUnit) throws java.io.IOException
java.io.IOException
public XContentBuilder percentageField(java.lang.String rawFieldName, java.lang.String readableFieldName, double percentage) throws java.io.IOException
java.io.IOException
public XContentBuilder byteSizeField(java.lang.String rawFieldName, java.lang.String readableFieldName, ByteSizeValue byteSizeValue) throws java.io.IOException
java.io.IOException
public XContentBuilder byteSizeField(java.lang.String rawFieldName, java.lang.String readableFieldName, long rawSize) throws java.io.IOException
java.io.IOException
@Deprecated public XContentBuilder rawField(java.lang.String name, java.io.InputStream value) throws java.io.IOException
rawField(String, InputStream, XContentType)
to avoid content type auto-detectionjava.io.IOException
public XContentBuilder rawField(java.lang.String name, java.io.InputStream value, XContentType contentType) throws java.io.IOException
java.io.IOException
@Deprecated public XContentBuilder rawField(java.lang.String name, BytesReference value) throws java.io.IOException
rawField(String name, BytesReference, XContentType)
to avoid content type auto-detectionjava.io.IOException
public XContentBuilder rawField(java.lang.String name, BytesReference value, XContentType contentType) throws java.io.IOException
java.io.IOException
@Deprecated public XContentBuilder rawValue(BytesReference value) throws java.io.IOException
rawValue(BytesReference, XContentType)
to avoid content type auto-detectionjava.io.IOException
public XContentBuilder rawValue(BytesReference value, XContentType contentType) throws java.io.IOException
java.io.IOException
public XContentBuilder copyCurrentStructure(XContentParser parser) throws java.io.IOException
java.io.IOException
public void flush() throws java.io.IOException
flush
in interface java.io.Flushable
java.io.IOException
public void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in interface Releasable
public XContentGenerator generator()
public BytesReference bytes()
public java.lang.String string() throws java.io.IOException
java.io.IOException