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.impl.CryptoDirectoryProviderTest.java
@Test public void testToEncryptedDirectory() throws Exception { final Path home = new Path("/vault", EnumSet.of(Path.Type.directory)); final NullSession session = new NullSession(new Host(new TestProtocol())) { @Override// w w w . j a v a2 s. c o m @SuppressWarnings("unchecked") public <T> T _getFeature(final Class<T> type) { if (type == Read.class) { return (T) new Read() { @Override public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { final String masterKey = "{\n" + " \"scryptSalt\": \"NrC7QGG/ouc=\",\n" + " \"scryptCostParam\": 16384,\n" + " \"scryptBlockSize\": 8,\n" + " \"primaryMasterKey\": \"Q7pGo1l0jmZssoQh9rXFPKJE9NIXvPbL+HcnVSR9CHdkeR8AwgFtcw==\",\n" + " \"hmacMasterKey\": \"xzBqT4/7uEcQbhHFLC0YmMy4ykVKbuvJEA46p1Xm25mJNuTc20nCbw==\",\n" + " \"versionMac\": \"hlNr3dz/CmuVajhaiGyCem9lcVIUjDfSMLhjppcXOrM=\",\n" + " \"version\": 5\n" + "}"; return IOUtils.toInputStream(masterKey, Charset.defaultCharset()); } @Override public boolean offset(final Path file) throws BackgroundException { return false; } }; } return super._getFeature(type); } }; final CryptoVault vault = new CryptoVault(home, new DisabledPasswordStore()); vault.load(session, new DisabledPasswordCallback() { @Override public Credentials prompt(final Host bookmark, final String title, final String reason, final LoginOptions options) throws LoginCanceledException { return new VaultCredentials("vault"); } }); final CryptoDirectoryProvider provider = new CryptoDirectoryProvider(home, vault); assertNotNull(provider.toEncrypted(session, null, home)); final Path f = new Path("/vault/f", EnumSet.of(Path.Type.directory)); assertNotNull(provider.toEncrypted(session, null, f)); assertEquals(provider.toEncrypted(session, null, f), provider.toEncrypted(session, null, f)); }
From source file:ch.cyberduck.core.cryptomator.SFTPFindFeatureTest.java
@Test public void testFindCryptomator() 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 Path home = new SFTPHomeDirectoryService(session).find(); final Path vault = new Path(home, UUID.randomUUID().toString(), EnumSet.of(Path.Type.directory)); final Path test = new Path(vault, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); final CryptoVault cryptomator = new CryptoVault(vault, new DisabledPasswordStore()); cryptomator.create(session, null, new VaultCredentials("test")); session.withRegistry(//from w w w. java 2s . co m new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator)); assertFalse(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator) .find(new Path(vault, "a", EnumSet.of(Path.Type.directory)))); new CryptoTouchFeature<Void>(session, new DefaultTouchFeature<Void>(new DefaultUploadFeature<Void>(new SFTPWriteFeature(session))), new SFTPWriteFeature(session), cryptomator).touch(test, new TransferStatus()); assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(test)); 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.dropbox.DropboxSearchFeature.java
@Override public AttributedList<Path> search(final Path workdir, final Filter<Path> regex, final ListProgressListener listener) throws BackgroundException { try {/*from ww w . j a v a2 s. c om*/ final AttributedList<Path> list = new AttributedList<>(); long start = 0; SearchResult result; do { result = new DbxUserFilesRequests(session.getClient()) .searchBuilder(workdir.isRoot() ? StringUtils.EMPTY : workdir.getAbsolute(), regex.toPattern().pattern()) .withMode(SearchMode.FILENAME).withStart(start).start(); final List<SearchMatch> matches = result.getMatches(); for (SearchMatch match : matches) { final Metadata metadata = match.getMetadata(); final EnumSet<AbstractPath.Type> type; if (metadata instanceof FileMetadata) { type = EnumSet.of(Path.Type.file); } else if (metadata instanceof FolderMetadata) { type = EnumSet.of(Path.Type.directory); } else { log.warn(String.format("Skip file %s", metadata)); return null; } list.add(new Path(metadata.getPathDisplay(), type, attributes.convert(metadata))); listener.chunk(workdir, list); } start = result.getStart(); } while (result.getMore()); return list; } catch (DbxException e) { throw new DropboxExceptionMappingService().map("Failure to read attributes of {0}", e, workdir); } }
From source file:ch.cyberduck.core.cryptomator.DAVDirectoryFeatureTest.java
@Test public void testMakeDirectoryEncrypted() throws Exception { final Host host = new Host(new DAVProtocol(), "test.cyberduck.ch", new Credentials(System.getProperties().getProperty("webdav.user"), System.getProperties().getProperty("webdav.password"))); host.setDefaultPath("/dav/basic"); final DAVSession session = new DAVSession(host); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); 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.directory)); final CryptoVault cryptomator = new CryptoVault(vault, new DisabledPasswordStore()); cryptomator.create(session, null, new VaultCredentials("test")); session.withRegistry(/*w w w . j av a 2 s . co m*/ new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator)); new CryptoDirectoryFeature<String>(session, new DAVDirectoryFeature(session), new DAVWriteFeature(session), cryptomator).mkdir(test, null, new TransferStatus()); assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(test)); new CryptoDeleteFeature(session, new DAVDeleteFeature(session), cryptomator) .delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
From source file:ch.cyberduck.core.cryptomator.FTPTouchFeatureTest.java
@Test public void testTouchLongFilenameEncrypted() 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 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(/*from w w w . jav a2 s .c o m*/ new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator)); new CryptoTouchFeature<Integer>(session, new DefaultTouchFeature<Integer>(new DefaultUploadFeature<Integer>(new FTPWriteFeature(session))), new FTPWriteFeature(session), cryptomator).touch(test, new TransferStatus()); assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(test)); 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.SFTPDirectoryFeatureTest.java
@Test public void testMakeDirectoryEncrypted() 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 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.directory)); final CryptoVault cryptomator = new CryptoVault(vault, new DisabledPasswordStore()); cryptomator.create(session, null, new VaultCredentials("test")); session.withRegistry(/* w w w .java 2 s . co m*/ new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator)); new CryptoDirectoryFeature<Void>(session, new SFTPDirectoryFeature(session), new SFTPWriteFeature(session), cryptomator).mkdir(test, null, new TransferStatus()); assertTrue(new CryptoFindFeature(session, new SFTPFindFeature(session), cryptomator).find(test)); assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(test)); 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.shared.DefaultDownloadFeatureTest.java
@Test public void testTransferAppend() 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 Path test = new Path(new SFTPHomeDirectoryService(session).find(), UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); session.getFeature(Touch.class).touch(test, new TransferStatus()); final byte[] content = new byte[39864]; new Random().nextBytes(content); {// w ww. ja va 2 s . c o m final TransferStatus status = new TransferStatus().length(content.length); final OutputStream out = new SFTPWriteFeature(session).write(test, status, new DisabledConnectionCallback()); assertNotNull(out); new StreamCopier(status, status).withLimit(new Long(content.length)) .transfer(new ByteArrayInputStream(content), out); out.close(); } final Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString()); { final TransferStatus status = new TransferStatus().length(content.length / 2); new DefaultDownloadFeature(new SFTPReadFeature(session)).download(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), status, new DisabledConnectionCallback(), new DisabledPasswordCallback()); } { final TransferStatus status = new TransferStatus().length(content.length / 2).skip(content.length / 2) .append(true); new DefaultDownloadFeature(new SFTPReadFeature(session)).download(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), status, new DisabledConnectionCallback(), new DisabledPasswordCallback()); } final byte[] buffer = new byte[content.length]; final InputStream in = local.getInputStream(); IOUtils.readFully(in, buffer); in.close(); assertArrayEquals(content, buffer); final Delete delete = session.getFeature(Delete.class); delete.delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
From source file:com.mnt.base.console.JettyController.java
protected void init() { log.info("Prepare to startup the Jetty Web Server..."); super.init(); final ServletContextHandler context = new ServletContextHandler( BaseConfiguration.isSessionEnabled() ? ServletContextHandler.SESSIONS : ServletContextHandler.NO_SESSIONS); context.setContextPath("/"); jettyServer.setHandler(context);/*from w ww . j a v a 2 s .co m*/ context.addServlet(new ServletHolder(new AccessRouterServlet()), "/*"); super.setupExternalConf(new ExternalConfSetter() { @Override public void addServlet(Class<HttpServlet> servletClass, String pathSpec) throws Exception { HttpServlet servlet = (HttpServlet) (servletClass.newInstance()); context.addServlet(new ServletHolder(servlet), pathSpec); } @Override public void addFilter(Class<Filter> filterClass, String pathSpec) { context.addFilter(filterClass, pathSpec, EnumSet.of(DispatcherType.REQUEST)); } }); }
From source file:ch.cyberduck.core.ftp.FTPStatListServiceTest.java
@Test public void testList() 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 ListService service = new FTPStatListService(session, new CompositeFileEntryParser(Collections.singletonList(new UnixFTPEntryParser()))); final Path directory = new FTPWorkdirService(session).find(); final Path file = new Path(directory, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)); new DefaultTouchFeature<Integer>(new DefaultUploadFeature<Integer>(new FTPWriteFeature(session))) .touch(file, new TransferStatus()); final Permission permission = new Permission(Permission.Action.read_write, Permission.Action.read_write, Permission.Action.read_write); new FTPUnixPermissionFeature(session).setUnixPermission(file, permission); final AttributedList<Path> list = service.list(directory, new DisabledListProgressListener()); assertTrue(list.contains(file));/* ww w . j a v a 2 s. c o m*/ assertEquals(permission, list.get(file).attributes().getPermission()); session.close(); }
From source file:com.github.fge.jsonschema.core.keyword.syntax.checkers.draftv4.RequiredSyntaxChecker.java
@Override protected void checkValue(final Collection<JsonPointer> pointers, final MessageBundle bundle, final ProcessingReport report, final SchemaTree tree) throws ProcessingException { final JsonNode node = getNode(tree); final int size = node.size(); if (size == 0) { report.error(newMsg(tree, bundle, "common.array.empty")); return;/* w w w . j a v a 2 s.c o m*/ } final Set<Equivalence.Wrapper<JsonNode>> set = Sets.newHashSet(); boolean uniqueElements = true; JsonNode element; NodeType type; for (int index = 0; index < size; index++) { element = node.get(index); uniqueElements = set.add(EQUIVALENCE.wrap(element)); type = NodeType.getNodeType(element); if (type != NodeType.STRING) report.error(newMsg(tree, bundle, "common.array.element.incorrectType").putArgument("index", index) .putArgument("expected", EnumSet.of(NodeType.STRING)).putArgument("found", type)); } if (!uniqueElements) report.error(newMsg(tree, bundle, "common.array.duplicateElements")); }