Esempio n. 1
0
 /** Register the given directory with the WatchService */
 private void register(Path dir) throws IOException {
   WatchKey key = dir.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
   if (trace) {
     Path prev = keys.get(key);
     if (prev == null) {
       System.out.format("register: %s\n", dir);
     } else {
       if (!dir.equals(prev)) {
         System.out.format("update: %s -> %s\n", prev, dir);
       }
     }
   }
   keys.put(key, dir);
 }
Esempio n. 2
0
  public void downloadFile(String relPath) {
    VOSync.debug("Downloading file from storage: " + relPath);
    Path filePath = FileSystems.getDefault().getPath(startDir.toString(), relPath.substring(1));
    try {
      WatchKey key =
          filePath.getParent().register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
      keys.remove(key);
      key.cancel();

      FileOutputStream outp = new FileOutputStream(filePath.toFile());
      DropboxFileInfo info = api.getFile(relPath, null, outp, null);
      outp.close();

      key = filePath.getParent().register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
      keys.put(key, filePath.getParent());

      MetaHandler.setFile(relPath, filePath.toFile(), info.getMetadata().rev);
    } catch (IOException ex) {
      logger.error("Error downloading file " + relPath + ": " + ex.getMessage());
    } catch (DropboxException ex) {
      ex.printStackTrace();
      logger.error("Error downloading file " + relPath + ": " + ex.getMessage());
    }
  }
Esempio n. 3
0
 /** Регистрация директории для WatchService. */
 private void register(Path dir) throws IOException {
   // Решистрируем ключи событий, в начальной версии не отслеживаем
   // ENTRY_DELETE, ENTRY_MODIFY
   WatchKey key = dir.register(watcher, ENTRY_CREATE);
   keys.put(key, dir);
 }