/**
   * Writes the fingerprint cache file to disk. This takes place at the end of the demo's
   * processing.
   */
  void writeCache() {
    File f = getCacheFile();

    try (PrintWriter pw = new PrintWriter(new FileWriter(f))) {
      StringBuilder builderStr = new StringBuilder();
      int i = 0;
      for (Iterator<Term> it = cache.values().iterator(); it.hasNext(); i++) {
        Term t = it.next();
        String termStr = Term.toJson(t);
        if (i > 0) {
          termStr = termStr.substring(1).trim();
        }
        termStr = termStr.substring(0, termStr.length() - 1).trim();
        builderStr.append(termStr).append(",");
      }
      builderStr.setLength(builderStr.length() - 1);
      builderStr.append(" ]");

      pw.println(builderStr.toString());
      pw.flush();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }