private static String convertToYaml(String type, BytesReference bytes, boolean prettyPrint) throws IOException { try (XContentParser parser = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY, SearchGuardDeprecationHandler.INSTANCE, bytes.streamInput())) { parser.nextToken(); parser.nextToken(); if(!type.equals((parser.currentName()))) { return null; } parser.nextToken(); XContentBuilder builder = XContentFactory.yamlBuilder(); if (prettyPrint) { builder.prettyPrint(); } builder.rawValue(new ByteArrayInputStream(parser.binaryValue()), XContentType.YAML); return Strings.toString(builder); } }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { if (source != null) { builder.rawValue(source.streamInput(), xContentType); } else { builder.startObject().endObject(); } return builder; } }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.rawValue(source.streamInput(), xContentType); return builder; }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { if (source != null) { try (InputStream stream = new BytesArray(source).streamInput()) { builder.rawValue(stream, XContentType.JSON); } } else { builder.startObject().endObject(); } return builder; } }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { try (InputStream stream = status.streamInput()) { return builder.rawValue(stream, XContentHelper.xContentType(status)); } }
@Override public RestResponse buildResponse(final GetResponse response) throws Exception { checkResource(response); final XContentBuilder builder = channel.newBuilder(request.getXContentType(), false); final BytesReference source = response.getSourceInternal(); try (InputStream stream = source.streamInput()) { builder.rawValue(stream, XContentHelper.xContentType(source)); } return new BytesRestResponse(OK, builder); }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { return builder.rawValue(status); }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { if (source != null) { builder.rawValue(source.streamInput(), xContentType); } else { builder.startObject().endObject(); } return builder; } }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { if (source != null) { builder.rawValue(source.streamInput(), xContentType); } else { builder.startObject().endObject(); } return builder; } }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { try (InputStream stream = preview.streamInput()) { builder.rawValue(stream, XContentType.JSON); } return builder; }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.rawValue(source.streamInput(), xContentType); return builder; }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.rawValue(source.streamInput(), xContentType); return builder; }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { if (source != null) { try (InputStream stream = new BytesArray(source).streamInput()) { builder.rawValue(stream, XContentType.JSON); } } else { builder.startObject().endObject(); } return builder; } }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { if (source != null) { try (InputStream stream = new BytesArray(source).streamInput()) { builder.rawValue(stream, XContentType.JSON); } } else { builder.startObject().endObject(); } return builder; } }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { try (InputStream stream = status.streamInput()) { return builder.rawValue(stream, XContentHelper.xContentType(status)); } }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { try (InputStream stream = status.streamInput()) { return builder.rawValue(stream, XContentHelper.xContentType(status)); } }
@Override public RestResponse buildResponse(GetResponse response) throws Exception { XContentBuilder builder = channel.newBuilder(response.getSourceInternal(), false); if (!response.isExists()) { return new BytesRestResponse(NOT_FOUND, builder); } else { builder.rawValue(response.getSourceInternal()); return new BytesRestResponse(OK, builder); } } });
private static String convertToYaml(String type, BytesReference bytes, boolean prettyPrint) throws IOException { try (XContentParser parser = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY, SearchGuardDeprecationHandler.INSTANCE, bytes.streamInput())) { parser.nextToken(); parser.nextToken(); if(!type.equals((parser.currentName()))) { return null; } parser.nextToken(); XContentBuilder builder = XContentFactory.yamlBuilder(); if (prettyPrint) { builder.prettyPrint(); } builder.rawValue(new ByteArrayInputStream(parser.binaryValue()), XContentType.YAML); return Strings.toString(builder); } }