Ejemplo n.º 1
0
  private void uploadFile(String relPath, Path fullPath) throws DropboxException, IOException {
    if (!fullPath.toFile().exists()) return;

    /*if(api.metadata(relPath, 1, null, false, null).rev == MetaHandler.getRev(relPath)){
    	logger.debug("File "+relPath+" not changed");
    	return;
    }*/

    VOSync.debug("Uploading " + relPath);

    String rev = MetaHandler.getRev(relPath);

    InputStream inp = new FileInputStream(fullPath.toFile());
    Entry fileEntry = api.putFile(relPath, inp, fullPath.toFile().length(), rev, null);
    inp.close();

    Path destFilePath =
        FileSystems.getDefault()
            .getPath(fullPath.toFile().getParentFile().getPath(), fileEntry.fileName());

    MetaHandler.setFile(relPath, destFilePath.toFile(), fileEntry.rev);

    logger.debug(relPath + " put to db");

    // if the file was renamed, move the file on disk and download the current from server
    if (!fileEntry.fileName().equals(fullPath.toFile().getName())) {
      logger.error(fileEntry.fileName() + " != " + fullPath.toFile().getName());
      fullPath.toFile().renameTo(destFilePath.toFile());
    }
  }
Ejemplo n.º 2
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;
  }