Ejemplo n.º 1
0
 private static void saveVersion(File versionFile) {
   try {
     DataOutputStream versionOutputStream =
         new DataOutputStream(new BufferedOutputStream(new FileOutputStream(versionFile)));
     try {
       DataInputOutputUtil.writeINT(versionOutputStream, VERSION);
     } finally {
       versionOutputStream.close();
     }
   } catch (IOException ignore) {
   }
 }
Ejemplo n.º 2
0
    static {
      File snapshotInfoFile = new File(new File(getJarsDir()), "snapshots_info");

      int currentVersion = -1;
      File versionFile = getVersionFile(snapshotInfoFile);
      if (versionFile.exists()) {
        try {
          DataInputStream versionStream =
              new DataInputStream(new BufferedInputStream(new FileInputStream(versionFile)));
          try {
            currentVersion = DataInputOutputUtil.readINT(versionStream);
          } finally {
            versionStream.close();
          }
        } catch (IOException ignore) {
        }
      }

      if (currentVersion != VERSION) {
        PersistentHashMap.deleteFilesStartingWith(snapshotInfoFile);
        saveVersion(versionFile);
      }

      PersistentHashMap<String, CacheLibraryInfo> info = null;
      for (int i = 0; i < 2; ++i) {
        try {
          info =
              new PersistentHashMap<String, CacheLibraryInfo>(
                  snapshotInfoFile,
                  new EnumeratorStringDescriptor(),
                  new DataExternalizer<CacheLibraryInfo>() {

                    @Override
                    public void save(@NotNull DataOutput out, CacheLibraryInfo value)
                        throws IOException {
                      IOUtil.writeUTF(out, value.mySnapshotPath);
                      out.writeLong(value.myModificationTime);
                      out.writeLong(value.myFileLength);
                    }

                    @Override
                    public CacheLibraryInfo read(@NotNull DataInput in) throws IOException {
                      return new CacheLibraryInfo(IOUtil.readUTF(in), in.readLong(), in.readLong());
                    }
                  });

          if (i == 0) removeStaleJarFilesIfNeeded(snapshotInfoFile, info);
          break;
        } catch (IOException ex) {
          PersistentHashMap.deleteFilesStartingWith(snapshotInfoFile);
          saveVersion(versionFile);
        }
      }

      assert info != null;
      ourCachedLibraryInfo = info;
      FlushingDaemon.everyFiveSeconds(
          new Runnable() {
            @Override
            public void run() {
              flushCachedLibraryInfos();
            }
          });

      ShutDownTracker.getInstance()
          .registerShutdownTask(
              new Runnable() {
                @Override
                public void run() {
                  flushCachedLibraryInfos();
                }
              });
    }