use of com.dropbox.core.v2.DbxRawClientV2 in project XR3Player by goxr3plus.
the class DownloadService method createTask.
@Override
protected Task<Boolean> createTask() {
return new Task<Boolean>() {
@Override
protected Boolean call() throws Exception {
try {
// Create the Client
client = new DbxClientV2(config, dropBoxViewer.getAccessToken());
// Try to download the File
downloadFile(client, dropboxFile, localFileAbsolutePath);
// Show message to the User
Platform.runLater(() -> AlertTool.showNotification("Download completed", "Completed downloading " + (!dropboxFile.isDirectory() ? "File" : FOLDER) + " :\n[ " + dropboxFile.getMetadata().getName() + " ]", Duration.millis(3000), NotificationType.SIMPLE, JavaFXTool.getFontIcon("fa-dropbox", DropboxViewer.FONT_ICON_COLOR, 64)));
// Update the progress
updateProgress(1, 1);
return true;
} catch (final Exception ex) {
ex.printStackTrace();
// Show message to the User
Platform.runLater(() -> AlertTool.showNotification("Download Failed", "Failed to download " + (!dropboxFile.isDirectory() ? "File" : FOLDER) + ":\n[ " + dropboxFile.getMetadata().getName() + " ]", Duration.millis(3000), NotificationType.ERROR));
return false;
}
}
/**
* Download Dropbox File to Local Computer
*
* @param client Current connected client
* @param dropboxFile The file path on the Dropbox cloud server ->
* [/foldername/something.txt] or a Folder [/fuck]
* @param localFileAbsolutePath The absolute file path of the File on the Local
* File System
* @throws DbxException
* @throws DownloadErrorException
* @throws IOException
*/
public void downloadFile(final DbxClientV2 client, final DropboxFile dropboxFile, final String localFileAbsolutePath) throws DownloadErrorException, DbxException, IOException {
final String dropBoxFilePath = dropboxFile.getMetadata().getPathLower();
// Simple File
if (!dropboxFile.isDirectory()) {
// Create DbxDownloader
downloadFile = client.files().download(dropBoxFilePath);
try (// FileOutputStream
FileOutputStream fOut = new FileOutputStream(localFileAbsolutePath);
// ProgressOutPutStream
ProgressOutputStream output = new ProgressOutputStream(fOut, downloadFile.getResult().getSize(), (long completed, long totalSize) -> {
// System.out.println( ( completed * 100 ) / totalSize + " %")
updateProgress((completed * 100), totalSize);
})) {
// FileOutputStream
System.out.println("Downloading .... " + dropBoxFilePath);
// Add a progress Listener
downloadFile.download(output);
// Fast way...
// client.files().downloadBuilder(file).download(new
// FileOutputStream("downloads/" + md.getName()))
// DbxRawClientV2 rawClient = new
// DbxRawClientV2(config,dropBoxViewer.getAccessToken())
// DbxUserFilesRequests r = new DbxUserFilesRequests(client)
} catch (final Exception ex) {
ex.printStackTrace();
}
// Directory
} else {
// Create DbxDownloader
downloadFolder = client.files().downloadZip(dropBoxFilePath);
try (// FileOutputStream
FileOutputStream fOut = new FileOutputStream(localFileAbsolutePath)) {
// FileOutputStream
System.out.println("Downloading .... " + dropBoxFilePath);
// Add a progress Listener
downloadFolder.download(fOut);
} catch (final Exception ex) {
ex.printStackTrace();
}
}
}
};
}
use of com.dropbox.core.v2.DbxRawClientV2 in project cyberduck by iterate-ch.
the class DropboxListService method list.
@Override
public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException {
try {
final AttributedList<Path> children = new AttributedList<>();
ListFolderResult result;
final DbxRawClientV2 client;
this.parse(directory, listener, children, result = new DbxUserFilesRequests(session.getClient(directory)).listFolder(containerService.getKey(directory)));
// If true, then there are more entries available. Pass the cursor to list_folder/continue to retrieve the rest.
while (result.getHasMore()) {
this.parse(directory, listener, children, result = new DbxUserFilesRequests(session.getClient(directory)).listFolderContinue(result.getCursor()));
}
return children;
} catch (DbxException e) {
throw new DropboxExceptionMappingService().map("Listing directory {0} failed", e, directory);
}
}
Aggregations