use of com.dropbox.core.v2.DbxClientV2 in project dropbox-sdk-java by dropbox.
the class DbxClientV2IT method testRangeDownload.
@Test
public void testRangeDownload() throws Exception {
DbxClientV2 client = ITUtil.newClientV2();
byte[] contents = ITUtil.randomBytes(500);
String path = ITUtil.path(getClass(), "/testRangeDownload.dat");
FileMetadata metadata = client.files().uploadBuilder(path).withAutorename(false).withMode(WriteMode.OVERWRITE).withMute(true).uploadAndFinish(new ByteArrayInputStream(contents));
assertThat(metadata.getSize()).isEqualTo(contents.length);
assertRangeDownload(client, path, contents, 0, contents.length);
assertRangeDownload(client, path, contents, 0, 200);
assertRangeDownload(client, path, contents, 300, 200);
assertRangeDownload(client, path, contents, 499, 1);
assertRangeDownload(client, path, contents, 0, 600);
assertRangeDownload(client, path, contents, 250, null);
}
use of com.dropbox.core.v2.DbxClientV2 in project dropbox-sdk-java by dropbox.
the class DbxClientV2IT method testUploadAndDownload.
private void testUploadAndDownload(DbxClientV2 client, boolean trackProgress) throws Exception {
final byte[] contents = ITUtil.randomBytes(1024 << 8);
String filename = "testUploadAndDownload.dat";
String path = ITUtil.path(getClass(), "/" + filename);
ProgressListener progressListener = null;
if (trackProgress) {
progressListener = createTestListener(contents.length);
}
FileMetadata metadata = client.files().uploadBuilder(path).withAutorename(false).withMode(WriteMode.ADD).withMute(true).uploadAndFinish(new ByteArrayInputStream(contents), progressListener);
assertThat(metadata.getName()).isEqualTo(filename);
assertThat(metadata.getPathLower()).isEqualTo(path.toLowerCase());
assertThat(metadata.getSize()).isEqualTo(contents.length);
Metadata actual = client.files().getMetadata(path);
assertWithMessage(actual.getClass().getCanonicalName()).that(actual instanceof FileMetadata).isTrue();
try {
assertThat(actual).isEqualTo(metadata);
if (trackProgress) {
progressListener = createTestListener(contents.length);
}
DbxDownloader<FileMetadata> downloader = client.files().download(path);
ByteArrayOutputStream out = new ByteArrayOutputStream();
downloader.download(out, progressListener);
byte[] actualContents = out.toByteArray();
FileMetadata actualResult = downloader.getResult();
assertThat(actualResult).isEqualTo(metadata);
assertThat(actualContents).isEqualTo(contents);
assertThat(downloader.getContentType()).isEqualTo("application/octet-stream");
} catch (AssertionError e) {
// so subsequent tests don't fail due to file not being cleaned up
client.files().deleteV2(path).getMetadata();
throw e;
}
Metadata deleted = client.files().deleteV2(path).getMetadata();
assertThat(deleted).isEqualTo(metadata);
}
use of com.dropbox.core.v2.DbxClientV2 in project syndesis-qe by syndesisio.
the class DropBoxUtils method getClient.
private DbxClientV2 getClient() throws DbxException {
if (this.client == null) {
System.setProperty("https.protocols", "TLSv1.2");
Account account = AccountsDirectory.getInstance().get(Account.Name.DROPBOX);
DbxRequestConfig config = new DbxRequestConfig(account.getProperty("clientIdentifier"));
this.client = new DbxClientV2(config, account.getProperty("accessToken"));
log.debug("DropBox client created, logged as: " + client.users().getCurrentAccount());
} else {
log.debug("DropBox client was already created, returning existing instance");
}
return this.client;
}
use of com.dropbox.core.v2.DbxClientV2 in project dropbox-webhooks-spring-boot-example by zeldan.
the class DropboxService method logChangedFiles.
public void logChangedFiles(final String userId) throws Exception {
final String accessToken = getTokenAndCheckIsTokenExists(userId);
final DbxClientV2 client = new DbxClientV2(requestConfig, accessToken);
final String cursor = userTokenRepository.getValue(CURSORS_HASH_KEY, userId);
final ListFolderResult listFolderContinue = client.files().listFolderContinue(cursor);
logChangedFilesOfUser(userId, listFolderContinue);
}
use of com.dropbox.core.v2.DbxClientV2 in project dropbox-webhooks-spring-boot-example by zeldan.
the class DropboxService method finishAuthAndSaveUserDetails.
public void finishAuthAndSaveUserDetails(final HttpSession session, final Map<String, String[]> parameterMap) throws Exception {
final DbxSessionStore csrfTokenStore = new DbxStandardSessionStore(session, dropboxConfigProp.getSessionStore().getKey());
final DbxAuthFinish authFinish = auth.finishFromRedirect(dropboxConfigProp.getRedirectUri(), csrfTokenStore, parameterMap);
final String accessToken = authFinish.getAccessToken();
final DbxClientV2 client = new DbxClientV2(requestConfig, accessToken);
final String userId = authFinish.getUserId();
final ListFolderResult listFolderResult = client.files().listFolderBuilder("").withRecursive(true).start();
saveAccessTokenAndActualCursor(userId, accessToken, listFolderResult);
}
Aggregations