@Override public void print(Message message, OutputStream output, MediaType contentType, Charset charset) throws IOException, HttpMessageConversionException { if (contentType.isCompatibleWith(APPLICATION_JSON)) { OutputStreamWriter writer = new OutputStreamWriter(output, charset); this.printer.appendTo(message, writer); writer.flush(); } else { throw new HttpMessageConversionException( "protobuf-java-util does not support printing " + contentType); } } }
@Override public void print(Message message, OutputStream output, MediaType contentType, Charset charset) throws IOException, HttpMessageConversionException { if (contentType.isCompatibleWith(APPLICATION_JSON)) { OutputStreamWriter writer = new OutputStreamWriter(output, charset); this.printer.appendTo(message, writer); writer.flush(); } else { throw new HttpMessageConversionException( "protobuf-java-util does not support printing " + contentType); } } }
/** * Converts a protobuf message to JSON format. Throws exceptions if there * are unknown Any types in the message. */ public String print(MessageOrBuilder message) throws InvalidProtocolBufferException { try { StringBuilder builder = new StringBuilder(); appendTo(message, builder); return builder.toString(); } catch (InvalidProtocolBufferException e) { throw e; } catch (IOException e) { // Unexpected IOException. throw new IllegalStateException(e); } } }
try (PrintWriter jsonPrintWriter = new PrintWriter(outFileJsonServiceConfig, StandardCharsets.UTF_8.name())) { jsonPrinter.appendTo(serviceConfig, jsonPrintWriter);
try (PrintWriter jsonPrintWriter = new PrintWriter(outFileJsonServiceConfig, StandardCharsets.UTF_8.name())) { jsonPrinter.appendTo(serviceConfig, jsonPrintWriter);
@Override public void print(Message message, OutputStream output, MediaType contentType, Charset charset) throws IOException, HttpMessageConversionException { if (contentType.isCompatibleWith(APPLICATION_JSON)) { OutputStreamWriter writer = new OutputStreamWriter(output, charset); this.printer.appendTo(message, writer); writer.flush(); } else { throw new HttpMessageConversionException( "protobuf-java-util does not support printing " + contentType); } } }
@Override public void print(Message message, OutputStream output, MediaType contentType, Charset charset) throws IOException { if (contentType.isCompatibleWith(APPLICATION_JSON)) { OutputStreamWriter writer = new OutputStreamWriter(output, charset); this.printer.appendTo(message, writer); writer.flush(); } else { throw new IOException("protobuf-java-util does not support " + contentType + " format"); } } }