use of ch.cyberduck.core.io.StatusOutputStream in project cyberduck by iterate-ch.
the class BoxWriteFeatureTest method testWriteVaultWithTimeStamp.
@Test
public void testWriteVaultWithTimeStamp() throws Exception {
final BoxFileidProvider fileid = new BoxFileidProvider(session);
final Path container = new BoxDirectoryFeature(session, fileid).mkdir(new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), new TransferStatus());
final Path vault = new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
final Path test = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
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 CryptoWriteFeature feature = new CryptoWriteFeature<>(session, new BoxWriteFeature(session, fileid), cryptomator);
final byte[] content = RandomUtils.nextBytes(6 * 1024 * 1024);
final TransferStatus writeStatus = new TransferStatus();
final FileHeader header = cryptomator.getFileHeaderCryptor().create();
writeStatus.setHeader(cryptomator.getFileHeaderCryptor().encryptHeader(header));
writeStatus.setNonces(new RandomNonceGenerator());
writeStatus.setLength(-1L);
writeStatus.setTimestamp(Instant.now().getEpochSecond());
final StatusOutputStream out = feature.write(test, writeStatus, new DisabledConnectionCallback());
final ByteArrayInputStream in = new ByteArrayInputStream(content);
final TransferStatus progress = new TransferStatus();
final BytecountStreamListener count = new BytecountStreamListener();
new StreamCopier(new TransferStatus(), progress).withListener(count).transfer(in, out);
assertEquals(content.length, count.getSent());
assertEquals(content.length, count.getRecv());
assertNotNull(out.getStatus());
assertTrue(new CryptoFindFeature(session, new BoxFindFeature(session, fileid), cryptomator).find(test));
final byte[] compare = new byte[content.length];
final InputStream stream = new CryptoReadFeature(session, new BoxReadFeature(session, fileid), cryptomator).read(test, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
IOUtils.readFully(stream, compare);
stream.close();
assertArrayEquals(content, compare);
cryptomator.getFeature(session, Delete.class, new BoxDeleteFeature(session, fileid)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.io.StatusOutputStream in project cyberduck by iterate-ch.
the class BufferWriteFeatureTest method testWriteVault.
@Test
public void testWriteVault() throws Exception {
final BoxFileidProvider fileid = new BoxFileidProvider(session);
final Path container = new BoxDirectoryFeature(session, fileid).mkdir(new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), new TransferStatus());
final Path vault = new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
final Path test = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
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 CryptoWriteFeature feature = new CryptoWriteFeature<>(session, new BufferWriteFeature(session), cryptomator);
final byte[] content = RandomUtils.nextBytes(1024 * 1024);
final TransferStatus writeStatus = new TransferStatus();
final FileHeader header = cryptomator.getFileHeaderCryptor().create();
writeStatus.setHeader(cryptomator.getFileHeaderCryptor().encryptHeader(header));
writeStatus.setNonces(new RandomNonceGenerator());
writeStatus.setChecksum(feature.checksum(test, new TransferStatus()).compute(new ByteArrayInputStream(content), new TransferStatus()));
writeStatus.setLength(content.length);
final StatusOutputStream out = feature.write(test, writeStatus, new DisabledConnectionCallback());
final ByteArrayInputStream in = new ByteArrayInputStream(content);
final TransferStatus progress = new TransferStatus();
final BytecountStreamListener count = new BytecountStreamListener();
new StreamCopier(new TransferStatus(), progress).withListener(count).transfer(in, out);
assertEquals(content.length, count.getSent());
assertEquals(content.length, count.getRecv());
assertTrue(new CryptoFindFeature(session, new BoxFindFeature(session, fileid), cryptomator).find(test));
final byte[] compare = new byte[content.length];
final InputStream stream = new CryptoReadFeature(session, new BoxReadFeature(session, fileid), cryptomator).read(test, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
IOUtils.readFully(stream, compare);
stream.close();
assertArrayEquals(content, compare);
cryptomator.getFeature(session, Delete.class, new BoxDeleteFeature(session, fileid)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.io.StatusOutputStream in project cyberduck by iterate-ch.
the class BufferWriteFeatureTest method testWriteOverwrite.
@Test
public void testWriteOverwrite() throws Exception {
final BoxFileidProvider fileid = new BoxFileidProvider(session);
final BufferWriteFeature feature = new BufferWriteFeature(session);
final Path file = new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
{
final byte[] content = RandomUtils.nextBytes(42512);
final TransferStatus status = new TransferStatus();
status.setLength(content.length);
final StatusOutputStream<Void> out = feature.write(file, status, new DisabledConnectionCallback());
final ByteArrayInputStream in = new ByteArrayInputStream(content);
new StreamCopier(status, status).transfer(in, out);
assertNull(out.getStatus());
assertTrue(new DefaultFindFeature(session).find(file));
final byte[] compare = new byte[content.length];
final InputStream stream = new BoxReadFeature(session, fileid).read(file, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
IOUtils.readFully(stream, compare);
stream.close();
assertArrayEquals(content, compare);
}
{
final byte[] content = RandomUtils.nextBytes(33221);
final TransferStatus status = new TransferStatus().exists(true);
status.setLength(content.length);
final StatusOutputStream<Void> out = feature.write(file, status, new DisabledConnectionCallback());
final ByteArrayInputStream in = new ByteArrayInputStream(content);
new StreamCopier(status, status).transfer(in, out);
assertNull(out.getStatus());
assertTrue(new DefaultFindFeature(session).find(file));
final byte[] compare = new byte[content.length];
final InputStream stream = new BoxReadFeature(session, fileid).read(file, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
IOUtils.readFully(stream, compare);
stream.close();
assertArrayEquals(content, compare);
}
new BoxDeleteFeature(session, fileid).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.io.StatusOutputStream in project cyberduck by iterate-ch.
the class DefaultCopyFeature method copy.
@Override
public Path copy(final Path source, final Path target, final TransferStatus status, final ConnectionCallback callback, final StreamListener listener) throws BackgroundException {
InputStream in;
StatusOutputStream out;
in = from.getFeature(Read.class).read(source, new TransferStatus(status), callback);
Write write = to.getFeature(MultipartWrite.class);
if (null == write) {
// Fallback if multipart write is not available
write = to.getFeature(Write.class);
}
out = write.write(target, status, callback);
new StreamCopier(status, status).withListener(listener).transfer(in, out);
return target.withAttributes(status.getResponse());
}
use of ch.cyberduck.core.io.StatusOutputStream in project cyberduck by iterate-ch.
the class RenameExistingFilterTest method testTemporaryDirectoryUpload.
@Test
public void testTemporaryDirectoryUpload() throws Exception {
final Path file = new Path("/t", EnumSet.of(Path.Type.directory));
final AtomicBoolean found = new AtomicBoolean();
final AtomicBoolean moved = new AtomicBoolean();
final Find find = new Find() {
@Override
public boolean find(final Path f, final ListProgressListener listener) {
if (f.equals(file)) {
found.set(true);
return true;
}
return false;
}
};
final AttributesFinder attributes = new AttributesFinder() {
@Override
public PathAttributes find(final Path file, final ListProgressListener listener) {
return new PathAttributes();
}
};
final Host host = new Host(new TestProtocol());
final NullSession session = new NullSession(host) {
@Override
@SuppressWarnings("unchecked")
public <T> T _getFeature(final Class<T> type) {
if (type.equals(Move.class)) {
return (T) new Move() {
@Override
public Path move(final Path f, final Path renamed, TransferStatus status, final Delete.Callback callback, final ConnectionCallback connectionCallback) {
assertFalse(moved.get());
assertEquals(file, f);
moved.set(true);
return renamed;
}
@Override
public boolean isRecursive(final Path source, final Path target) {
return true;
}
};
}
if (type.equals(Write.class)) {
return (T) new Write<Void>() {
@Override
public StatusOutputStream write(final Path file, final TransferStatus status, final ConnectionCallback callback) {
fail();
return null;
}
@Override
public Append append(final Path file, final TransferStatus status) {
fail();
return new Append(false);
}
};
}
return null;
}
};
final RenameExistingFilter f = new RenameExistingFilter(new DisabledUploadSymlinkResolver(), session, new UploadFilterOptions(host).withTemporary(true));
f.withFinder(find).withAttributes(attributes);
final TransferStatus status = f.prepare(file, new NullLocal("/t") {
@Override
public boolean isDirectory() {
return true;
}
@Override
public boolean isFile() {
return false;
}
}, new TransferStatus().exists(true), new DisabledProgressListener());
assertTrue(found.get());
assertNull(status.getRename().remote);
assertNull(status.getRename().local);
assertFalse(moved.get());
f.apply(file, new NullLocal("/t") {
@Override
public boolean isDirectory() {
return true;
}
}, new TransferStatus().exists(true), new DisabledProgressListener());
assertTrue(moved.get());
}
Aggregations