Example usage for java.util EnumSet of

List of usage examples for java.util EnumSet of

Introduction

In this page you can find the example usage for java.util EnumSet of.

Prototype

public static <E extends Enum<E>> EnumSet<E> of(E e) 

Source Link

Document

Creates an enum set initially containing the specified element.

Usage

From source file:ch.cyberduck.core.googledrive.DriveWriteFeatureTest.java

@Test
public void testWrite() throws Exception {
    final Path test = new Path(new DriveHomeFinderService(session).find(), UUID.randomUUID().toString(),
            EnumSet.of(Path.Type.file));
    {/* ww  w .j  a v  a  2  s . c om*/
        final TransferStatus status = new TransferStatus();
        status.setMime("x-application/cyberduck");
        final byte[] content = RandomUtils.nextBytes(2048);
        status.setLength(content.length);
        final OutputStream out = new DriveWriteFeature(session).write(test, status,
                new DisabledConnectionCallback());
        assertNotNull(out);
        new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content),
                out);
        out.close();
        test.attributes().setVersionId(
                new DriveFileidProvider(session).getFileid(test, new DisabledListProgressListener()));
        assertTrue(new DefaultFindFeature(session).find(test));
        final PathAttributes attributes = session.list(test.getParent(), new DisabledListProgressListener())
                .get(test).attributes();
        assertEquals(content.length, attributes.getSize());
        final Write.Append append = new DriveWriteFeature(session).append(test, status.getLength(),
                PathCache.empty());
        assertTrue(append.override);
        assertEquals(content.length, append.size, 0L);
        final byte[] buffer = new byte[content.length];
        final InputStream in = new DriveReadFeature(session).read(test, new TransferStatus(),
                new DisabledConnectionCallback());
        IOUtils.readFully(in, buffer);
        in.close();
        assertArrayEquals(content, buffer);
        assertEquals("x-application/cyberduck",
                session.getClient().files().get(test.attributes().getVersionId()).execute().getMimeType());
    }
    {
        final TransferStatus status = new TransferStatus();
        status.setMime("x-application/cyberduck");
        status.setExists(true);
        final byte[] content = RandomUtils.nextBytes(1024);
        status.setLength(content.length);
        final OutputStream out = new DriveWriteFeature(session).write(test, status,
                new DisabledConnectionCallback());
        assertNotNull(out);
        new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content),
                out);
        out.close();
        final PathAttributes attributes = session.list(test.getParent(), new DisabledListProgressListener())
                .get(test).attributes();
        assertEquals(content.length, attributes.getSize());
        assertEquals("x-application/cyberduck",
                session.getClient().files().get(test.attributes().getVersionId()).execute().getMimeType());
    }
    new DriveDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
}

From source file:ch.cyberduck.core.onedrive.OneDriveSearchFeatureTest.java

@Test
@Ignore//from  w  w  w.  j  ava2 s  .co  m
public void testSearch() throws Exception {
    final String name = new AlphanumericRandomStringService().random();
    final Path drive = new OneDriveHomeFinderFeature(session).find();
    final Path directory = new OneDriveDirectoryFeature(session).mkdir(
            new Path(drive, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)),
            null, new TransferStatus());
    final Path file = new OneDriveTouchFeature(session)
            .touch(new Path(directory, name, EnumSet.of(Path.Type.file)), new TransferStatus());
    final OneDriveSearchFeature feature = new OneDriveSearchFeature(session);
    assertTrue(
            feature.search(drive, new SearchFilter(name), new DisabledListProgressListener()).contains(file));
    assertFalse(feature
            .search(drive, new SearchFilter(StringUtils.substring(name, 2)), new DisabledListProgressListener())
            .contains(file));
    assertTrue(feature.search(drive, new SearchFilter(StringUtils.substring(name, 0, name.length() - 2)),
            new DisabledListProgressListener()).contains(file));
    assertTrue(feature.search(directory, new SearchFilter(StringUtils.substring(name, 0, name.length() - 2)),
            new DisabledListProgressListener()).contains(file));
    try {
        assertFalse(feature.search(
                new Path(drive, new AlphanumericRandomStringService().random(),
                        EnumSet.of(Path.Type.directory)),
                new SearchFilter(name), new DisabledListProgressListener()).contains(file));
        fail();
    } catch (NotfoundException e) {
        //
    }
    final Path subdir = new OneDriveDirectoryFeature(session).mkdir(new Path(directory,
            new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), null,
            new TransferStatus());
    assertNull(feature.search(subdir, new SearchFilter(name), new DisabledListProgressListener())
            .find(new SimplePathPredicate(file)));
    final Path filesubdir = new OneDriveTouchFeature(session).touch(
            new Path(subdir, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)),
            new TransferStatus());
    {
        final AttributedList<Path> result = feature.search(directory, new SearchFilter(filesubdir.getName()),
                new DisabledListProgressListener());
        assertNotNull(result.find(new SimplePathPredicate(filesubdir)));
        assertEquals(subdir, result.find(new SimplePathPredicate(filesubdir)).getParent());
    }
    new OneDriveDeleteFeature(session).delete(Arrays.asList(file, filesubdir, subdir),
            new DisabledLoginCallback(), new Delete.DisabledCallback());
}

From source file:com.elemenopy.backupcopy.filesystem.WatcherManager.java

public static void init(BackupConfig config) throws IOException {
    backupConfig = config;/*  w  w  w .jav  a  2 s .  c  om*/

    for (RootFolder rootFolder : config.getRootFolders()) {

        WatchService watcher = fileSystem.newWatchService();

        //start monitoring the source folder
        TaskManager.runTask(new WatcherTask(rootFolder, watcher));

        TaskManager.runTask(() -> {
            //traverse the source folder tree, registering subfolders on the watcher
            final WatcherRegisteringFileVisitor visitor = new WatcherRegisteringFileVisitor(rootFolder,
                    watcher);

            try {
                EnumSet<FileVisitOption> opts = EnumSet.of(FOLLOW_LINKS);
                Files.walkFileTree(fileSystem.getPath(rootFolder.getPath()), opts, Integer.MAX_VALUE, visitor);
            } catch (IOException ex) {
                logger.error("Error while setting up directory watchers", ex);
            }
        });
    }

}

From source file:com.flipkart.zjsonpatch.CompatibilityTest.java

@Test
public void withFlagAddNodeWithMissingValueShouldValidateCorrectly() {
    JsonPatch.validate(addNodeWithMissingValue, EnumSet.of(MISSING_VALUES_AS_NULLS));
}

From source file:ch.cyberduck.cli.DeletePathFinderTest.java

@Test
public void testFindFile() throws Exception {
    final CommandLineParser parser = new PosixParser();
    final CommandLine input = parser.parse(TerminalOptionsBuilder.options(),
            new String[] { "--delete", "rackspace://cdn.cyberduck.ch/remote" });

    assertTrue(new DeletePathFinder()
            .find(input, TerminalAction.delete, new Path("/remote", EnumSet.of(Path.Type.file)))
            .contains(new TransferItem(new Path("/remote", EnumSet.of(Path.Type.file)))));
}

From source file:com.sentinel.config.WebAppInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    LOG.trace("Method: onStartup called.");

    EnumSet<DispatcherType> dispatch = EnumSet.of(DispatcherType.REQUEST);
    super.onStartup(servletContext);
    DelegatingFilterProxy filter = new DelegatingFilterProxy("springSecurityFilterChain");
    filter.setContextAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher");
    servletContext.addFilter("springSecurityFilterChain", filter).addMappingForUrlPatterns(dispatch, false,
            "/*");

    LOG.trace("Method: onStartup finished.");
}

From source file:ch.cyberduck.core.googledrive.DriveReadFeatureTest.java

@Test(expected = NotfoundException.class)
public void testReadNotFound() throws Exception {
    final TransferStatus status = new TransferStatus();
    new DriveReadFeature(session).read(
            new Path(new DriveHomeFinderService(session).find(), "nosuchname", EnumSet.of(Path.Type.file)),
            status, new DisabledConnectionCallback());
}

From source file:com.elemenopy.backupcopy.filesystem.RootFolderSynchronizer.java

public void synchronize() throws IOException {
    Path sourceRoot = fileSystem.getPath(sourceRootFolder.getPath());
    if (!sourceRoot.toFile().isDirectory()) {
        throw new IllegalArgumentException("Source path " + sourceRootFolder.getPath() + " is not a directory");
    }/* www  . j a  va 2  s  . c om*/
    EnumSet<FileVisitOption> opts = EnumSet.of(FOLLOW_LINKS);
    Files.walkFileTree(sourceRoot, opts, Integer.MAX_VALUE, new SyncingFileVisitor(sourceRoot, destination));
}

From source file:ch.cyberduck.core.onedrive.OneDriveReadFeatureTest.java

@Test(expected = NotfoundException.class)
public void testReadNotFound() throws Exception {
    final TransferStatus status = new TransferStatus();
    final Path drive = new OneDriveHomeFinderFeature(session).find();
    new OneDriveReadFeature(session).read(new Path(drive, "nosuchname", EnumSet.of(Path.Type.file)), status,
            new DisabledConnectionCallback());
}

From source file:org.openmrs.web.WebComponentRegistrar.java

@Override
public void setServletContext(ServletContext servletContext) {

    try {/*from   w w  w .  ja  v a 2 s  .  c o m*/
        ServletRegistration openmrsServletReg = servletContext.getServletRegistration("openmrs");
        addMappings(openmrsServletReg, "*.htm", "*.form", "*.list", "*.json", "*.field", "*.portlet", "*.page",
                "*.action");

        addMappings(servletContext.getServletRegistration("jsp"), "*.withjstl");

        ServletRegistration servletReg = servletContext.addServlet("logoutServlet", new LogoutServlet());
        servletReg.addMapping("/logout");

        Dynamic filter = servletContext.addFilter("forcePasswordChangeFilter", new ForcePasswordChangeFilter());
        filter.setInitParameter("changePasswordForm", "/admin/users/changePassword.form");
        filter.setInitParameter("excludeURL", "changePasswordForm,logout,.js,.css,.gif,.jpg,.jpeg,.png");
        filter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");

        filter = servletContext.addFilter("adminPageFilter", new AdminPageFilter());
        filter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/admin");

        servletContext.addListener(new SessionListener());
        /*
         * EfficientShutdownServletContextAttributeListener is used instead of
         * EfficientShutdownServletContextListener since the latter implements ServletContextListener,
         * which is not supported by ServletContext.addListener.
        */
        servletContext.addListener(new EfficientShutdownServletContextAttributeListener());
    } catch (Exception ex) {
        //TODO not yet looked into what caused this to fail.
    }
}