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.editor.AbstractEditorTest.java
@Test public void testOpen() throws Exception { final AtomicBoolean t = new AtomicBoolean(); final NullSession session = new NullSession(new Host(new TestProtocol())) { @Override// w w w . ja va2 s. c o m @SuppressWarnings("unchecked") public <T> T _getFeature(final Class<T> type) { if (type.equals(Read.class)) { return (T) new Read() { @Override public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { t.set(true); return IOUtils.toInputStream("content", Charset.defaultCharset()); } @Override public boolean offset(final Path file) { assertEquals(new Path("/f", EnumSet.of(Path.Type.file)), file); return false; } }; } return super._getFeature(type); } }; final AtomicBoolean e = new AtomicBoolean(); final Path file = new Path("/f", EnumSet.of(Path.Type.file)); file.attributes().setSize("content".getBytes().length); final AbstractEditor editor = new AbstractEditor(new Application("com.editor"), new StatelessSessionPool(new TestLoginConnectionService(), session, PathCache.empty(), new DisabledTranscriptListener(), new DefaultVaultRegistry(new DisabledPasswordCallback())), file, new DisabledProgressListener()) { @Override protected void edit(final ApplicationQuitCallback quit, final FileWatcherListener listener) throws IOException { e.set(true); } @Override protected void watch(final Local local, final FileWatcherListener listener) throws IOException { // } }; editor.open(new DisabledApplicationQuitCallback(), new DisabledTransferErrorCallback(), new DisabledFileWatcherListener()).run(session); assertTrue(t.get()); assertNotNull(editor.getLocal()); assertTrue(e.get()); assertTrue(editor.getLocal().exists()); }
From source file:ch.cyberduck.core.nio.LocalWriteFeatureTest.java
@Test(expected = NotfoundException.class) public void testWriteNotFound() throws Exception { final LocalSession session = new LocalSession( new Host(new LocalProtocol(), new LocalProtocol().getDefaultHostname())); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final Path workdir = new LocalHomeFinderFeature(session).find(); final Path test = new Path(workdir.getAbsolute() + "/nosuchdirectory/" + UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); new LocalWriteFeature(session).write(test, new TransferStatus(), new DisabledConnectionCallback()); }
From source file:ch.cyberduck.core.ftp.FTPReadFeatureTest.java
@Test public void testReadRange() 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 test = new Path(new FTPWorkdirService(session).find(), UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); session.getFeature(Touch.class).touch(test, new TransferStatus()); final byte[] content = RandomUtils.nextBytes(2048); final OutputStream out = new FTPWriteFeature(session).write(test, new TransferStatus().length(content.length), new DisabledConnectionCallback()); assertNotNull(out);/*from w w w . ja v a2 s. c o m*/ new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), out); out.close(); final TransferStatus status = new TransferStatus(); // Partial read with offset and not full content length final long limit = content.length - 100; status.setLength(limit); status.setAppend(true); final long offset = 2L; status.setOffset(offset); final InputStream in = new FTPReadFeature(session).read(test, status, new DisabledConnectionCallback()); assertNotNull(in); final ByteArrayOutputStream download = new ByteArrayOutputStream(); new StreamCopier(status, status).withLimit(limit).transfer(in, download); final byte[] reference = new byte[(int) limit]; System.arraycopy(content, (int) offset, reference, 0, (int) limit); assertArrayEquals(reference, download.toByteArray()); new FTPDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
From source file:ch.cyberduck.core.shared.DefaultDownloadFeatureTest.java
@Test public void testTransferUnknownSize() 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[1]; new Random().nextBytes(content); {//w w w. ja v a2s . 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(-1L); 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.jivesoftware.os.server.http.jetty.jersey.server.JerseyEndpoints.java
@Override public Handler getHandler(final Server server, String context, String applicationName) { ResourceConfig rc = new ResourceConfig().registerClasses(allClasses) .register(HttpMethodOverrideFilter.class).register(new JacksonFeature().withMapper(mapper)) .register(MultiPartFeature.class) // adds support for multi-part API requests .registerInstances(allBinders) .registerInstances(new InjectableBinder(allInjectables), new AbstractBinder() { @Override/*from w ww .jav a 2 s. c o m*/ protected void configure() { bind(server).to(Server.class); } }); if (supportCORS) { rc.register(CorsContainerResponseFilter.class); } ServletHolder servletHolder = new ServletHolder(new ServletContainer(rc)); ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS); servletContextHandler.setContextPath(context); if (!applicationName.isEmpty()) { servletContextHandler.setDisplayName(applicationName); } servletContextHandler.addServlet(servletHolder, "/"); servletContextHandler.addFilter(NewRelicRequestFilter.class, "/", EnumSet.of(DispatcherType.REQUEST)); return servletContextHandler; }
From source file:ch.cyberduck.core.cryptomator.FTPDirectoryFeatureTest.java
@Test public void testMakeDirectoryLongFilenameEncrypted() 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.directory)); final CryptoVault cryptomator = new CryptoVault(vault, new DisabledPasswordStore()); cryptomator.create(session, null, new VaultCredentials("test")); session.withRegistry(//w ww .j ava 2 s. c o m new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator)); new CryptoDirectoryFeature<Integer>(session, new FTPDirectoryFeature(session), new FTPWriteFeature(session), cryptomator).mkdir(test, null, 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:com.spotify.apollo.elide.ElideResourceTest.java
@Test public void shouldHaveNoRouteForDisabledMethod() throws Exception { EnumSet<Method> allButGet = EnumSet.complementOf(EnumSet.of(Method.GET)); resource = ElideResource.builder(PREFIX, elide).enabledMethods(allButGet).build(); assertThat(resource.routes().filter(r -> r.method().equals("GET")).findAny(), is(empty())); }
From source file:io.realm.processor.RealmProxyMediatorGenerator.java
private void emitValidateTableMethod(JavaWriter writer) throws IOException { writer.emitAnnotation("Override"); writer.beginMethod("void", "validateTable", EnumSet.of(Modifier.PUBLIC), "Class<? extends RealmObject>", "clazz", "ImplicitTransaction", "transaction"); emitMediatorSwitch(new ProxySwitchStatement() { @Override/*from w ww.jav a 2 s.c o m*/ public void emitStatement(int i, JavaWriter writer) throws IOException { writer.emitStatement("%s.validateTable(transaction)", proxyClasses.get(i)); } }, writer); writer.endMethod(); writer.emitEmptyLine(); }
From source file:de.appsolve.padelcampus.controller.pro.ProOperatorsController.java
@RequestMapping(method = POST, value = "newaccount") public ModelAndView postNewAccount(HttpServletRequest request, @ModelAttribute("Model") CustomerRegistrationModel customerAccount, BindingResult bindingResult) { if (bindingResult.hasErrors()) { return new ModelAndView("pro/newaccount", "Model", customerAccount); }/*from ww w .j a v a2 s.c om*/ try { if (StringUtils.isEmpty(customerAccount.getCustomer().getName())) { throw new Exception(msg.get("ProjectNameFormatRequirements")); } String projectName = customerAccount.getCustomer().getName().toLowerCase(Constants.DEFAULT_LOCALE) .replace(" ", "-"); //verify dns name requirements if (!DNS_SUBDOMAIN_PATTERN.matcher(projectName).matches()) { throw new Exception(msg.get("ProjectNameFormatRequirements")); } //make sure customer does not exist yet Customer customer = customerDAO.findByName(projectName); if (customer != null) { throw new Exception(msg.get("ProjectAlreadyExists")); } String dnsHostname = environment.getProperty("DNS_HOSTNAME"); String cloudflareUrl = environment.getProperty("CLOUDFLARE_URL"); //create DNS subdomain in cloudflare String domainName = cloudFlareApiClient.addCnameRecord(projectName, cloudflareUrl, dnsHostname); //save customer to DB HashSet<String> domainNames = new HashSet<>(); domainNames.add(domainName); customerAccount.getCustomer().setDomainNames(domainNames); customer = customerDAO.saveOrUpdate(customerAccount.getCustomer()); //create admin account in DB Player adminPlayer = playerDAO.findByEmail(customerAccount.getPlayer().getEmail()); if (adminPlayer == null) { customerAccount.getPlayer().setCustomer(customer); adminPlayer = playerDAO.saveOrUpdate(customerAccount.getPlayer()); } //create admin group in DB AdminGroup adminGroup = adminGroupDAO.findByAttribute("customer", customer); if (adminGroup == null) { adminGroup = new AdminGroup(); adminGroup.setName(domainName + " Admins"); EnumSet<Privilege> privileges = EnumSet.complementOf(EnumSet.of(Privilege.ManageCustomers)); adminGroup.setPrivileges(privileges); adminGroup.setPlayers(new HashSet<>(Arrays.asList(new Player[] { adminPlayer }))); adminGroup.setCustomer(customer); adminGroupDAO.saveOrUpdate(adminGroup); } //create all.min.css.stylesheet for new customer htmlResourceUtil.updateCss(servletContext, customer); Mail mail = new Mail(); mail.addRecipient(getDefaultContact()); mail.setSubject("New Customer Registration"); mail.setBody(customer.toString()); mailUtils.send(mail, request); return new ModelAndView("redirect:/pro/operators/newaccount/" + customer.getId()); } catch (Exception e) { LOG.error(e.getMessage(), e); errorReporter.notify(e); bindingResult.addError(new ObjectError("id", e.getMessage())); return new ModelAndView("pro/newaccount", "Model", customerAccount); } }
From source file:io.paradoxical.cassieq.ServiceConfigurator.java
private void enableCors(ServiceConfiguration config, Environment environment) { FilterRegistration.Dynamic filter = environment.servlets().addFilter("CORS", CrossOriginFilter.class); filter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, environment.getApplicationContext().getContextPath() + "*"); filter.setInitParameter("allowedOrigins", String.join(",", config.getWeb().getAllowedOrigins())); // allowed origins comma separated filter.setInitParameter("allowedHeaders", "Content-Type,Authorization,X-Requested-With,Content-Length,Accept,Origin"); filter.setInitParameter("allowedMethods", "GET,PUT,POST,DELETE,OPTIONS"); }