Search in sources :

Example 6 with DbxUserFilesRequests

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();
                }
            }
        }
    };
}
Also used : DbxClientV2(com.dropbox.core.v2.DbxClientV2) Task(javafx.concurrent.Task) DropboxFile(com.goxr3plus.xr3player.controllers.dropbox.DropboxFile) FileOutputStream(java.io.FileOutputStream) ProgressOutputStream(com.goxr3plus.xr3player.controllers.dropbox.ProgressOutputStream) IOException(java.io.IOException) DownloadErrorException(com.dropbox.core.v2.files.DownloadErrorException) DbxException(com.dropbox.core.DbxException)

Example 7 with DbxUserFilesRequests

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);
    }
}
Also used : FileFactory(com.mucommander.commons.file.FileFactory) FilePermissions(com.mucommander.commons.file.FilePermissions) ConnectionPool(com.mucommander.commons.file.connection.ConnectionPool) BufferedInputStream(java.io.BufferedInputStream) Date(java.util.Date) ConnectionHandlerFactory(com.mucommander.commons.file.connection.ConnectionHandlerFactory) LoggerFactory(org.slf4j.LoggerFactory) WriteMode(com.dropbox.core.v2.files.WriteMode) ListFolderResult(com.dropbox.core.v2.files.ListFolderResult) BufferedOutputStream(java.io.BufferedOutputStream) CreateFolderResult(com.dropbox.core.v2.files.CreateFolderResult) ByteArrayInputStream(java.io.ByteArrayInputStream) ProtocolFile(com.mucommander.commons.file.protocol.ProtocolFile) FolderMetadata(com.dropbox.core.v2.files.FolderMetadata) SpaceUsage(com.dropbox.core.v2.users.SpaceUsage) DbxUserFilesRequests(com.dropbox.core.v2.files.DbxUserFilesRequests) PermissionBits(com.mucommander.commons.file.PermissionBits) PermissionType(com.mucommander.commons.file.PermissionType) DeletedMetadata(com.dropbox.core.v2.files.DeletedMetadata) OutputStream(java.io.OutputStream) Logger(org.slf4j.Logger) UploadSessionCursor(com.dropbox.core.v2.files.UploadSessionCursor) PermissionAccess(com.mucommander.commons.file.PermissionAccess) IOException(java.io.IOException) RandomAccessInputStream(com.mucommander.commons.io.RandomAccessInputStream) ConnectionHandler(com.mucommander.commons.file.connection.ConnectionHandler) PathUtils(com.mucommander.commons.file.util.PathUtils) FileMetadata(com.dropbox.core.v2.files.FileMetadata) DbxException(com.dropbox.core.DbxException) RandomAccessOutputStream(com.mucommander.commons.io.RandomAccessOutputStream) CommitInfo(com.dropbox.core.v2.files.CommitInfo) FileOperation(com.mucommander.commons.file.FileOperation) UnsupportedFileOperation(com.mucommander.commons.file.UnsupportedFileOperation) FileURL(com.mucommander.commons.file.FileURL) Metadata(com.dropbox.core.v2.files.Metadata) AbstractFile(com.mucommander.commons.file.AbstractFile) UnsupportedFileOperationException(com.mucommander.commons.file.UnsupportedFileOperationException) InputStream(java.io.InputStream) DbxUserFilesRequests(com.dropbox.core.v2.files.DbxUserFilesRequests) FileURL(com.mucommander.commons.file.FileURL) ListFolderResult(com.dropbox.core.v2.files.ListFolderResult) DeletedMetadata(com.dropbox.core.v2.files.DeletedMetadata) DbxException(com.dropbox.core.DbxException)

Example 8 with DbxUserFilesRequests

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);
    }
}
Also used : Delete(ch.cyberduck.core.features.Delete) DbxUserFilesRequests(com.dropbox.core.v2.files.DbxUserFilesRequests) DbxException(com.dropbox.core.DbxException)

Example 9 with DbxUserFilesRequests

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);
    }
}
Also used : Path(ch.cyberduck.core.Path) DbxUserFilesRequests(com.dropbox.core.v2.files.DbxUserFilesRequests) AttributedList(ch.cyberduck.core.AttributedList) ListFolderResult(com.dropbox.core.v2.files.ListFolderResult) DbxRawClientV2(com.dropbox.core.v2.DbxRawClientV2) DbxException(com.dropbox.core.DbxException)

Aggregations

DbxException (com.dropbox.core.DbxException)9 DbxUserFilesRequests (com.dropbox.core.v2.files.DbxUserFilesRequests)8 Path (ch.cyberduck.core.Path)3 AttributedList (ch.cyberduck.core.AttributedList)2 FileMetadata (com.dropbox.core.v2.files.FileMetadata)2 ListFolderResult (com.dropbox.core.v2.files.ListFolderResult)2 IOException (java.io.IOException)2 DescriptiveUrl (ch.cyberduck.core.DescriptiveUrl)1 BackgroundException (ch.cyberduck.core.exception.BackgroundException)1 InteroperabilityException (ch.cyberduck.core.exception.InteroperabilityException)1 NotfoundException (ch.cyberduck.core.exception.NotfoundException)1 Delete (ch.cyberduck.core.features.Delete)1 HttpRange (ch.cyberduck.core.http.HttpRange)1 DefaultStreamCloser (ch.cyberduck.core.io.DefaultStreamCloser)1 HostPreferences (ch.cyberduck.core.preferences.HostPreferences)1 ScheduledThreadPool (ch.cyberduck.core.threading.ScheduledThreadPool)1 DbxClientV2 (com.dropbox.core.v2.DbxClientV2)1 DbxRawClientV2 (com.dropbox.core.v2.DbxRawClientV2)1 CommitInfo (com.dropbox.core.v2.files.CommitInfo)1 CreateFolderResult (com.dropbox.core.v2.files.CreateFolderResult)1