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

    clear();

    if (!file.delete()) {
      Log.warn("Failed to delete history file: ", file);
    }
  }
Esempio n. 2
0
 public void load(final File file) throws IOException {
   checkNotNull(file);
   if (file.exists()) {
     Log.trace("Loading history from: ", file);
     load(new FileReader(file));
   }
 }
Esempio n. 3
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();
    }
  }