|
@@ -106,7 +106,9 @@ public class XContentHelper {
|
|
|
input = bytes.streamInput();
|
|
|
}
|
|
|
contentType = xContentType != null ? xContentType : XContentFactory.xContentType(input);
|
|
|
- return new Tuple<>(Objects.requireNonNull(contentType), convertToMap(XContentFactory.xContent(contentType), input, ordered));
|
|
|
+ try (InputStream stream = input) {
|
|
|
+ return new Tuple<>(Objects.requireNonNull(contentType), convertToMap(XContentFactory.xContent(contentType), stream, ordered));
|
|
|
+ }
|
|
|
} catch (IOException e) {
|
|
|
throw new ElasticsearchParseException("Failed to parse content to map", e);
|
|
|
}
|
|
@@ -163,8 +165,9 @@ public class XContentHelper {
|
|
|
}
|
|
|
|
|
|
// It is safe to use EMPTY here because this never uses namedObject
|
|
|
- try (XContentParser parser = XContentFactory.xContent(xContentType).createParser(NamedXContentRegistry.EMPTY,
|
|
|
- DeprecationHandler.THROW_UNSUPPORTED_OPERATION, bytes.streamInput())) {
|
|
|
+ try (InputStream stream = bytes.streamInput();
|
|
|
+ XContentParser parser = XContentFactory.xContent(xContentType).createParser(NamedXContentRegistry.EMPTY,
|
|
|
+ DeprecationHandler.THROW_UNSUPPORTED_OPERATION, stream)) {
|
|
|
parser.nextToken();
|
|
|
XContentBuilder builder = XContentFactory.jsonBuilder();
|
|
|
if (prettyPrint) {
|
|
@@ -376,8 +379,9 @@ public class XContentHelper {
|
|
|
public static void writeRawField(String field, BytesReference source, XContentBuilder builder, ToXContent.Params params) throws IOException {
|
|
|
Compressor compressor = CompressorFactory.compressor(source);
|
|
|
if (compressor != null) {
|
|
|
- InputStream compressedStreamInput = compressor.streamInput(source.streamInput());
|
|
|
- builder.rawField(field, compressedStreamInput);
|
|
|
+ try (InputStream compressedStreamInput = compressor.streamInput(source.streamInput())) {
|
|
|
+ builder.rawField(field, compressedStreamInput);
|
|
|
+ }
|
|
|
} else {
|
|
|
builder.rawField(field, source);
|
|
|
}
|
|
@@ -392,8 +396,9 @@ public class XContentHelper {
|
|
|
Objects.requireNonNull(xContentType);
|
|
|
Compressor compressor = CompressorFactory.compressor(source);
|
|
|
if (compressor != null) {
|
|
|
- InputStream compressedStreamInput = compressor.streamInput(source.streamInput());
|
|
|
- builder.rawField(field, compressedStreamInput, xContentType);
|
|
|
+ try (InputStream compressedStreamInput = compressor.streamInput(source.streamInput())) {
|
|
|
+ builder.rawField(field, compressedStreamInput, xContentType);
|
|
|
+ }
|
|
|
} else {
|
|
|
builder.rawField(field, source, xContentType);
|
|
|
}
|