Search in sources :

Example 1 with PathAttributes

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

the class B2WriteFeatureTest method testWrite.

@Test
public void testWrite() throws Exception {
    final TransferStatus status = new TransferStatus();
    final int length = 1048576;
    final byte[] content = RandomUtils.nextBytes(length);
    status.setLength(content.length);
    final Path home = new Path("/test-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final CryptoVault cryptomator = new CryptoVault(new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)));
    final Path vault = cryptomator.create(session, new VaultCredentials("test"), new DisabledPasswordStore(), vaultVersion);
    final Path test = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
    final B2VersionIdProvider fileid = new B2VersionIdProvider(session);
    final CryptoWriteFeature<BaseB2Response> writer = new CryptoWriteFeature<BaseB2Response>(session, new B2WriteFeature(session, fileid), cryptomator);
    final FileHeader header = cryptomator.getFileHeaderCryptor().create();
    status.setHeader(cryptomator.getFileHeaderCryptor().encryptHeader(header));
    status.setNonces(new RotatingNonceGenerator(cryptomator.numberOfChunks(content.length)));
    status.setChecksum(writer.checksum(test, status).compute(new ByteArrayInputStream(content), status));
    final OutputStream out = writer.write(test, status, new DisabledConnectionCallback());
    assertNotNull(out);
    new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out);
    out.close();
    assertTrue(new CryptoFindFeature(session, new B2FindFeature(session, fileid), cryptomator).find(test));
    final PathAttributes attributes = new CryptoAttributesFeature(session, new B2AttributesFinderFeature(session, fileid), cryptomator).find(test);
    assertEquals(content.length, attributes.getSize());
    assertEquals(content.length, writer.append(test, status.withRemote(attributes)).size, 0L);
    final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
    final InputStream in = new CryptoReadFeature(session, new B2ReadFeature(session, fileid), cryptomator).read(test, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
    new StreamCopier(status, status).transfer(in, buffer);
    assertArrayEquals(content, buffer.toByteArray());
    cryptomator.getFeature(session, Delete.class, new B2DeleteFeature(session, fileid)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : Delete(ch.cyberduck.core.features.Delete) B2ReadFeature(ch.cyberduck.core.b2.B2ReadFeature) CryptoWriteFeature(ch.cyberduck.core.cryptomator.features.CryptoWriteFeature) B2VersionIdProvider(ch.cyberduck.core.b2.B2VersionIdProvider) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) B2AttributesFinderFeature(ch.cyberduck.core.b2.B2AttributesFinderFeature) RotatingNonceGenerator(ch.cyberduck.core.cryptomator.random.RotatingNonceGenerator) B2DeleteFeature(ch.cyberduck.core.b2.B2DeleteFeature) DefaultVaultRegistry(ch.cyberduck.core.vault.DefaultVaultRegistry) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) CryptoReadFeature(ch.cyberduck.core.cryptomator.features.CryptoReadFeature) FileHeader(org.cryptomator.cryptolib.api.FileHeader) Path(ch.cyberduck.core.Path) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PathAttributes(ch.cyberduck.core.PathAttributes) B2WriteFeature(ch.cyberduck.core.b2.B2WriteFeature) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CryptoFindFeature(ch.cyberduck.core.cryptomator.features.CryptoFindFeature) CryptoAttributesFeature(ch.cyberduck.core.cryptomator.features.CryptoAttributesFeature) ByteArrayInputStream(java.io.ByteArrayInputStream) B2FindFeature(ch.cyberduck.core.b2.B2FindFeature) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) BaseB2Response(synapticloop.b2.response.BaseB2Response) DisabledPasswordStore(ch.cyberduck.core.DisabledPasswordStore) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) StreamCopier(ch.cyberduck.core.io.StreamCopier) AbstractB2Test(ch.cyberduck.core.b2.AbstractB2Test) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 2 with PathAttributes

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

the class BrickMultipartWriteFeatureTest method testWriteSinglePart.

@Test
public void testWriteSinglePart() throws Exception {
    final BrickMultipartWriteFeature feature = new BrickMultipartWriteFeature(session, 5 * 1024 * 1024);
    final Path container = new Path("/", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final TransferStatus status = new TransferStatus();
    status.setLength(-1L);
    final Path file = new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final HttpResponseOutputStream<FileEntity> out = feature.write(file, status, new DisabledConnectionCallback());
    final byte[] content = RandomUtils.nextBytes(4 * 1024 * 1024);
    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());
    in.close();
    out.close();
    assertNull(out.getStatus());
    assertTrue(new BrickFindFeature(session).find(file));
    final PathAttributes attributes = new BrickAttributesFinderFeature(session).find(file);
    assertEquals(content.length, attributes.getSize());
    final byte[] compare = new byte[content.length];
    final InputStream stream = new BrickReadFeature(session).read(file, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
    IOUtils.readFully(stream, compare);
    stream.close();
    assertArrayEquals(content, compare);
    new BrickDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) FileEntity(ch.cyberduck.core.brick.io.swagger.client.model.FileEntity) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PathAttributes(ch.cyberduck.core.PathAttributes) BytecountStreamListener(ch.cyberduck.core.BytecountStreamListener) ByteArrayInputStream(java.io.ByteArrayInputStream) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) StreamCopier(ch.cyberduck.core.io.StreamCopier) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 3 with PathAttributes

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

the class BoxMultipartWriteFeatureTest method testWriteMultiplePartsExisting.

@Test
public void testWriteMultiplePartsExisting() throws Exception {
    final BoxFileidProvider fileid = new BoxFileidProvider(session);
    final BoxMultipartWriteFeature feature = new BoxMultipartWriteFeature(session, fileid);
    // Makes sure to test overwrite
    final Path file = new BoxTouchFeature(session, fileid).touch(new Path(Home.ROOT, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus());
    final byte[] content = RandomUtils.nextBytes(21 * 1024 * 1024);
    final TransferStatus status = new TransferStatus().withRemote(file.attributes()).exists(true).withChecksum(feature.checksum(file, new TransferStatus()).compute(new ByteArrayInputStream(content), new TransferStatus())).withLength(content.length);
    final HttpResponseOutputStream<File> out = feature.write(file, status, 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());
    in.close();
    out.close();
    assertNotNull(out.getStatus());
    assertTrue(new DefaultFindFeature(session).find(file));
    assertTrue(new BoxFindFeature(session, fileid).find(file));
    final PathAttributes attributes = new BoxAttributesFinderFeature(session, fileid).find(file);
    assertEquals(content.length, attributes.getSize());
    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());
}
Also used : Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PathAttributes(ch.cyberduck.core.PathAttributes) BytecountStreamListener(ch.cyberduck.core.BytecountStreamListener) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultFindFeature(ch.cyberduck.core.shared.DefaultFindFeature) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) File(ch.cyberduck.core.box.io.swagger.client.model.File) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) StreamCopier(ch.cyberduck.core.io.StreamCopier) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 4 with PathAttributes

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

the class BoxMultipartWriteFeatureTest method testWriteMultipleParts.

@Test
public void testWriteMultipleParts() throws Exception {
    final BoxFileidProvider fileid = new BoxFileidProvider(session);
    final BoxMultipartWriteFeature feature = new BoxMultipartWriteFeature(session, fileid);
    // Makes sure to test overwrite
    final Path file = new Path(Home.ROOT, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final byte[] content = RandomUtils.nextBytes(21 * 1024 * 1024);
    final TransferStatus status = new TransferStatus().withRemote(file.attributes()).exists(false).withChecksum(feature.checksum(file, new TransferStatus()).compute(new ByteArrayInputStream(content), new TransferStatus())).withLength(content.length);
    final HttpResponseOutputStream<File> out = feature.write(file, status, 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());
    in.close();
    out.close();
    assertNotNull(out.getStatus());
    assertTrue(new DefaultFindFeature(session).find(file));
    assertTrue(new BoxFindFeature(session, fileid).find(file));
    final PathAttributes attributes = new BoxAttributesFinderFeature(session, fileid).find(file);
    assertEquals(content.length, attributes.getSize());
    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());
}
Also used : Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PathAttributes(ch.cyberduck.core.PathAttributes) BytecountStreamListener(ch.cyberduck.core.BytecountStreamListener) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultFindFeature(ch.cyberduck.core.shared.DefaultFindFeature) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) File(ch.cyberduck.core.box.io.swagger.client.model.File) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) StreamCopier(ch.cyberduck.core.io.StreamCopier) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 5 with PathAttributes

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

the class BrickAttributesFinderFeatureTest method testFindDirectory.

@Test
public void testFindDirectory() throws Exception {
    final Path folder = new BrickDirectoryFeature(session).mkdir(new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), new TransferStatus());
    final Path test = new BrickDirectoryFeature(session).mkdir(new Path(folder, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), new TransferStatus());
    final BrickAttributesFinderFeature f = new BrickAttributesFinderFeature(session);
    final PathAttributes attributes = f.find(test);
    assertEquals(-1L, attributes.getSize());
    assertNotEquals(-1L, attributes.getModificationDate());
    assertNull(attributes.getChecksum().algorithm);
    assertTrue(attributes.getPermission().isReadable());
    assertTrue(attributes.getPermission().isWritable());
    assertTrue(attributes.getPermission().isExecutable());
    // Test wrong type
    try {
        f.find(new Path(test.getAbsolute(), EnumSet.of(Path.Type.file)));
        fail();
    } catch (NotfoundException e) {
    // Expected
    }
    new BrickDeleteFeature(session).delete(Collections.singletonList(folder), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) NotfoundException(ch.cyberduck.core.exception.NotfoundException) PathAttributes(ch.cyberduck.core.PathAttributes) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Aggregations

PathAttributes (ch.cyberduck.core.PathAttributes)291 Path (ch.cyberduck.core.Path)233 Test (org.junit.Test)200 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)176 IntegrationTest (ch.cyberduck.test.IntegrationTest)175 Delete (ch.cyberduck.core.features.Delete)153 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)143 AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)139 DisabledConnectionCallback (ch.cyberduck.core.DisabledConnectionCallback)74 ByteArrayInputStream (java.io.ByteArrayInputStream)55 StreamCopier (ch.cyberduck.core.io.StreamCopier)49 InputStream (java.io.InputStream)49 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)45 NotfoundException (ch.cyberduck.core.exception.NotfoundException)45 DisabledPasswordCallback (ch.cyberduck.core.DisabledPasswordCallback)41 VaultCredentials (ch.cyberduck.core.vault.VaultCredentials)36 AttributedList (ch.cyberduck.core.AttributedList)34 Local (ch.cyberduck.core.Local)32 Host (ch.cyberduck.core.Host)31 OutputStream (java.io.OutputStream)31