public static void restDocumentSource(byte[] source, int offset, int length, XContentBuilder builder, ToXContent.Params params) throws IOException {
if (LZF.isCompressed(source, offset, length)) {
BytesStreamInput siBytes = new BytesStreamInput(source, offset, length);
LZFStreamInput siLzf = CachedStreamInput.cachedLzf(siBytes);
XContentType contentType = XContentFactory.xContentType(siLzf);
siLzf.resetToBufferStart();
if (contentType == builder.contentType()) {
builder.rawField("_source", siLzf);
} else {
XContentParser parser = XContentFactory.xContent(contentType).createParser(siLzf);
try {
parser.nextToken();
builder.field("_source");
builder.copyCurrentStructure(parser);
} finally {
parser.close();
}
}
} else {
XContentType contentType = XContentFactory.xContentType(source, offset, length);
if (contentType == builder.contentType()) {
builder.rawField("_source", source, offset, length);
} else {
XContentParser parser = XContentFactory.xContent(contentType).createParser(source);
try {