Tabnine Logo
DbxClientV2.files
Code IndexAdd Tabnine to your IDE (free)

How to use
files
method
in
com.dropbox.core.v2.DbxClientV2

Best Java code snippets using com.dropbox.core.v2.DbxClientV2.files (Showing top 20 results out of 315)

origin: sebbrudzinski/Open-LaTeX-Studio

private static File downloadRemoteFile(String revision, String remotePath, String localPath) {
  DbxClientV2 client = getDbxClient();
  
  FileOutputStream outputStream = null;
  File outputFile = new File(localPath);
  
  try {
    outputStream = new FileOutputStream(outputFile);
    client.files().download(remotePath, revision).download(outputStream);
  } catch (DbxException | IOException ex) {
    Exceptions.printStackTrace(ex);
  } finally {
    IOUtils.closeQuietly(outputStream);
  }
  
  return outputFile;
}

origin: adrian/upm-android

@Override
protected Integer doInBackground(Void... params) {
  try {
    ListFolderResult filderContents =
        DropboxClientFactory.getClient().files().listFolder("");
    dropBoxEntries = filderContents.getEntries();
    return 0;
  } catch (InvalidAccessTokenException e) {
    Log.e(TAG, "InvalidAccessTokenException downloading database", e);
    return ERROR_DROPBOX_INVALID_TOKEN;
  } catch (DbxException e) {
    Log.e(TAG, "DbxException downloading database", e);
    return ERROR_DROPBOX;
  }
}
origin: org.apache.camel/camel-dropbox

private FileMetadata putSingleFile(File inputFile, String dropboxPath, DropboxUploadMode mode) throws Exception {
  FileInputStream inputStream = new FileInputStream(inputFile);
  FileMetadata uploadedFile;
  try {
    WriteMode uploadMode;
    if (mode == DropboxUploadMode.force) {
      uploadMode = WriteMode.OVERWRITE;
    } else {
      uploadMode = WriteMode.ADD;
    }
    uploadedFile = client.files().uploadBuilder(dropboxPath).withMode(uploadMode).uploadAndFinish(inputStream, inputFile.length());
    return uploadedFile;
  } finally {
    IOHelper.close(inputStream);
  }
}
origin: quebic-source/microservices-sample-project

  @Override
  public void writeTo(OutputStream outputStream) {
    try {
      String fileStr = SEPARATOR + imageDir + SEPARATOR + id + SEPARATOR + fileName;
      DbxRequestConfig config = new DbxRequestConfig(APP_IDENTIFIER);
      DbxClientV2 client = new DbxClientV2(config, ACCESS_TOKEN);
      client.files().download(fileStr).download(outputStream);
    } catch (Exception e) {
      logger.error(e.getMessage());
      throw new ResourceNotFoundException("Image Not Found : " + id + "/" + fileName);
    }
  }
};
origin: org.apache.camel/camel-dropbox

private Map<String, Object> downloadFilesInFolder(String path) throws DropboxException {
  try {
    ListFolderResult folderResult = client.files().listFolder(path.equals("/") ? "" : path);
    Map<String, Object> returnMap = new LinkedHashMap<>();
    for (Metadata entry : folderResult.getEntries()) {
      returnMap.put(entry.getPathDisplay(), downloadSingleFile(entry.getPathDisplay()).getValue());
    }
    return returnMap;
  } catch (ListFolderErrorException e) {
    try {
      DbxDownloader<FileMetadata> listing = client.files().download(path);
      if (listing == null) {
        return Collections.emptyMap();
      } else {
        LOG.debug("downloading a single file...");
        Map.Entry<String, Object> entry = downloadSingleFile(path);
        return Collections.singletonMap(entry.getKey(), entry.getValue());
      }
    } catch (DbxException dbxException) {
      throw new DropboxException(dbxException);
    }
  } catch (DbxException e) {
    throw new DropboxException(e);
  }
}
origin: org.apache.camel/camel-dropbox

/**
 * Rename a remote path with the new path location.
 *
 * @param remotePath the existing remote path to be renamed
 * @param newRemotePath the new remote path substituting the old one
 * @return a result object with the result of the move operation.
 * @throws DropboxException
 */
public DropboxMoveResult move(String remotePath, String newRemotePath) throws DropboxException {
  try {
    client.files().moveV2(remotePath, newRemotePath);
    return new DropboxMoveResult(remotePath, newRemotePath);
  } catch (DbxException e) {
    throw new DropboxException(remotePath + " does not exist or cannot obtain metadata", e);
  }
}
origin: org.apache.camel/camel-dropbox

/**
 * Delete every files and subdirectories inside the remote directory. In
 * case the remotePath is a file, delete the file.
 *
 * @param remotePath the remote location to delete
 * @return a result object with the result of the delete operation.
 * @throws DropboxException
 */
public DropboxDelResult del(String remotePath) throws DropboxException {
  try {
    client.files().deleteV2(remotePath);
  } catch (DbxException e) {
    throw new DropboxException(remotePath + " does not exist or cannot obtain metadata", e);
  }
  return new DropboxDelResult(remotePath);
}
origin: adrian/upm-android

@Override
protected Integer doInBackground(Void... params) {
  int result = UPLOAD_OK;
  FileInputStream inputStream = null;
  try {
    File databaseFile = getPasswordDatabase().getDatabaseFile();
    inputStream = new FileInputStream(databaseFile);
    DropboxClientFactory.getClient().files()
        .uploadBuilder("/" + databaseFile.getName())
        .withMode(WriteMode.OVERWRITE)
        .uploadAndFinish(inputStream);
  } catch (IOException e) {
    Log.e(TAG, "IOException during database upload", e);
    result = ERROR_IO;
  } catch (DbxException e) {
    Log.e(TAG, "DbxException downloading database", e);
    return ERROR_DROPBOX;
  } finally {
    if (inputStream != null) {
      try {
        inputStream.close();
      } catch (IOException e) {
        Log.e(TAG, "IOException during database upload", e);
        return ERROR_IO;
      }
    }
  }
  return result;
}
origin: org.apache.camel/camel-dropbox

private FileMetadata putSingleBody(Exchange exchange, String dropboxPath, DropboxUploadMode mode) throws Exception {
  byte[] data = exchange.getIn().getMandatoryBody(byte[].class);
  InputStream is = new ByteArrayInputStream(data);
  try {
    FileMetadata uploadedFile;
    WriteMode uploadMode;
    if (mode == DropboxUploadMode.force) {
      uploadMode = WriteMode.OVERWRITE;
    } else {
      uploadMode = WriteMode.ADD;
    }
    uploadedFile = client.files().uploadBuilder(dropboxPath).withMode(uploadMode).uploadAndFinish(is, data.length);
    return uploadedFile;
  } finally {
    IOHelper.close(is);
  }
}
origin: dsolonenko/financisto

List<String> listFiles() throws Exception {
  if (authSession()) {
    try {
      List<String> files = new ArrayList<String>();
      ListFolderResult listFolderResult = dropboxClient.files().listFolder("");
      for (Metadata metadata : listFolderResult.getEntries()) {
        String name = metadata.getName();
        if (name.endsWith(".backup")) {
          files.add(name);
        }
      }
      Collections.sort(files, new Comparator<String>() {
        @Override
        public int compare(String s1, String s2) {
          return s2.compareTo(s1);
        }
      });
      return files;
    } catch (Exception e) {
      Log.e("Financisto", "Dropbox: Something wrong", e);
      throw new ImportExportException(R.string.dropbox_error, e);
    }
  } else {
    throw new ImportExportException(R.string.dropbox_auth_error);
  }
}
origin: quebic-source/microservices-sample-project

private FileMetadata dropBoxSave(String uploadPath, InputStream inputStream)throws Exception{
  DbxRequestConfig config = new DbxRequestConfig(APP_IDENTIFIER);
  DbxClientV2 client = new DbxClientV2(config, ACCESS_TOKEN);
  return client.files().uploadBuilder(uploadPath).uploadAndFinish(inputStream);
}
origin: org.apache.camel/camel-dropbox

  private Map.Entry<String, Object> downloadSingleFile(String path) throws DropboxException {
    try {
      OutputStreamBuilder target = OutputStreamBuilder.withExchange(exchange);
      DbxDownloader<FileMetadata> downloadedFile = client.files().download(path);
      if (downloadedFile != null) {
        downloadedFile.download(target);
        LOG.debug("downloaded path={}", path);
        return new AbstractMap.SimpleEntry<>(path, target.build());
      } else {
        return null;
      }
    } catch (DbxException e) {
      throw new DropboxException(path + " does not exist or cannot obtain metadata", e);
    } catch (IOException e) {
      throw new DropboxException(path + " cannot obtain a stream", e);
    }
  }
}
origin: dsolonenko/financisto

public FileMetadata uploadFile(File file) throws Exception {
  if (authSession()) {
    try {
      InputStream is = new FileInputStream(file);
      try {
        FileMetadata fileMetadata = dropboxClient.files().uploadBuilder("/" + file.getName()).withMode(WriteMode.ADD).uploadAndFinish(is);
        Log.i("Financisto", "Dropbox: The uploaded file's rev is: " + fileMetadata.getRev());
        return fileMetadata;
      } finally {
        IOUtil.closeInput(is);
      }
    } catch (Exception e) {
      Log.e("Financisto", "Dropbox: Something wrong", e);
      throw new ImportExportException(R.string.dropbox_error, e);
    }
  } else {
    throw new ImportExportException(R.string.dropbox_auth_error);
  }
}
origin: dsolonenko/financisto

  public InputStream getFileAsStream(String backupFile) throws Exception {
    if (authSession()) {
      try {
        return dropboxClient.files().downloadBuilder("/" + backupFile).start().getInputStream();
      } catch (Exception e) {
        Log.e("Financisto", "Dropbox: Something wrong", e);
        throw new ImportExportException(R.string.dropbox_error, e);
      }
    } else {
      throw new ImportExportException(R.string.dropbox_auth_error);
    }
  }
}
origin: org.apache.camel/camel-dropbox

/**
 * Put or upload a new file or an entire directory to dropbox
 *
 * @param localPath the file path or the dir path on the local filesystem
 * @param remotePath the remote path destination on dropbox
 * @param mode how a file should be saved on dropbox; in case of "add" the
 *            new file will be renamed in case a file with the same name
 *            already exists on dropbox. in case of "force" the file already
 *            existing with the same name will be overridden.
 * @return a result object reporting for each remote path the result of the
 *         operation.
 * @throws DropboxException
 */
public DropboxFileUploadResult put(String localPath, String remotePath, DropboxUploadMode mode) throws DropboxException {
  // in case the remote path is not specified, the remotePath = localPath
  String dropboxPath = remotePath == null ? localPath : remotePath;
  boolean isPresent = true;
  try {
    client.files().getMetadata(dropboxPath);
  } catch (DbxException e) {
    isPresent = false;
  }
  if (localPath != null) {
    return putFile(localPath, mode, dropboxPath, isPresent);
  } else {
    return putBody(exchange, mode, dropboxPath, isPresent);
  }
}
origin: org.apache.camel/camel-dropbox

LOG.debug("Search no query");
try {
  listing = client.files().search(remotePath, null);
  searchMatches = listing.getMatches();
  return new DropboxSearchResult(searchMatches);
LOG.debug("Search by query: {}", query);
try {
  listing = client.files().search(remotePath, query);
  searchMatches = listing.getMatches();
  return new DropboxSearchResult(searchMatches);
origin: sebbrudzinski/Open-LaTeX-Studio

ListFolderResult result = client.files().listFolderBuilder("").withRecursive(true).start();
while (true) {
  for (Metadata metadata : result.getEntries()) {
  result = client.files().listFolderContinue(result.getCursor());
origin: sebbrudzinski/Open-LaTeX-Studio

private void restoreThisRevisionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_restoreThisRevisionButtonActionPerformed
  DbxClientV2 client = DbxUtil.getDbxClient();
  
  if (client == null) {
    return;
  }
  if (displayedRevision != null) {
    try {
      FileMetadata restoredFileMetadata = client.files().restore(displayedRevision.getPath(), displayedRevision.getRevision());
      File restored = DbxUtil.downloadRemoteFile(restoredFileMetadata, ApplicationUtils.getTempSourceFile());
      etc.setEditorContent(FileUtils.readFileToString(restored));
      etc.requestActive();
    } catch (DbxException e) {
      DbxUtil.showDbxAccessDeniedPrompt();
    } catch (IOException e) {
      Exceptions.printStackTrace(e);
    }
  }
}//GEN-LAST:event_restoreThisRevisionButtonActionPerformed
origin: org.jbpm.contrib/dropbox-workitem

@Before
public void setUp() {
  try {
    testDoc = new DocumentImpl();
    testDoc.setName("testDoc.txt");
    testDoc.setIdentifier("testDoc");
    testDoc.setLastModified(new Date());
    testDoc.setContent(new String("test doc content").getBytes());
    InputStream testInputStream =
        IOUtils.toInputStream("test doc content",
                   "UTF-8");
    when(auth.authorize(anyString(),
              anyString())).thenReturn(client);
    when(client.files()).thenReturn(fileRequests);
    // upload
    when(fileRequests.uploadBuilder(anyString())).thenReturn(uploadBuilder);
    when(uploadBuilder.withMode(any(WriteMode.class))).thenReturn(uploadBuilder);
    when(uploadBuilder.withClientModified(any(Date.class))).thenReturn(uploadBuilder);
    when(uploadBuilder.uploadAndFinish(any(java.io.InputStream.class))).thenReturn(metaData);
    // download
    when(fileRequests.downloadBuilder(anyString())).thenReturn(downloadBuilder);
    when(downloadBuilder.start()).thenReturn(downloader);
    when(downloader.getInputStream()).thenReturn(testInputStream);
  } catch (Exception e) {
    fail(e.getMessage());
  }
}
origin: sebbrudzinski/Open-LaTeX-Studio

DbxDownloader<FileMetadata> downloader = client.files().download(entry.getPath(), entry.getRevision());
downloader.download(outputStream);
com.dropbox.core.v2DbxClientV2files

Popular methods of DbxClientV2

  • <init>
    For internal use only. Used by other clients to provide functionality like DbxTeamClientV2.asMember(
  • users
  • auth

Popular in Java

  • Start an intent from android
  • startActivity (Activity)
  • setRequestProperty (URLConnection)
  • setScale (BigDecimal)
  • Rectangle (java.awt)
    A Rectangle specifies an area in a coordinate space that is enclosed by the Rectangle object's top-
  • FileWriter (java.io)
    A specialized Writer that writes to a file in the file system. All write requests made by calling me
  • PrintStream (java.io)
    Fake signature of an existing Java class.
  • MessageDigest (java.security)
    Uses a one-way hash function to turn an arbitrary number of bytes into a fixed-length byte sequence.
  • Format (java.text)
    The base class for all formats. This is an abstract base class which specifies the protocol for clas
  • Stream (java.util.stream)
    A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now