use of com.dropbox.core.v2.files.DbxUserFilesRequests 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.files.DbxUserFilesRequests in project mucommander by mucommander.
the class DropboxFile method ls.
@Override
public AbstractFile[] ls() throws IOException, UnsupportedFileOperationException {
try (DropboxConnectionHandler connHandler = getConnHandler()) {
DbxUserFilesRequests r = connHandler.getDbxClient().files();
ListFolderResult result;
try {
result = r.listFolder(getId());
} catch (DbxException e) {
LOGGER.error("failed to list folder", e);
return null;
}
return result.getEntries().stream().filter(meta -> !(meta instanceof DeletedMetadata)).map(meta -> {
FileURL url = (FileURL) fileURL.clone();
url.setPath(meta.getPathDisplay());
return new DropboxFile(url, this, meta);
}).toArray(AbstractFile[]::new);
}
}
use of com.dropbox.core.v2.files.DbxUserFilesRequests in project cyberduck by iterate-ch.
the class DropboxCopyFeature method copy.
@Override
public Path copy(final Path source, final Path target, final TransferStatus status, final ConnectionCallback callback, final StreamListener listener) throws BackgroundException {
try {
if (status.isExists()) {
new DropboxDeleteFeature(session).delete(Collections.singletonMap(target, status), callback, new Delete.DisabledCallback());
}
// If the source path is a folder all its contents will be copied.
new DbxUserFilesRequests(session.getClient(source)).copyV2(containerService.getKey(source), containerService.getKey(target));
listener.sent(status.getLength());
return target;
} catch (DbxException e) {
throw new DropboxExceptionMappingService().map("Cannot copy {0}", e, source);
}
}
use of com.dropbox.core.v2.files.DbxUserFilesRequests 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