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); } }
/** * Constructs a xcontent builder that will output the result into the provided output stream. */ public static XContentBuilder contentBuilder(XContentType type, OutputStream outputStream) throws IOException { if (type == XContentType.JSON) { return jsonBuilder(outputStream); } else if (type == XContentType.SMILE) { return smileBuilder(outputStream); } else if (type == XContentType.YAML) { return yamlBuilder(outputStream); } else if (type == XContentType.CBOR) { return cborBuilder(outputStream); } throw new IllegalArgumentException("No matching content type for " + type); }
/** * Constructs a xcontent builder that will output the result into the provided output stream. */ public static XContentBuilder contentBuilder(XContentType type, OutputStream outputStream) throws IOException { if (type == XContentType.JSON) { return jsonBuilder(outputStream); } else if (type == XContentType.SMILE) { return smileBuilder(outputStream); } else if (type == XContentType.YAML) { return yamlBuilder(outputStream); } else if (type == XContentType.CBOR) { return cborBuilder(outputStream); } throw new IllegalArgumentException("No matching content type for " + type); }
/** * Constructs a xcontent builder that will output the result into the provided output stream. */ public static XContentBuilder contentBuilder(XContentType type, OutputStream outputStream) throws IOException { if (type == XContentType.JSON) { return jsonBuilder(outputStream); } else if (type == XContentType.SMILE) { return smileBuilder(outputStream); } else if (type == XContentType.YAML) { return yamlBuilder(outputStream); } else if (type == XContentType.CBOR) { return cborBuilder(outputStream); } throw new IllegalArgumentException("No matching content type for " + type); }
void updateAuthPassword(final String newPassword) { AccessController.doPrivileged((PrivilegedAction<Void>) () -> { Settings updatedSettings = Settings.builder() .put(settings) .put("auth.basic.password", newPassword) .build(); AuthConfig updatedAuthConfig = new AuthConfig(updatedSettings); try (OutputStream outputStream = Files.newOutputStream(configFile); XContentBuilder contentBuilder = XContentFactory.yamlBuilder(outputStream)) { contentBuilder.startObject(); updatedSettings.toXContent(contentBuilder, new ToXContent.MapParams(Collections.singletonMap("flat_settings", "true"))); contentBuilder.endObject(); BucklerConfig.this.settings = updatedSettings; BucklerConfig.this.authConfig = updatedAuthConfig; } catch (IOException e) { throw new AuthConfigUpdateException("Failed to write Buckler configuration to the file", e); } return null; }); }
/** * Constructs a xcontent builder that will output the result into the provided output stream. */ public static XContentBuilder contentBuilder(XContentType type, OutputStream outputStream) throws IOException { if (type == XContentType.JSON) { return jsonBuilder(outputStream); } else if (type == XContentType.SMILE) { return smileBuilder(outputStream); } else if (type == XContentType.YAML) { return yamlBuilder(outputStream); } else if (type == XContentType.CBOR) { return cborBuilder(outputStream); } throw new IllegalArgumentException("No matching content type for " + type); }
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); } }