Search in sources :

Example 1 with DisabledListProgressListener

use of ch.cyberduck.core.DisabledListProgressListener in project cyberduck by iterate-ch.

the class DefaultAttributesFinderFeatureTest method testFindLargeUpload.

@Test
public void testFindLargeUpload() throws Exception {
    final Path bucket = new Path("test-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final Path file = new Path(bucket, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final B2StartLargeFileResponse startResponse = session.getClient().startLargeFileUpload(new B2VersionIdProvider(session).getVersionId(bucket, new DisabledListProgressListener()), file.getName(), null, Collections.emptyMap());
    file.attributes().setVersionId(startResponse.getFileId());
    final B2VersionIdProvider fileid = new B2VersionIdProvider(session);
    assertTrue(new B2FindFeature(session, fileid).find(file));
    assertTrue(new DefaultFindFeature(session).find(file));
    session.getClient().cancelLargeFileUpload(startResponse.getFileId());
}
Also used : Path(ch.cyberduck.core.Path) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) B2StartLargeFileResponse(synapticloop.b2.response.B2StartLargeFileResponse) B2VersionIdProvider(ch.cyberduck.core.b2.B2VersionIdProvider) B2FindFeature(ch.cyberduck.core.b2.B2FindFeature) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) AbstractB2Test(ch.cyberduck.core.b2.AbstractB2Test) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 2 with DisabledListProgressListener

use of ch.cyberduck.core.DisabledListProgressListener in project cyberduck by iterate-ch.

the class BoxWriteFeature method write.

@Override
public HttpResponseOutputStream<File> write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
    final DelayedHttpEntityCallable<File> command = new DelayedHttpEntityCallable<File>() {

        @Override
        public File call(final AbstractHttpEntity entity) throws BackgroundException {
            try {
                final HttpPost request;
                if (status.isExists()) {
                    request = new HttpPost(String.format("%s/files/%s/content?fields=%s", client.getBasePath(), fileid.getFileId(file, new DisabledListProgressListener()), String.join(",", BoxAttributesFinderFeature.DEFAULT_FIELDS)));
                } else {
                    request = new HttpPost(String.format("%s/files/content?fields=%s", client.getBasePath(), String.join(",", BoxAttributesFinderFeature.DEFAULT_FIELDS)));
                }
                final Checksum checksum = status.getChecksum();
                if (Checksum.NONE != checksum) {
                    switch(checksum.algorithm) {
                        case sha1:
                            request.addHeader(HttpHeaders.CONTENT_MD5, checksum.hash);
                    }
                }
                final ByteArrayOutputStream content = new ByteArrayOutputStream();
                new JSON().getContext(null).writeValue(content, new FilescontentAttributes().name(file.getName()).parent(new FilescontentAttributesParent().id(fileid.getFileId(file.getParent(), new DisabledListProgressListener()))).contentModifiedAt(status.getTimestamp() != null ? new DateTime(status.getTimestamp()) : null));
                final MultipartEntityBuilder multipart = MultipartEntityBuilder.create();
                multipart.addBinaryBody("attributes", content.toByteArray());
                final ByteArrayOutputStream out = new ByteArrayOutputStream();
                entity.writeTo(out);
                multipart.addBinaryBody("file", out.toByteArray(), null == status.getMime() ? ContentType.APPLICATION_OCTET_STREAM : ContentType.create(status.getMime()), file.getName());
                request.setEntity(multipart.build());
                if (status.isExists()) {
                    if (StringUtils.isNotBlank(status.getRemote().getETag())) {
                        request.addHeader(new BasicHeader(HttpHeaders.IF_MATCH, status.getRemote().getETag()));
                    } else {
                        log.warn(String.format("Missing remote attributes in transfer status to read current ETag for %s", file));
                    }
                }
                final Files files = session.getClient().execute(request, new BoxClientErrorResponseHandler<Files>() {

                    @Override
                    public Files handleEntity(final HttpEntity entity) throws IOException {
                        return new JSON().getContext(null).readValue(entity.getContent(), Files.class);
                    }
                });
                if (log.isDebugEnabled()) {
                    log.debug(String.format("Received response %s for upload of %s", files, file));
                }
                if (files.getEntries().stream().findFirst().isPresent()) {
                    return files.getEntries().stream().findFirst().get();
                }
                throw new NotfoundException(file.getAbsolute());
            } catch (HttpResponseException e) {
                throw new DefaultHttpResponseExceptionMappingService().map(e);
            } catch (IOException e) {
                throw new DefaultIOExceptionMappingService().map("Upload {0} failed", e, file);
            }
        }

        @Override
        public long getContentLength() {
            return -1L;
        }
    };
    return this.write(file, status, command);
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) NotfoundException(ch.cyberduck.core.exception.NotfoundException) DefaultHttpResponseExceptionMappingService(ch.cyberduck.core.http.DefaultHttpResponseExceptionMappingService) MultipartEntityBuilder(org.apache.http.entity.mime.MultipartEntityBuilder) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) AbstractHttpEntity(org.apache.http.entity.AbstractHttpEntity) HttpEntity(org.apache.http.HttpEntity) JSON(ch.cyberduck.core.box.io.swagger.client.JSON) FilescontentAttributes(ch.cyberduck.core.box.io.swagger.client.model.FilescontentAttributes) HttpResponseException(org.apache.http.client.HttpResponseException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) FilescontentAttributesParent(ch.cyberduck.core.box.io.swagger.client.model.FilescontentAttributesParent) DelayedHttpEntityCallable(ch.cyberduck.core.http.DelayedHttpEntityCallable) DateTime(org.joda.time.DateTime) Checksum(ch.cyberduck.core.io.Checksum) DefaultIOExceptionMappingService(ch.cyberduck.core.DefaultIOExceptionMappingService) Files(ch.cyberduck.core.box.io.swagger.client.model.Files) File(ch.cyberduck.core.box.io.swagger.client.model.File) AbstractHttpEntity(org.apache.http.entity.AbstractHttpEntity) BasicHeader(org.apache.http.message.BasicHeader)

Example 3 with DisabledListProgressListener

use of ch.cyberduck.core.DisabledListProgressListener in project cyberduck by iterate-ch.

the class BoxShareFeature method createFileSharedLink.

private DescriptiveUrl createFileSharedLink(final Path file, final PasswordCallback callback) throws BackgroundException {
    try {
        final String password = this.prompt(file, callback);
        final File link = new SharedLinksFilesApi(new BoxApiClient(session.getClient())).putFilesIdAddSharedLink("shared_link", fileid.getFileId(file, new DisabledListProgressListener()), new FilesFileIdaddSharedLinkBody().sharedLink(new FilesfileIdaddSharedLinkSharedLink().password(password)));
        return new DescriptiveUrl(URI.create(link.getSharedLink().getDownloadUrl()), DescriptiveUrl.Type.signed);
    } catch (ApiException e) {
        throw new BoxExceptionMappingService(fileid).map(e);
    }
}
Also used : DescriptiveUrl(ch.cyberduck.core.DescriptiveUrl) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) FilesFileIdaddSharedLinkBody(ch.cyberduck.core.box.io.swagger.client.model.FilesFileIdaddSharedLinkBody) SharedLinksFilesApi(ch.cyberduck.core.box.io.swagger.client.api.SharedLinksFilesApi) FilesfileIdaddSharedLinkSharedLink(ch.cyberduck.core.box.io.swagger.client.model.FilesfileIdaddSharedLinkSharedLink) File(ch.cyberduck.core.box.io.swagger.client.model.File) ApiException(ch.cyberduck.core.box.io.swagger.client.ApiException)

Example 4 with DisabledListProgressListener

use of ch.cyberduck.core.DisabledListProgressListener in project cyberduck by iterate-ch.

the class BrickListServiceTest method testListRootDefaultChunkSize.

@Test
public void testListRootDefaultChunkSize() throws Exception {
    final AttributedList<Path> list = new BrickListService(session).list(new Path("/", EnumSet.of(directory)), new DisabledListProgressListener());
    assertNotNull(list);
    assertFalse(list.isEmpty());
}
Also used : AbstractPath(ch.cyberduck.core.AbstractPath) Path(ch.cyberduck.core.Path) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 5 with DisabledListProgressListener

use of ch.cyberduck.core.DisabledListProgressListener in project cyberduck by iterate-ch.

the class BrickListServiceTest method testListEmptyDirectory.

@Test
public void testListEmptyDirectory() throws Exception {
    final Path directory = new BrickDirectoryFeature(session).mkdir(new Path(new AlphanumericRandomStringService().random(), EnumSet.of(AbstractPath.Type.directory)), new TransferStatus());
    final AttributedList<Path> list = new BrickListService(session).list(directory, new DisabledListProgressListener());
    assertNotNull(list);
    assertTrue(list.isEmpty());
    new BrickDeleteFeature(session).delete(Collections.singletonList(directory), new DisabledPasswordCallback(), new Delete.DisabledCallback());
}
Also used : AbstractPath(ch.cyberduck.core.AbstractPath) Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Aggregations

DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)401 Path (ch.cyberduck.core.Path)346 Test (org.junit.Test)313 IntegrationTest (ch.cyberduck.test.IntegrationTest)287 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)199 Delete (ch.cyberduck.core.features.Delete)190 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)189 AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)172 DisabledConnectionCallback (ch.cyberduck.core.DisabledConnectionCallback)54 DisabledPasswordCallback (ch.cyberduck.core.DisabledPasswordCallback)54 Host (ch.cyberduck.core.Host)51 PathAttributes (ch.cyberduck.core.PathAttributes)45 IOException (java.io.IOException)40 SimplePathPredicate (ch.cyberduck.core.SimplePathPredicate)37 ByteArrayInputStream (java.io.ByteArrayInputStream)36 AbstractPath (ch.cyberduck.core.AbstractPath)35 StreamCopier (ch.cyberduck.core.io.StreamCopier)35 InputStream (java.io.InputStream)34 VaultCredentials (ch.cyberduck.core.vault.VaultCredentials)33 AttributedList (ch.cyberduck.core.AttributedList)32