List of usage examples for java.util EnumSet of
public static <E extends Enum<E>> EnumSet<E> of(E e)
From source file:ch.cyberduck.core.cryptomator.FTPWriteFeatureTest.java
@Test public void testWrite() throws Exception { final Host host = new Host(new FTPTLSProtocol(), "test.cyberduck.ch", new Credentials(System.getProperties().getProperty("ftp.user"), System.getProperties().getProperty("ftp.password"))); final FTPSession session = new FTPSession(host); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final TransferStatus status = new TransferStatus(); final int length = 1048576; final byte[] content = RandomUtils.nextBytes(length); status.setLength(content.length);//from w ww .j a v a 2s. c o m final Path home = new DefaultHomeFinderService(session).find(); final Path vault = new Path(home, 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, new DisabledPasswordStore()); cryptomator.create(session, null, new VaultCredentials("test")); session.withRegistry( new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator)); final CryptoWriteFeature<Integer> writer = new CryptoWriteFeature<Integer>(session, new FTPWriteFeature(session), cryptomator); final Cryptor cryptor = cryptomator.getCryptor(); final FileHeader header = cryptor.fileHeaderCryptor().create(); status.setHeader(cryptor.fileHeaderCryptor().encryptHeader(header)); status.setNonces(new RotatingNonceGenerator(cryptomator.numberOfChunks(content.length))); status.setChecksum(writer.checksum(test).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 DefaultFindFeature(session), cryptomator).find(test)); assertEquals(content.length, new CryptoListService(session, session, cryptomator) .list(test.getParent(), new DisabledListProgressListener()).get(test).attributes().getSize()); assertEquals(content.length, new CryptoWriteFeature<>(session, new FTPWriteFeature(session), cryptomator) .append(test, status.getLength(), PathCache.empty()).size, 0L); final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length); final InputStream in = new CryptoReadFeature(session, new FTPReadFeature(session), cryptomator).read(test, new TransferStatus().length(content.length), new DisabledConnectionCallback()); new StreamCopier(status, status).transfer(in, buffer); assertArrayEquals(content, buffer.toByteArray()); new CryptoDeleteFeature(session, new FTPDeleteFeature(session), cryptomator) .delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
From source file:ch.cyberduck.core.cryptomator.DropboxTouchFeatureTest.java
@Test public void testTouchLongFilenameEncryptedDefaultFeature() throws Exception { final Path home = new DefaultHomeFinderService(session).find(); final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)); final Path test = new Path(vault, new RandomStringGenerator.Builder().build().generate(130), EnumSet.of(Path.Type.file)); final CryptoVault cryptomator = new CryptoVault(vault, new DisabledPasswordStore()); cryptomator.create(session, null, new VaultCredentials("test")); session.withRegistry(//w ww. j av a 2 s .co m new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator)); new CryptoTouchFeature<String>(session, new DefaultTouchFeature<String>(new DropboxUploadFeature(new DropboxWriteFeature(session))), new DropboxWriteFeature(session), cryptomator).touch(test, new TransferStatus()); assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(test)); new CryptoDeleteFeature(session, new DropboxDeleteFeature(session), cryptomator) .delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback()); }
From source file:ch.cyberduck.core.cryptomator.SFTPWriteFeatureTest.java
@Test public void testWrite() throws Exception { final Host host = new Host(new SFTPProtocol(), "test.cyberduck.ch", new Credentials(System.getProperties().getProperty("sftp.user"), System.getProperties().getProperty("sftp.password"))); final SFTPSession session = new SFTPSession(host); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final TransferStatus status = new TransferStatus(); final int length = 1048576; final byte[] content = RandomUtils.nextBytes(length); status.setLength(content.length);/*from w w w. j av a 2s. co m*/ final Path home = new SFTPHomeDirectoryService(session).find(); final Path vault = new Path(home, 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, new DisabledPasswordStore()); cryptomator.create(session, null, new VaultCredentials("test")); session.withRegistry( new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator)); final CryptoWriteFeature<Void> writer = new CryptoWriteFeature<>(session, new SFTPWriteFeature(session), cryptomator); final Cryptor cryptor = cryptomator.getCryptor(); final FileHeader header = cryptor.fileHeaderCryptor().create(); status.setHeader(cryptor.fileHeaderCryptor().encryptHeader(header)); status.setNonces(new RandomNonceGenerator()); status.setChecksum(writer.checksum(test).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 SFTPFindFeature(session), cryptomator).find(test)); Assert.assertEquals(content.length, new CryptoListService(session, session, cryptomator) .list(test.getParent(), new DisabledListProgressListener()).get(test).attributes().getSize()); Assert.assertEquals(content.length, writer.append(test, status.getLength(), PathCache.empty()).size, 0L); final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length); final InputStream in = new CryptoReadFeature(session, new SFTPReadFeature(session), cryptomator).read(test, new TransferStatus().length(content.length), new DisabledConnectionCallback()); new StreamCopier(status, status).transfer(in, buffer); assertArrayEquals(content, buffer.toByteArray()); new CryptoDeleteFeature(session, new SFTPDeleteFeature(session), cryptomator) .delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
From source file:ch.cyberduck.core.manta.AbstractMantaTest.java
@Before public void setup() throws Exception { final Profile profile = new ProfilePlistReader( new ProtocolFactory(Collections.singleton(new MantaProtocol()))) .read(new Local("../profiles/Joyent Triton Object Storage.cyberduckprofile")); final String hostname; final Local file; if (ObjectUtils.allNotNull(System.getProperty("manta.key_path"), System.getProperty("manta.url"))) { file = new Local(System.getProperty("manta.key_path")); hostname = new URL(System.getProperty("manta.url")).getHost(); } else {//w w w . ja va2 s. com final String key = System.getProperty("manta.key"); file = TemporaryFileServiceFactory.get().create(new AlphanumericRandomStringService().random()); LocalTouchFactory.get().touch(file); IOUtils.write(key, file.getOutputStream(false), Charset.defaultCharset()); hostname = profile.getDefaultHostname(); } final String user = System.getProperty("manta.user"); final Host host = new Host(profile, hostname, new Credentials(user).withIdentity(file)); session = new MantaSession(host, new DisabledX509TrustManager(), new DefaultX509KeyManager()); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final String testRoot = "cyberduck-test-" + new AlphanumericRandomStringService().random(); testPathPrefix = new Path( new MantaAccountHomeInfo(host.getCredentials().getUsername(), host.getDefaultPath()) .getAccountPrivateRoot(), testRoot, EnumSet.of(Type.directory)); session.getClient().putDirectory(testPathPrefix.getAbsolute()); }
From source file:ch.cyberduck.core.cryptomator.OneDriveTouchFeatureTest.java
@Test public void testTouchLongFilenameEncryptedDefaultFeature() throws Exception { final Path home = new OneDriveHomeFinderFeature(session).find(); final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)); final Path test = new Path(vault, new RandomStringGenerator.Builder().build().generate(130), EnumSet.of(Path.Type.file)); final CryptoVault cryptomator = new CryptoVault(vault, new DisabledPasswordStore()); cryptomator.create(session, null, new VaultCredentials("test")); session.withRegistry(//ww w . jav a2 s .c om new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator)); new CryptoTouchFeature<Void>(session, new DefaultTouchFeature<Void>(new DefaultUploadFeature(new OneDriveWriteFeature(session))), new OneDriveWriteFeature(session), cryptomator).touch(test, new TransferStatus()); assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(test)); new CryptoDeleteFeature(session, new OneDriveDeleteFeature(session), cryptomator) .delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback()); }
From source file:ch.cyberduck.core.cryptomator.SFTPReadFeatureTest.java
@Test public void testReadRange() throws Exception { final Host host = new Host(new SFTPProtocol(), "test.cyberduck.ch", new Credentials(System.getProperties().getProperty("sftp.user"), System.getProperties().getProperty("sftp.password"))); final SFTPSession session = new SFTPSession(host); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final TransferStatus status = new TransferStatus(); final int length = 140000; final byte[] content = RandomUtils.nextBytes(length); status.setLength(content.length);/*w w w .j av a2 s . c o m*/ final Path home = new SFTPHomeDirectoryService(session).find(); final Path vault = new Path(home, 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, new DisabledPasswordStore()); cryptomator.create(session, null, new VaultCredentials("test")); session.withRegistry( new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator)); final CryptoWriteFeature<Void> writer = new CryptoWriteFeature<>(session, new SFTPWriteFeature(session), cryptomator); final Cryptor cryptor = cryptomator.getCryptor(); final FileHeader header = cryptor.fileHeaderCryptor().create(); status.setHeader(cryptor.fileHeaderCryptor().encryptHeader(header)); status.setNonces(new RandomNonceGenerator()); status.setChecksum(writer.checksum(test).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 SFTPFindFeature(session), cryptomator).find(test)); Assert.assertEquals(content.length, new CryptoListService(session, session, cryptomator) .list(test.getParent(), new DisabledListProgressListener()).get(test).attributes().getSize()); Assert.assertEquals(content.length, writer.append(test, status.getLength(), PathCache.empty()).size, 0L); final ByteArrayOutputStream buffer = new ByteArrayOutputStream(30000); final TransferStatus read = new TransferStatus(); read.setOffset(40000); read.setAppend(true); read.length(30000); // ensure to read at least two chunks final InputStream in = new CryptoReadFeature(session, new SFTPReadFeature(session), cryptomator).read(test, read, new DisabledConnectionCallback()); new StreamCopier(read, read).withLimit(30000L).transfer(in, buffer); final byte[] reference = new byte[30000]; System.arraycopy(content, 40000, reference, 0, reference.length); assertArrayEquals(reference, buffer.toByteArray()); new CryptoDeleteFeature(session, new SFTPDeleteFeature(session), cryptomator) .delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
From source file:ch.cyberduck.core.onedrive.OneDriveBufferWriteFeatureTest.java
@Test public void testWriteOverwrite() throws Exception { final OneDriveBufferWriteFeature feature = new OneDriveBufferWriteFeature(session); final Path container = new OneDriveHomeFinderFeature(session).find(); final Path file = new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)); {//from w w w. j a v a2 s.co m final byte[] content = RandomUtils.nextBytes(42512); final TransferStatus status = new TransferStatus(); status.setLength(content.length); final HttpResponseOutputStream<Void> out = feature.write(file, status, new DisabledConnectionCallback()); final ByteArrayInputStream in = new ByteArrayInputStream(content); new StreamCopier(status, status).transfer(in, out); in.close(); out.flush(); out.close(); assertNull(out.getStatus()); assertTrue(new DefaultFindFeature(session).find(file)); final byte[] compare = new byte[content.length]; final InputStream stream = new OneDriveReadFeature(session).read(file, new TransferStatus().length(content.length), new DisabledConnectionCallback()); IOUtils.readFully(stream, compare); stream.close(); assertArrayEquals(content, compare); } { final byte[] content = RandomUtils.nextBytes(33221); final TransferStatus status = new TransferStatus(); status.setLength(content.length); final HttpResponseOutputStream<Void> out = feature.write(file, status, new DisabledConnectionCallback()); final ByteArrayInputStream in = new ByteArrayInputStream(content); new StreamCopier(status, status).transfer(in, out); in.close(); out.flush(); out.close(); assertNull(out.getStatus()); assertTrue(new DefaultFindFeature(session).find(file)); final byte[] compare = new byte[content.length]; final InputStream stream = new OneDriveReadFeature(session).read(file, new TransferStatus().length(content.length), new DisabledConnectionCallback()); IOUtils.readFully(stream, compare); stream.close(); assertArrayEquals(content, compare); } new OneDriveDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback()); }
From source file:ch.cyberduck.core.azure.AzureObjectListService.java
@Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { try {//w ww. j a v a 2s . c o m final CloudBlobContainer container = session.getClient() .getContainerReference(containerService.getContainer(directory).getName()); final AttributedList<Path> children = new AttributedList<Path>(); ResultContinuation token = null; ResultSegment<ListBlobItem> result; String prefix = StringUtils.EMPTY; if (!containerService.isContainer(directory)) { prefix = containerService.getKey(directory); if (!prefix.endsWith(String.valueOf(Path.DELIMITER))) { prefix += Path.DELIMITER; } } do { final BlobRequestOptions options = new BlobRequestOptions(); result = container.listBlobsSegmented(prefix, false, EnumSet.noneOf(BlobListingDetails.class), PreferencesFactory.get().getInteger("azure.listing.chunksize"), token, options, context); for (ListBlobItem object : result.getResults()) { if (new Path(object.getUri().getPath(), EnumSet.of(Path.Type.directory)).equals(directory)) { continue; } final PathAttributes attributes = new PathAttributes(); if (object instanceof CloudBlob) { final CloudBlob blob = (CloudBlob) object; attributes.setSize(blob.getProperties().getLength()); attributes.setModificationDate(blob.getProperties().getLastModified().getTime()); attributes.setETag(blob.getProperties().getEtag()); if (StringUtils.isNotBlank(blob.getProperties().getContentMD5())) { attributes.setChecksum(Checksum.parse(Hex .encodeHexString(Base64.decodeBase64(blob.getProperties().getContentMD5())))); } } // A directory is designated by a delimiter character. final EnumSet<AbstractPath.Type> types = object instanceof CloudBlobDirectory ? EnumSet.of(Path.Type.directory, Path.Type.placeholder) : EnumSet.of(Path.Type.file); final Path child = new Path(directory, PathNormalizer.name(object.getUri().getPath()), types, attributes); children.add(child); } listener.chunk(directory, children); token = result.getContinuationToken(); } while (result.getHasMoreResults()); return children; } catch (StorageException e) { throw new AzureExceptionMappingService().map("Listing directory {0} failed", e, directory); } catch (URISyntaxException e) { throw new NotfoundException(e.getMessage(), e); } }
From source file:ch.cyberduck.core.onedrive.OneDriveWriteFeatureTest.java
@Test public void testWriteUmlaut() throws Exception { final OneDriveWriteFeature feature = new OneDriveWriteFeature(session); final Path container = new OneDriveHomeFinderFeature(session).find(); final byte[] content = RandomUtils.nextBytes(2048); final TransferStatus status = new TransferStatus(); status.setLength(content.length);// www . j a v a 2 s .co m final Path file = new Path(container, String.format("%s", new AlphanumericRandomStringService().random()), EnumSet.of(Path.Type.file)); final HttpResponseOutputStream<Void> out = feature.write(file, status, new DisabledConnectionCallback()); final ByteArrayInputStream in = new ByteArrayInputStream(content); assertEquals(content.length, IOUtils.copyLarge(in, out)); in.close(); out.close(); assertNull(out.getStatus()); assertTrue(new DefaultFindFeature(session).find(file)); final byte[] compare = new byte[content.length]; final InputStream stream = new OneDriveReadFeature(session).read(file, new TransferStatus().length(content.length), new DisabledConnectionCallback()); IOUtils.readFully(stream, compare); stream.close(); assertArrayEquals(content, compare); new OneDriveDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback()); }
From source file:ch.cyberduck.core.irods.IRODSWriteFeatureTest.java
@Test public void testWriteConcurrent() throws Exception { final ProtocolFactory factory = new ProtocolFactory( new HashSet<>(Collections.singleton(new IRODSProtocol()))); final Profile profile = new ProfilePlistReader(factory) .read(new Local("../profiles/iRODS (iPlant Collaborative).cyberduckprofile")); final Host host = new Host(profile, profile.getDefaultHostname(), new Credentials(System.getProperties().getProperty("irods.key"), System.getProperties().getProperty("irods.secret"))); final IRODSSession session1 = new IRODSSession(host); session1.open(new DisabledHostKeyCallback()); session1.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final IRODSSession session2 = new IRODSSession(host); session2.open(new DisabledHostKeyCallback()); session2.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final Path test1 = new Path(new IRODSHomeFinderService(session1).find(), UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); final Path test2 = new Path(new IRODSHomeFinderService(session2).find(), UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); final byte[] content = RandomUtils.nextBytes(68400); final OutputStream out1 = new IRODSWriteFeature(session1).write(test1, new TransferStatus().append(false).length(content.length), new DisabledConnectionCallback()); final OutputStream out2 = new IRODSWriteFeature(session2).write(test2, new TransferStatus().append(false).length(content.length), new DisabledConnectionCallback()); new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), out2);/*from w w w . jav a 2 s . c o m*/ // Error code received from iRODS:-23000 new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), out1); { final InputStream in1 = session1.getFeature(Read.class).read(test1, new TransferStatus(), new DisabledConnectionCallback()); final byte[] buffer1 = new byte[content.length]; IOUtils.readFully(in1, buffer1); in1.close(); assertArrayEquals(content, buffer1); } { final InputStream in2 = session2.getFeature(Read.class).read(test2, new TransferStatus(), new DisabledConnectionCallback()); final byte[] buffer2 = new byte[content.length]; IOUtils.readFully(in2, buffer2); in2.close(); assertArrayEquals(content, buffer2); } session1.close(); session2.close(); }