Search in sources :

Example 1 with YamlPrinter

use of com.bluenimble.platform.json.printers.YamlPrinter in project serverless by bluenimble.

the class SpecUtils method write.

public static void write(File apiFolder, JsonObject spec) throws CommandExecutionException {
    File fApi = new File(apiFolder, "api." + BlueNimble.SpecLangs.Yaml);
    if (fApi.exists()) {
        // yaml
        OutputStream out = null;
        try {
            out = new FileOutputStream(fApi);
            YamlPrinter yaml = new YamlOutputStreamPrinter(out);
            yaml.print(spec);
        } catch (Exception ex) {
            throw new CommandExecutionException(ex.getMessage(), ex);
        } finally {
            IOUtils.closeQuietly(out);
        }
    } else {
        fApi = new File(apiFolder, "api." + BlueNimble.SpecLangs.Json);
        if (fApi.exists()) {
            try {
                Json.store(spec, fApi);
            } catch (Exception ex) {
                throw new CommandExecutionException(ex.getMessage(), ex);
            }
        }
    }
}
Also used : YamlOutputStreamPrinter(com.bluenimble.platform.json.printers.YamlOutputStreamPrinter) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) CommandExecutionException(com.bluenimble.platform.cli.command.CommandExecutionException) File(java.io.File) YamlPrinter(com.bluenimble.platform.json.printers.YamlPrinter) CommandExecutionException(com.bluenimble.platform.cli.command.CommandExecutionException)

Example 2 with YamlPrinter

use of com.bluenimble.platform.json.printers.YamlPrinter in project serverless by bluenimble.

the class SpecUtils method toYaml.

public static void toYaml(String jsonText, OutputStream out) throws Exception {
    JsonObject json = new JsonObject(jsonText);
    YamlPrinter printer = new YamlOutputStreamPrinter(out);
    printer.print(json);
}
Also used : YamlOutputStreamPrinter(com.bluenimble.platform.json.printers.YamlOutputStreamPrinter) JsonObject(com.bluenimble.platform.json.JsonObject) YamlPrinter(com.bluenimble.platform.json.printers.YamlPrinter)

Aggregations

YamlOutputStreamPrinter (com.bluenimble.platform.json.printers.YamlOutputStreamPrinter)2 YamlPrinter (com.bluenimble.platform.json.printers.YamlPrinter)2 CommandExecutionException (com.bluenimble.platform.cli.command.CommandExecutionException)1 JsonObject (com.bluenimble.platform.json.JsonObject)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1