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.manta.AbstractMantaTest.java
protected Path randomFile() { return new Path(testPathPrefix, UUID.randomUUID().toString(), EnumSet.of(Type.file)); }
From source file:ch.cyberduck.core.googledrive.DriveListService.java
@Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { try {//w w w . j a v a2 s . c om final AttributedList<Path> children = new AttributedList<Path>(); String page = null; do { final FileList list = session.getClient().files().list() .setQ(String.format("'%s' in parents", new DriveFileidProvider(session).getFileid(directory))) .setPageToken(page).setFields("nextPageToken, files").setPageSize(pagesize).execute(); for (File f : list.getFiles()) { final PathAttributes attributes = new PathAttributes(); if (null != f.getExplicitlyTrashed()) { if (f.getExplicitlyTrashed()) { log.warn(String.format("Skip file %s", f)); continue; } } if (!DRIVE_FOLDER.equals(f.getMimeType())) { if (StringUtils.startsWith(f.getMimeType(), GOOGLE_APPS_PREFIX)) { log.warn(String.format("Skip file %s", f)); continue; } } if (null != f.getSize()) { attributes.setSize(f.getSize()); } attributes.setVersionId(f.getId()); if (f.getModifiedTime() != null) { attributes.setModificationDate(f.getModifiedTime().getValue()); } if (f.getCreatedTime() != null) { attributes.setCreationDate(f.getCreatedTime().getValue()); } attributes.setChecksum(Checksum.parse(f.getMd5Checksum())); final EnumSet<AbstractPath.Type> type = DRIVE_FOLDER.equals(f.getMimeType()) ? EnumSet.of(Path.Type.directory) : EnumSet.of(Path.Type.file); final Path child = new Path(directory, PathNormalizer.name(f.getName()), type, attributes); children.add(child); } listener.chunk(directory, children); page = list.getNextPageToken(); } while (page != null); return children; } catch (IOException e) { throw new DriveExceptionMappingService().map("Listing directory failed", e, directory); } }
From source file:com.github.aptd.simulation.ui.CHTTPServer.java
/** * ctor/* ww w.j a va 2s .c o m*/ */ private CHTTPServer() { // web context definition final WebAppContext l_webapp = new WebAppContext(); // server process m_server = new Server(new InetSocketAddress( CConfiguration.INSTANCE.<String>getOrDefault("localhost", "httpserver", "host"), CConfiguration.INSTANCE.<Integer>getOrDefault(8000, "httpserver", "port"))); // set server / webapp connection m_server.setHandler(l_webapp); l_webapp.setServer(m_server); l_webapp.setContextPath("/"); l_webapp.setWelcomeFiles(new String[] { "index.html", "index.htm" }); l_webapp.setResourceBase(CHTTPServer.class .getResource(MessageFormat.format("/{0}/html", CCommon.PACKAGEROOT.replace(".", "/"))) .toExternalForm()); l_webapp.addServlet(new ServletHolder(new ServletContainer(m_restagent)), "/rest/*"); l_webapp.addFilter(new FilterHolder(new CrossOriginFilter()), "/rest/*", EnumSet.of(DispatcherType.REQUEST)); }
From source file:ch.cyberduck.core.ftp.FTPListResponseReader.java
@Override public AttributedList<Path> read(final Path directory, final List<String> replies, final ListProgressListener listener) throws IOException, FTPInvalidListException, ConnectionCanceledException { final AttributedList<Path> children = new AttributedList<Path>(); // At least one entry successfully parsed boolean success = false; // Call hook for those implementors which need to perform some action upon the list after it has been created // from the server stream, but before any clients see the list parser.preParse(replies);//from ww w . j a va2 s . c om for (String line : replies) { final FTPFile f = parser.parseFTPEntry(line); if (null == f) { continue; } final String name = f.getName(); if (!success) { if (lenient) { // Workaround for #2410. STAT only returns ls of directory itself // Workaround for #2434. STAT of symbolic link directory only lists the directory itself. if (directory.getName().equals(name)) { log.warn(String.format("Skip %s matching parent directory name", f.getName())); continue; } if (name.contains(String.valueOf(Path.DELIMITER))) { if (!name.startsWith(directory.getAbsolute() + Path.DELIMITER)) { // Workaround for #2434. log.warn(String.format("Skip %s with delimiter in name", name)); continue; } } } } success = true; if (name.equals(".") || name.equals("..")) { if (log.isDebugEnabled()) { log.debug(String.format("Skip %s", f.getName())); } continue; } final Path parsed = new Path(directory, PathNormalizer.name(name), f.getType() == FTPFile.DIRECTORY_TYPE ? EnumSet.of(Path.Type.directory) : EnumSet.of(Path.Type.file)); switch (f.getType()) { case FTPFile.SYMBOLIC_LINK_TYPE: parsed.setType(EnumSet.of(Path.Type.file, Path.Type.symboliclink)); // Symbolic link target may be an absolute or relative path final String target = f.getLink(); if (StringUtils.isBlank(target)) { log.warn(String.format("Missing symbolic link target for %s", parsed)); final EnumSet<AbstractPath.Type> type = parsed.getType(); type.remove(AbstractPath.Type.symboliclink); } else if (StringUtils.startsWith(target, String.valueOf(Path.DELIMITER))) { parsed.setSymlinkTarget(new Path(target, EnumSet.of(Path.Type.file))); } else if (StringUtils.equals("..", target)) { parsed.setSymlinkTarget(directory); } else if (StringUtils.equals(".", target)) { parsed.setSymlinkTarget(parsed); } else { parsed.setSymlinkTarget(new Path(directory, target, EnumSet.of(Path.Type.file))); } break; } if (parsed.isFile()) { parsed.attributes().setSize(f.getSize()); } parsed.attributes().setOwner(f.getUser()); parsed.attributes().setGroup(f.getGroup()); Permission.Action u = Permission.Action.none; if (f.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION)) { u = u.or(Permission.Action.read); } if (f.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION)) { u = u.or(Permission.Action.write); } if (f.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION)) { u = u.or(Permission.Action.execute); } Permission.Action g = Permission.Action.none; if (f.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION)) { g = g.or(Permission.Action.read); } if (f.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION)) { g = g.or(Permission.Action.write); } if (f.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION)) { g = g.or(Permission.Action.execute); } Permission.Action o = Permission.Action.none; if (f.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION)) { o = o.or(Permission.Action.read); } if (f.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION)) { o = o.or(Permission.Action.write); } if (f.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION)) { o = o.or(Permission.Action.execute); } final Permission permission = new Permission(u, g, o); if (f instanceof FTPExtendedFile) { permission.setSetuid(((FTPExtendedFile) f).isSetuid()); permission.setSetgid(((FTPExtendedFile) f).isSetgid()); permission.setSticky(((FTPExtendedFile) f).isSticky()); } parsed.attributes().setPermission(permission); final Calendar timestamp = f.getTimestamp(); if (timestamp != null) { parsed.attributes().setModificationDate(timestamp.getTimeInMillis()); } children.add(parsed); } if (!success) { throw new FTPInvalidListException(children); } return children; }
From source file:org.apache.hadoop.gateway.identityasserter.function.UsernameFunctionProcessorTest.java
public void setUp(String username, Map<String, String> initParams) throws Exception { String descriptorUrl = getTestResource("rewrite.xml").toExternalForm(); Log.setLog(new NoOpLogger()); server = new ServletTester(); server.setContextPath("/"); server.getContext().addEventListener(new UrlRewriteServletContextListener()); server.getContext().setInitParameter(UrlRewriteServletContextListener.DESCRIPTOR_LOCATION_INIT_PARAM_NAME, descriptorUrl);/*from ww w. j av a 2 s. co m*/ FilterHolder setupFilter = server.addFilter(SetupFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)); setupFilter.setFilter(new SetupFilter(username)); FilterHolder rewriteFilter = server.addFilter(UrlRewriteServletFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)); if (initParams != null) { for (Map.Entry<String, String> entry : initParams.entrySet()) { rewriteFilter.setInitParameter(entry.getKey(), entry.getValue()); } } rewriteFilter.setFilter(new UrlRewriteServletFilter()); interactions = new ArrayQueue<MockInteraction>(); ServletHolder servlet = server.addServlet(MockServlet.class, "/"); servlet.setServlet(new MockServlet("mock-servlet", interactions)); server.start(); interaction = new MockInteraction(); request = HttpTester.newRequest(); response = null; }
From source file:ch.cyberduck.core.cryptomator.impl.CryptoVaultTest.java
@Test public void testLoad() throws Exception { final NullSession session = new NullSession(new Host(new TestProtocol())) { @Override//www .j a v a 2 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 Path home = new Path("/", EnumSet.of((Path.Type.directory))); 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"); } }); assertEquals(Vault.State.open, vault.getState()); assertNotSame(home, vault.encrypt(session, home)); assertEquals(vault.encrypt(session, home), vault.encrypt(session, home)); final Path directory = new Path(home, "dir", EnumSet.of(Path.Type.directory)); assertNull(directory.attributes().getVault()); assertEquals(home, vault.encrypt(session, directory).attributes().getVault()); assertEquals(home, directory.attributes().getVault()); assertEquals(vault.encrypt(session, directory), vault.encrypt(session, directory)); assertEquals(new Path(home, directory.getName(), EnumSet.of(Path.Type.directory, Path.Type.decrypted)), vault.decrypt(session, vault.encrypt(session, directory, true))); final Path placeholder = new Path(home, "placeholder", EnumSet.of(Path.Type.directory, Path.Type.placeholder)); assertTrue(vault.encrypt(session, placeholder, true).getType().contains(Path.Type.placeholder)); assertTrue(vault.decrypt(session, vault.encrypt(session, placeholder, true)).getType() .contains(Path.Type.placeholder)); assertEquals( new Path(home, placeholder.getName(), EnumSet.of(Path.Type.directory, Path.Type.placeholder, Path.Type.decrypted)), vault.decrypt(session, vault.encrypt(session, placeholder, true))); assertNotEquals(vault.encrypt(session, directory), vault.encrypt(session, directory, true)); assertEquals(vault.encrypt(session, directory).attributes().getDirectoryId(), vault.encrypt(session, directory).attributes().getDirectoryId()); assertEquals(vault.encrypt(session, vault.encrypt(session, directory)).attributes().getDirectoryId(), vault.encrypt(session, vault.encrypt(session, directory)).attributes().getDirectoryId()); assertNull(vault.encrypt(session, directory, true).attributes().getDirectoryId()); assertNull(vault.encrypt(session, vault.encrypt(session, directory), true).attributes().getDirectoryId()); assertNotEquals(vault.encrypt(session, directory).attributes().getDirectoryId(), vault.encrypt(session, directory, true).attributes().getDirectoryId()); vault.close(); assertEquals(Vault.State.closed, vault.getState()); }
From source file:ch.cyberduck.core.cryptomator.MoveWorkerTest.java
@Test public void testMoveSameFolderCryptomator() 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 source = new Path(vault, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); final Path target = 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 ww . ja v a2 s .c o m*/ new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator)); final byte[] content = RandomUtils.nextBytes(40500); final TransferStatus status = new TransferStatus(); new CryptoBulkFeature<>(session, new DisabledBulkFeature(), new SFTPDeleteFeature(session), cryptomator) .pre(Transfer.Type.upload, Collections.singletonMap(source, status), new DisabledConnectionCallback()); new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), new CryptoWriteFeature<>(session, new SFTPWriteFeature(session), cryptomator).write(source, status.length(content.length), new DisabledConnectionCallback())); assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(source)); final MoveWorker worker = new MoveWorker(Collections.singletonMap(source, target), new DisabledProgressListener(), PathCache.empty(), new DisabledConnectionCallback()); worker.run(session); assertFalse(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(source)); assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(target)); final ByteArrayOutputStream out = new ByteArrayOutputStream(content.length); assertEquals(content.length, IOUtils.copy( new CryptoReadFeature(session, new SFTPReadFeature(session), cryptomator).read(target, new TransferStatus().length(content.length), new DisabledConnectionCallback()), out)); assertArrayEquals(content, out.toByteArray()); new CryptoDeleteFeature(session, new SFTPDeleteFeature(session), cryptomator) .delete(Arrays.asList(target, vault), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
From source file:ch.cyberduck.core.ftp.FTPDefaultListServiceTest.java
@Test public void testListDefaultFlag() 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 list = new FTPDefaultListService(session, new DisabledPasswordStore(), new DisabledLoginCallback(), new CompositeFileEntryParser(Arrays.asList(new UnixFTPEntryParser())), FTPListService.Command.lista); 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()); assertTrue(list.list(directory, new DisabledListProgressListener()).contains(file)); new FTPDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close();/* w w w .j a va 2s .co m*/ }
From source file:com.google.gerrit.server.ReviewerRecommender.java
@Inject ReviewerRecommender(ChangeQueryBuilder changeQueryBuilder, DynamicMap<ReviewerSuggestion> reviewerSuggestionPluginMap, InternalChangeQuery internalChangeQuery, WorkQueue workQueue, Provider<ReviewDb> dbProvider, ApprovalsUtil approvalsUtil, @GerritServerConfig Config config) { Set<FillOptions> fillOptions = EnumSet.of(FillOptions.SECONDARY_EMAILS); fillOptions.addAll(AccountLoader.DETAILED_OPTIONS); this.changeQueryBuilder = changeQueryBuilder; this.config = config; this.internalChangeQuery = internalChangeQuery; this.reviewerSuggestionPluginMap = reviewerSuggestionPluginMap; this.workQueue = workQueue; this.dbProvider = dbProvider; this.approvalsUtil = approvalsUtil; }