use of com.dropbox.core.v2.DbxClientV2 in project dropbox-sdk-java by dropbox.
the class DbxClientV2IT method testUploadAndDownload.
private void testUploadAndDownload(DbxClientV2 client) throws Exception {
byte[] contents = ITUtil.randomBytes(1024);
String filename = "testUploadAndDownload.dat";
String path = ITUtil.path(getClass(), "/" + filename);
FileMetadata metadata = client.files().uploadBuilder(path).withAutorename(false).withMode(WriteMode.ADD).withMute(true).uploadAndFinish(new ByteArrayInputStream(contents));
assertEquals(metadata.getName(), filename);
assertEquals(metadata.getPathLower(), path.toLowerCase());
assertEquals(metadata.getSize(), contents.length);
Metadata actual = client.files().getMetadata(path);
assertTrue(actual instanceof FileMetadata, actual.getClass().getCanonicalName());
assertEquals(actual, metadata);
DbxDownloader<FileMetadata> downloader = client.files().download(path);
ByteArrayOutputStream out = new ByteArrayOutputStream();
downloader.download(out);
byte[] actualContents = out.toByteArray();
FileMetadata actualResult = downloader.getResult();
assertEquals(actualResult, metadata);
assertEquals(actualContents, contents);
Metadata deleted = client.files().delete(path);
assertEquals(deleted, metadata);
}
use of com.dropbox.core.v2.DbxClientV2 in project dropbox-sdk-java by dropbox.
the class DropboxClientFactory method init.
public static void init(String accessToken) {
if (sDbxClient == null) {
DbxRequestConfig requestConfig = DbxRequestConfig.newBuilder("examples-v2-demo").withHttpRequestor(new OkHttp3Requestor(OkHttp3Requestor.defaultOkHttpClient())).build();
sDbxClient = new DbxClientV2(requestConfig, accessToken);
}
}
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) {
Optional<Account> optional = AccountsDirectory.getInstance().getAccount("QE Dropbox");
if (optional.isPresent()) {
DbxRequestConfig config = new DbxRequestConfig(optional.get().getProperty("clientIdentifier"));
this.client = new DbxClientV2(config, optional.get().getProperty("accessToken"));
} else {
log.error("Unable to create DropBox client - credentials not found.");
throw new IllegalArgumentException("DropBox credentials were not found.");
}
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 drill by apache.
the class DropboxFileSystem method getClient.
private DbxClientV2 getClient() {
if (this.client != null) {
return client;
}
// read preferred client identifier from config or use "Apache/Drill"
String clientIdentifier = this.getConf().get("clientIdentifier", "Apache/Drill");
logger.info("Creating dropbox client with client identifier: {}", clientIdentifier);
DbxRequestConfig config = DbxRequestConfig.newBuilder(clientIdentifier).build();
// read access token from config or credentials provider
logger.info("Reading dropbox access token from configuration or credentials provider");
String accessToken = this.getConf().get("dropboxAccessToken", "");
this.client = new DbxClientV2(config, accessToken);
return this.client;
}
use of com.dropbox.core.v2.DbxClientV2 in project dropbox-sdk-java by dropbox.
the class Main method createClient.
/**
* Create a new Dropbox client using the given authentication
* information and HTTP client config.
*
* @param auth Authentication information
* @param config HTTP request configuration
*
* @return new Dropbox V2 client
*/
private static DbxClientV2 createClient(DbxAuthInfo auth, StandardHttpRequestor.Config config) {
String clientUserAgentId = "examples-longpoll";
StandardHttpRequestor requestor = new StandardHttpRequestor(config);
DbxRequestConfig requestConfig = DbxRequestConfig.newBuilder(clientUserAgentId).withHttpRequestor(requestor).build();
return new DbxClientV2(requestConfig, auth.getAccessToken(), auth.getHost());
}
Aggregations