Exemplo n.º 1
0
  public void purge() throws IOException {
    Log.trace("Purging history");

    clear();

    if (!file.delete()) {
      Log.warn("Failed to delete history file: ", file);
    }
  }
Exemplo n.º 2
0
  public void flush() throws IOException {
    Log.trace("Flushing history");

    if (!file.exists()) {
      File dir = file.getParentFile();
      if (!dir.exists() && !dir.mkdirs()) {
        Log.warn("Failed to create directory: ", dir);
      }
      if (!file.createNewFile()) {
        Log.warn("Failed to create file: ", file);
      }
    }

    PrintStream out =
        new PrintStream(new BufferedOutputStream(new FileOutputStream(file)), false, "UTF-8");
    try {
      for (Entry entry : this) {
        out.println(entry.value());
      }
    } finally {
      out.close();
    }
  }