All Downloads are FREE. Search and download functionalities are using the official Maven repository.

kz.greetgo.logging.zookeeper.core.ConfigFileBridge Maven / Gradle / Ivy

There is a newer version: 0.2.0
Show newest version
package kz.greetgo.logging.zookeeper.core;

import kz.greetgo.logging.structure.config.ConfigFile;
import kz.greetgo.logging.zookeeper.config.EventConfigFile;

import java.util.Date;

import static java.nio.charset.StandardCharsets.UTF_8;

public class ConfigFileBridge implements ConfigFile, AutoCloseable {

  private final EventConfigFile eventConfigFile;

  public ConfigFileBridge(EventConfigFile eventConfigFile) {
    this.eventConfigFile = eventConfigFile;
  }

  @Override
  public String read() {
    byte[] content = eventConfigFile.readContent();
    if (content == null) {
      return null;
    }
    return new String(content, UTF_8);
  }

  @Override
  public void write(String content) {
    eventConfigFile.writeContent(content == null ? null : content.getBytes(UTF_8));
  }

  @Override
  public Date lastModifiedAt() {
    return eventConfigFile.lastModifiedAt().orElse(null);
  }

  @Override
  public void close() {
    eventConfigFile.close();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy