예제 #1
0
  public boolean pull() {
    // TODO Auto-generated method stub
    if (!isLinked()) return false;

    File file;
    FileOutputStream outputStream = null;
    try {
      Entry entry = mDBApi.metadata("/", 0, null, true, null);
      for (Entry e : entry.contents) {
        if (!e.isDir) {
          app.getGui().setStatus("Downloading...");
          file = new File(NoteManager.defaultPath.concat(e.fileName()));
          outputStream = new FileOutputStream(file);
          DropboxFileInfo info = mDBApi.getFile("/".concat(e.fileName()), null, outputStream, null);
          app.getGui().setStatus("Downloaded ".concat(info.getMetadata().fileName()));
          outputStream.close();
        }
      }
      return true;
    } catch (DropboxException e) {
      e.printStackTrace();
      app.getGui().setStatus("Couldn't connect to server.");
    } catch (FileNotFoundException e) {
      e.printStackTrace();
      app.getGui().setStatus("Files not found.");
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      app.getGui().setStatus("IO errors.");
    }
    return false;
  }
예제 #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());
    }
  }