Search in sources :

Example 1 with AzureSession

use of ch.cyberduck.core.azure.AzureSession in project cyberduck by iterate-ch.

the class AzureSingleTransferWorkerTest method download.

private void download(final Host host) throws ch.cyberduck.core.exception.BackgroundException, java.io.IOException {
    final OperationContext context = new OperationContext();
    final AzureSession session = new AzureSession(host);
    session.open(Proxy.DIRECT, new DisabledHostKeyCallback(), new DisabledLoginCallback(), new DisabledCancelCallback());
    session.login(Proxy.DIRECT, new DisabledLoginCallback(), new DisabledCancelCallback());
    final Path home = new Path("cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final Path test = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final Local localFile = TemporaryFileServiceFactory.get().create(test.getName());
    {
        final byte[] content = RandomUtils.nextBytes(39864);
        final TransferStatus writeStatus = new TransferStatus().withLength(content.length).withChecksum(new SHA256ChecksumCompute().compute(new ByteArrayInputStream(content), new TransferStatus()));
        final StatusOutputStream out = new AzureWriteFeature(session, context).write(test, writeStatus, new DisabledConnectionCallback());
        assertNotNull(out);
        new StreamCopier(writeStatus, writeStatus).withLimit((long) content.length).transfer(new ByteArrayInputStream(content), out);
        out.close();
    }
    final byte[] content = RandomUtils.nextBytes(39864);
    final TransferStatus writeStatus = new TransferStatus().withLength(content.length).withChecksum(new SHA256ChecksumCompute().compute(new ByteArrayInputStream(content), new TransferStatus()));
    final StatusOutputStream<Void> out = new AzureWriteFeature(session, context).write(test, writeStatus, new DisabledConnectionCallback());
    assertNotNull(out);
    new StreamCopier(writeStatus, writeStatus).withLimit((long) content.length).transfer(new ByteArrayInputStream(content), out);
    out.close();
    final Transfer t = new DownloadTransfer(new Host(new TestProtocol()), Collections.singletonList(new TransferItem(test, localFile)), new NullFilter<>());
    assertTrue(new SingleTransferWorker(session, session, t, new TransferOptions(), new TransferSpeedometer(t), new DisabledTransferPrompt() {

        @Override
        public TransferAction prompt(final TransferItem file) {
            return TransferAction.overwrite;
        }
    }, new DisabledTransferErrorCallback(), new DisabledProgressListener(), new DisabledStreamListener(), new DisabledLoginCallback(), new DisabledNotificationService()) {
    }.run(session));
    assertArrayEquals(content, IOUtils.toByteArray(localFile.getInputStream()));
    new AzureDeleteFeature(session, context).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
    localFile.delete();
}
Also used : Delete(ch.cyberduck.core.features.Delete) TestProtocol(ch.cyberduck.core.TestProtocol) TransferAction(ch.cyberduck.core.transfer.TransferAction) AzureWriteFeature(ch.cyberduck.core.azure.AzureWriteFeature) TransferOptions(ch.cyberduck.core.transfer.TransferOptions) DownloadTransfer(ch.cyberduck.core.transfer.DownloadTransfer) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) DisabledTransferErrorCallback(ch.cyberduck.core.transfer.DisabledTransferErrorCallback) OperationContext(com.microsoft.azure.storage.OperationContext) Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) DisabledNotificationService(ch.cyberduck.core.notification.DisabledNotificationService) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) AzureSession(ch.cyberduck.core.azure.AzureSession) StatusOutputStream(ch.cyberduck.core.io.StatusOutputStream) Local(ch.cyberduck.core.Local) Host(ch.cyberduck.core.Host) DisabledTransferPrompt(ch.cyberduck.core.transfer.DisabledTransferPrompt) DisabledCancelCallback(ch.cyberduck.core.DisabledCancelCallback) ByteArrayInputStream(java.io.ByteArrayInputStream) DisabledHostKeyCallback(ch.cyberduck.core.DisabledHostKeyCallback) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) AzureDeleteFeature(ch.cyberduck.core.azure.AzureDeleteFeature) Transfer(ch.cyberduck.core.transfer.Transfer) DownloadTransfer(ch.cyberduck.core.transfer.DownloadTransfer) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) TransferSpeedometer(ch.cyberduck.core.transfer.TransferSpeedometer) TransferItem(ch.cyberduck.core.transfer.TransferItem) SHA256ChecksumCompute(ch.cyberduck.core.io.SHA256ChecksumCompute) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) StreamCopier(ch.cyberduck.core.io.StreamCopier)

Aggregations

AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)1 DisabledCancelCallback (ch.cyberduck.core.DisabledCancelCallback)1 DisabledConnectionCallback (ch.cyberduck.core.DisabledConnectionCallback)1 DisabledHostKeyCallback (ch.cyberduck.core.DisabledHostKeyCallback)1 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)1 DisabledProgressListener (ch.cyberduck.core.DisabledProgressListener)1 Host (ch.cyberduck.core.Host)1 Local (ch.cyberduck.core.Local)1 Path (ch.cyberduck.core.Path)1 TestProtocol (ch.cyberduck.core.TestProtocol)1 AzureDeleteFeature (ch.cyberduck.core.azure.AzureDeleteFeature)1 AzureSession (ch.cyberduck.core.azure.AzureSession)1 AzureWriteFeature (ch.cyberduck.core.azure.AzureWriteFeature)1 Delete (ch.cyberduck.core.features.Delete)1 DisabledStreamListener (ch.cyberduck.core.io.DisabledStreamListener)1 SHA256ChecksumCompute (ch.cyberduck.core.io.SHA256ChecksumCompute)1 StatusOutputStream (ch.cyberduck.core.io.StatusOutputStream)1 StreamCopier (ch.cyberduck.core.io.StreamCopier)1 DisabledNotificationService (ch.cyberduck.core.notification.DisabledNotificationService)1 DisabledTransferErrorCallback (ch.cyberduck.core.transfer.DisabledTransferErrorCallback)1