use of ch.cyberduck.core.transfer.DisabledTransferPrompt in project cyberduck by iterate-ch.
the class GoogleStorageSingleTransferWorkerTest method testDownload.
@Test
public void testDownload() throws Exception {
final Path home = new Path("cyberduck-test-eu", EnumSet.of(Path.Type.volume, Path.Type.directory));
final Path test = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final Local localFile = new DefaultTemporaryFileService().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 GoogleStorageWriteFeature(session).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 HttpResponseOutputStream<StorageObject> out = new GoogleStorageWriteFeature(session).write(test, writeStatus, new DisabledConnectionCallback());
assertNotNull(out);
new StreamCopier(writeStatus, writeStatus).withLimit((long) content.length).transfer(new ByteArrayInputStream(content), out);
out.close();
final String versionId = String.valueOf(out.getStatus().getId());
assertNotNull(versionId);
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 GoogleStorageDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
localFile.delete();
}
use of ch.cyberduck.core.transfer.DisabledTransferPrompt in project cyberduck by iterate-ch.
the class CryptoS3SingleTransferWorkerTest method testUpload.
@Test
public void testUpload() throws Exception {
final Path home = new Path("test-eu-central-1-cyberduck", EnumSet.of(Path.Type.volume, Path.Type.directory));
final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
final Path dir1 = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
final Local localDirectory1 = new Local(System.getProperty("java.io.tmpdir"), new AlphanumericRandomStringService().random());
new DefaultLocalDirectoryFeature().mkdir(localDirectory1);
final byte[] content = RandomUtils.nextBytes(62768);
final Path file1 = new Path(dir1, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final Local localFile1 = new Local(localDirectory1, file1.getName());
final OutputStream out1 = localFile1.getOutputStream(false);
IOUtils.write(content, out1);
out1.close();
final Path file2 = new Path(dir1, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final Local localFile2 = new Local(localDirectory1, file2.getName());
final OutputStream out2 = localFile2.getOutputStream(false);
IOUtils.write(content, out2);
out2.close();
final CryptoVault cryptomator = new CryptoVault(vault);
cryptomator.create(session, new VaultCredentials("test"), new DisabledPasswordStore(), vaultVersion);
session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
final Transfer t = new UploadTransfer(new Host(new TestProtocol()), Collections.singletonList(new TransferItem(dir1, localDirectory1)), 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));
assertTrue(new CryptoFindFeature(session, new S3FindFeature(session), cryptomator).find(dir1));
assertEquals(content.length, new CryptoAttributesFeature(session, new S3AttributesFinderFeature(session), cryptomator).find(file1).getSize());
{
final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
final InputStream in = new CryptoReadFeature(session, new S3ReadFeature(session), cryptomator).read(file1, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(in, buffer);
assertArrayEquals(content, buffer.toByteArray());
}
assertEquals(content.length, new CryptoAttributesFeature(session, new S3AttributesFinderFeature(session), cryptomator).find(file2).getSize());
{
final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
final InputStream in = new CryptoReadFeature(session, new S3ReadFeature(session), cryptomator).read(file1, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(in, buffer);
assertArrayEquals(content, buffer.toByteArray());
}
cryptomator.getFeature(session, Delete.class, new S3DefaultDeleteFeature(session)).delete(Arrays.asList(file1, file2, dir1, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
localFile1.delete();
localFile2.delete();
localDirectory1.delete();
}
use of ch.cyberduck.core.transfer.DisabledTransferPrompt in project cyberduck by iterate-ch.
the class S3SingleTransferWorkerTest method testTransferredSizeRepeat.
@Test
public void testTransferredSizeRepeat() throws Exception {
final Local local = new Local(System.getProperty("java.io.tmpdir"), new AlphanumericRandomStringService().random());
// Minimum multipart upload size
final byte[] content = new byte[6 * 1024 * 1024];
new Random().nextBytes(content);
final OutputStream out = local.getOutputStream(false);
IOUtils.write(content, out);
out.close();
final ProtocolFactory factory = new ProtocolFactory(new HashSet<>(Collections.singleton(new S3Protocol())));
final Profile profile = new ProfilePlistReader(factory).read(this.getClass().getResourceAsStream("/S3 (HTTPS).cyberduckprofile"));
final Host host = new Host(profile, profile.getDefaultHostname(), new Credentials(System.getProperties().getProperty("s3.key"), System.getProperties().getProperty("s3.secret")));
final AtomicBoolean failed = new AtomicBoolean();
final S3Session session = new S3Session(host, new DefaultX509TrustManager(), new DefaultX509KeyManager()) {
@Override
@SuppressWarnings("unchecked")
public <T> T _getFeature(final Class<T> type) {
if (type == Upload.class) {
return (T) new S3MultipartUploadService(this, new S3WriteFeature(this), 5 * 1024L * 1024L, 5) {
@Override
protected InputStream decorate(final InputStream in, final MessageDigest digest) {
if (failed.get()) {
// Second attempt successful
return in;
}
return new CountingInputStream(in) {
@Override
protected void beforeRead(final int n) throws IOException {
super.beforeRead(n);
if (this.getByteCount() >= 1024L * 1024L) {
failed.set(true);
throw new SocketTimeoutException();
}
}
};
}
};
}
return super._getFeature(type);
}
};
session.open(Proxy.DIRECT, new DisabledHostKeyCallback(), new DisabledLoginCallback(), new DisabledCancelCallback());
session.login(Proxy.DIRECT, new DisabledLoginCallback(), new DisabledCancelCallback());
final Path home = new Path("test-eu-central-1-cyberduck", EnumSet.of(Path.Type.volume, Path.Type.directory));
final Path test = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final Transfer t = new UploadTransfer(session.getHost(), test, local);
final BytecountStreamListener counter = new BytecountStreamListener();
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(), counter, new DisabledLoginCallback(), new DisabledNotificationService()) {
}.run(session));
local.delete();
assertTrue(t.isComplete());
assertEquals(content.length, new S3AttributesFinderFeature(session).find(test).getSize());
assertEquals(content.length, counter.getRecv(), 0L);
assertEquals(content.length, counter.getSent(), 0L);
assertTrue(failed.get());
new S3DefaultDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.transfer.DisabledTransferPrompt 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();
}
use of ch.cyberduck.core.transfer.DisabledTransferPrompt in project cyberduck by iterate-ch.
the class Terminal method transfer.
protected Exit transfer(final LoginCallback login, final Transfer transfer, final SessionPool source, final SessionPool destination) {
// Transfer
final TransferSpeedometer meter = new TransferSpeedometer(transfer);
final TransferPrompt prompt;
final Host host = transfer.getSource();
if (input.hasOption(TerminalOptionsBuilder.Params.parallel.name())) {
host.setTransfer(Host.TransferType.concurrent);
} else {
host.setTransfer(Host.TransferType.newconnection);
}
if (input.hasOption(TerminalOptionsBuilder.Params.existing.name())) {
prompt = new DisabledTransferPrompt() {
@Override
public TransferAction prompt(final TransferItem file) {
return TransferAction.forName(input.getOptionValue(TerminalOptionsBuilder.Params.existing.name()));
}
};
} else if (input.hasOption(TerminalOptionsBuilder.Params.quiet.name())) {
prompt = new DisabledTransferPrompt() {
@Override
public TransferAction prompt(final TransferItem file) {
return TransferAction.comparison;
}
};
} else {
prompt = new TerminalTransferPrompt(transfer.getType());
}
final TerminalTransferBackgroundAction action = new TerminalTransferBackgroundAction(controller, source, destination, transfer.withCache(cache), new TransferOptions().reload(true), prompt, login, new TerminalTransferErrorCallback(reader), meter, input.hasOption(TerminalOptionsBuilder.Params.quiet.name()) ? new DisabledStreamListener() : new TerminalStreamListener(meter));
try {
this.execute(action);
} catch (TerminalBackgroundException e) {
return Exit.failure;
}
return Exit.success;
}
Aggregations