Example usage for io.vertx.core.file FileSystem writeFileBlocking

List of usage examples for io.vertx.core.file FileSystem writeFileBlocking

Introduction

In this page you can find the example usage for io.vertx.core.file FileSystem writeFileBlocking.

Prototype

@Fluent
FileSystem writeFileBlocking(String path, Buffer data);

Source Link

Document

Blocking version of #writeFile(String,Buffer,Handler)

Usage

From source file:de.braintags.netrelay.init.Settings.java

License:Open Source License

private static Settings loadSettings(NetRelay netRelay, Vertx vertx, String path) {
    FileSystem fs = vertx.fileSystem();
    if (fs.existsBlocking(path)) {
        LOGGER.info("going to load settings from " + path);
        Buffer buffer = fs.readFileBlocking(path);
        Settings settings = Json.decodeValue(buffer.toString(), Settings.class);
        LOGGER.info("settings successfully loaded from " + path);
        return settings;
    } else {//from  ww w . j av a  2s.  c  om
        LOGGER.info("creating default settings and store them in " + path);
        Settings settings = netRelay.createDefaultSettings();
        fs.writeFileBlocking(path, Buffer.buffer(Json.encodePrettily(settings)));
        String message = String.format(
                "Settings file did not exist and was created new in path %s. NOTE: edit the file, set edited to true and restart the server",
                path);
        throw new InitException(message);
    }

}