public void flush()

in common/src/main/java/jetbrains/buildServer/torrent/seeder/TorrentFilesDB.java [119:153]


  public void flush() throws IOException {

    if (!myIsDBChanged) return;

    File parentFile = myTorrentsDbFile.getParentFile();
    if (!parentFile.isDirectory() && !parentFile.mkdirs()) {
      throw new IOException("Failed to create directory for torrent database file: " + myTorrentsDbFile.getAbsolutePath());
    }

    PrintWriter writer = null;
    try {
      OutputStreamWriter osWriter = new OutputStreamWriter(new FileOutputStream(myTorrentsDbFile), ENCODING);
      writer = new PrintWriter(osWriter);

      List<FileInfo> sorted = getSortedKeys();

      synchronized (myFile2TorrentMap) {
        for (FileInfo srcFile : sorted) {
          final FileInfo torrentFile = myFile2TorrentMap.get().get(srcFile);
          if (torrentFile == null) continue;

          String srcPath = srcFile.myPath;
          String torrentPath = torrentFile.myPath;

          writer.print(srcPath);
          writer.print(SEPARATOR);
          writer.print(torrentPath);
          writer.println();
        }
        myIsDBChanged = false;
      }
    } finally {
      FileUtil.close(writer);
    }
  }