本文整理汇总了Java中com.dropbox.core.DbxClient类的典型用法代码示例。如果您正苦于以下问题:Java DbxClient类的具体用法?Java DbxClient怎么用?Java DbxClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DbxClient类属于com.dropbox.core包,在下文中一共展示了DbxClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isAuthenticated
import com.dropbox.core.DbxClient; //导入依赖的package包/类
@Override
public boolean isAuthenticated() {
if (authenticated) {
return true;
} else {
System.out.println("check credentials file");
Credentials cred = new Credentials();
String token = cred.checkCredentialsFile("dropbox");
if (token != null && !token.isEmpty()) {
dbClient = new DbxClient(config, token);
if (isValidToken()) {
authenticated = true;
bearerToken = token;
return true;
} else {
return false;
}
} else {
return false;
}
}
}
示例2: upload
import com.dropbox.core.DbxClient; //导入依赖的package包/类
public String upload(File fileToUpload) throws UploadException {
DbxRequestConfig dconfig = new DbxRequestConfig("sc-java", Locale
.getDefault().toString());
DbxClient client = new DbxClient(dconfig, config.getDropboxConfig()
.getAccessToken());
DbxEntry.File uploadedFile = null;
String shareLink = null;
try (InputStream inputStream = new FileInputStream(fileToUpload);) {
uploadedFile = client.uploadFile("/" + fileToUpload.getName(),
DbxWriteMode.add(), fileToUpload.length(), inputStream);
shareLink = client.createShareableUrl(uploadedFile.path);
} catch (DbxException | IOException e) {
throw new UploadException(e);
}
return shareLink;
}
示例3: subirArchivo
import com.dropbox.core.DbxClient; //导入依赖的package包/类
/**
* Permite subir el fichero de log a una cuenta de Dropbox
* @throws DbxException
* @throws IOException
*/
public void subirArchivo() throws DbxException, IOException{
DbxRequestConfig config = new DbxRequestConfig(
"JavaTutorial/1.0", Locale.getDefault().toString());
String accessToken = "cGF10uurG7MAAAAAAAAFGGi0UJD9H-TpMKBgESMHV5kDy5jTeF7ou8It1HY8ZFC7";
DbxClient client = new DbxClient(config, accessToken);
System.out.println("Linked account: " + client.getAccountInfo().displayName);
FileInputStream inputStream = new FileInputStream(archivoLog);
try {
DbxEntry.File uploadedFile = client.uploadFile(
"/ArchivoLog_ " + TheHouseOfCrimes.getUsuario() + "_" + TheHouseOfCrimes.getFecha(),
DbxWriteMode.add(), archivoLog.length(), inputStream);
System.out.println("Uploaded: " + uploadedFile.toString());
} finally {
inputStream.close();
}
}
示例4: getDbxTexEntries
import com.dropbox.core.DbxClient; //导入依赖的package包/类
/**
* @return List with user's files or empty List if error occurs
*/
public List<DbxEntryDto> getDbxTexEntries(DbxClient client) {
List<DbxEntryDto> dbxEntries = new ArrayList<>();
if (client == null) {
return dbxEntries;
}
try {
for (DbxEntry entry : client.searchFileAndFolderNames("/", TEX_EXTENSION)) {
dbxEntries.add(new DbxEntryDto(entry));
}
} catch (DbxException ex) {
DbxUtil.showDbxAccessDeniedPrompt();
dbxEntries = new ArrayList<>(); //Empty list
} finally {
return dbxEntries;
}
}
示例5: downloadRemoteFile
import com.dropbox.core.DbxClient; //导入依赖的package包/类
public static File downloadRemoteFile(DbxEntryDto remoteEntry, String localPath) {
DbxClient client = getDbxClient();
FileOutputStream outputStream = null;
File outputFile = new File(localPath);
try {
outputStream = new FileOutputStream(outputFile);
client.getFile(remoteEntry.getPath(), remoteEntry.getRevision(), outputStream);
} catch (DbxException | IOException ex) {
Exceptions.printStackTrace(ex);
} finally {
IOUtils.closeQuietly(outputStream);
}
return outputFile;
}
示例6: ls
import com.dropbox.core.DbxClient; //导入依赖的package包/类
public static DbxEntry[] ls(String query, DbxClient client) throws DbxException {
DbxEntry.WithChildren listing = client.getMetadataWithChildren(query);
if(listing == null) {
return new DbxEntry[]{};
}
if(listing.entry.isFile()) {
return new DbxEntry[]{listing.entry};
}
DbxEntry[] dirents = new DbxEntry[listing.children.size()];
int idx = 0;
for (DbxEntry child : listing.children) {
dirents[idx++] = child;
}
return dirents;
}
示例7: listFilesAndDirectories
import com.dropbox.core.DbxClient; //导入依赖的package包/类
@Override
public FileInstanceAbstract[] listFilesAndDirectories() throws URISyntaxException, IOException {
try {
DbxClient dbxClient = connect();
DbxEntry.WithChildren entries;
entries = dbxClient.getMetadataWithChildren(getPath());
if (entries == null || entries.children == null)
return null;
FileInstanceAbstract[] fileInstances = new FileInstanceAbstract[entries.children.size()];
int i = 0;
for (DbxEntry entry : entries.children)
fileInstances[i++] = new DropboxFileInstance(filePathItem, this, entry);
return fileInstances;
} catch (DbxException e) {
throw new IOException(e);
}
}
示例8: importFilesFromDropbox
import com.dropbox.core.DbxClient; //导入依赖的package包/类
private void importFilesFromDropbox(DbxEntry entry, String bcIdentifier, DbxClient client) throws Exception {
String fileName = entry.name;
if (null != fileName) {
int indexOfDot = fileName.indexOf('.');
if (-1 != indexOfDot) {
BatchClass batchClass = batchClassService.getBatchClassByIdentifier(bcIdentifier);
if (batchClass != null) {
String uncFolder = batchClassService.getBatchClassByIdentifier(bcIdentifier).getUncFolder();
String destinationFolder = EphesoftStringUtil.concatenate(new Object[] { uncFolder, File.separator, fileName.substring(0, indexOfDot), Character.valueOf('_'),
Long.valueOf(System.currentTimeMillis()) });
String destinationFile = EphesoftStringUtil.concatenate(new String[] { destinationFolder, File.separator, fileName });
File folder = new File(destinationFolder);
if (!folder.exists())
folder.mkdir();
FileOutputStream outputStream = new FileOutputStream(destinationFile);
client.getFile(entry.path, null, outputStream);
} else
LOGGER.debug(bcIdentifier + " doesn't exist.");
}
}
}
示例9: call
import com.dropbox.core.DbxClient; //导入依赖的package包/类
@Override
protected final void call(final DbxClient client, final ProgressMonitor pm) throws DbxException {
final Iterable<DbxEntry> entries;
pm.begin(1);
if (list) {
if (hash == null) {
entries = from(client.getMetadataWithChildren(path));
} else {
final Maybe<WithChildren> metadata = client.getMetadataWithChildrenIfChanged(path, hash);
entries = metadata.isNothing() ? Collections.<DbxEntry> emptyList() : from(metadata.getJust());
}
} else {
entries = singletonList(client.getMetadata(path));
}
for (final DbxEntry entry : entries) {
getLog().info(entry.toString());
}
}
示例10: call
import com.dropbox.core.DbxClient; //导入依赖的package包/类
@Override
protected final void call(final DbxClient client, final ProgressMonitor pm) throws IOException, DbxException {
final long fileLength = file.length();
Uploader uploader = null;
pm.begin(fileLength);
final DbxWriteMode writeMode = overwrite ? DbxWriteMode.force() : DbxWriteMode.update(parent_rev);
try (InputStream in = new FileInputStream(file)) {
uploader = client.startUploadFile(path, writeMode, fileLength);
final OutputStream body = uploader.getBody();
final byte[] buffer = new byte[bufferSize];
int read = 0;
while ((read = in.read(buffer)) > -1) {
body.write(buffer, 0, read);
pm.worked(read);
}
uploader.finish();
} finally {
close(uploader);
}
}
示例11: call
import com.dropbox.core.DbxClient; //导入依赖的package包/类
@Override
protected final void call(final DbxClient client, final ProgressMonitor pm) throws IOException, DbxException {
final int dataSize = (int) Math.min(chunkSize, file.length() - offset);
pm.begin(file.length());
final byte[] data = new byte[dataSize];
try (InputStream in = new FileInputStream(file)) {
in.skip(offset);
final int read = in.read(data);
if (upload_id == null) {
getLog().info("upload_id=" + client.chunkedUploadFirst(data, 0, read));
} else {
final long correctOffset = client.chunkedUploadAppend(upload_id, offset, data);
if (correctOffset != -1) {
getLog().error("expected the offset to be " + correctOffset);
}
}
pm.worked(offset + read);
}
}
示例12: getInstance
import com.dropbox.core.DbxClient; //导入依赖的package包/类
/**
* Return a singleton instance of this class
* @param client the DbxClient performing dropbox low level operations
* @return the singleton instance of this class
*/
public static DropboxAPIFacade getInstance(DbxClient client) {
if (instance == null) {
instance = new DropboxAPIFacade();
DropboxAPIFacade.client = client;
}
return instance;
}
示例13: collectDropboxEntries
import com.dropbox.core.DbxClient; //导入依赖的package包/类
private void collectDropboxEntries(DbxClient client, Map<String, Long> dropboxEntries, String path) throws DbxException {
WithChildren entries = client.getMetadataWithChildren(path);
for (DbxEntry entry : entries.children) {
if (entry.isFolder()) {
collectDropboxEntries(client, dropboxEntries, entry.path);
} else {
dropboxEntries.put(entry.path, entry.asFile().lastModified.getTime());
}
}
}
示例14: uploadFile
import com.dropbox.core.DbxClient; //导入依赖的package包/类
private void uploadFile(DbxClient client, String dropboxPath, boolean overwrite) throws DbxException, IOException {
File file = new File(contentDir + File.separator + dropboxPath);
FileInputStream inputStream = new FileInputStream(file);
try {
DbxWriteMode mode = overwrite ? DbxWriteMode.force() : DbxWriteMode.add();
DbxEntry.File uploadedFile =
client.uploadFile(dropboxPath, mode, file.length(), inputStream);
logger.debug("successfully uploaded file '{}'. New revision is '{}'", uploadedFile.toString(), uploadedFile.rev);
} finally {
inputStream.close();
}
}
示例15: execute
import com.dropbox.core.DbxClient; //导入依赖的package包/类
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
boolean isUpload =
UPLOAD_JOB_KEY.compareTo(context.getJobDetail().getKey()) == 0;
DropboxSynchronizer synchronizer = DropboxSynchronizer.instance;
if (synchronizer != null) {
try {
DbxClient client = getClient(synchronizer);
if (client != null) {
if (isUpload) {
synchronizer.syncLocalToDropbox(client);
} else {
synchronizer.syncDropboxToLocal(client);
}
} else {
logger.info("Couldn't create Dropbox client. Most likely there has been no "
+ "access token found. Please restart authentication process by typing "
+ "'startAuthentication' on the OSGi console");
}
} catch (Exception e) {
logger.warn("Synchronizing data with Dropbox throws an exception: {}", e.getMessage());
}
} else {
logger.debug("DropboxSynchronizer instance hasn't been initialized properly!");
}
}