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

@SafeVarargs
public static <E extends Enum<E>> EnumSet<E> of(E first, E... rest) 

Source Link

Document

Creates an enum set initially containing the specified elements.

Usage

From source file:net.rgielen.actionframeworks.struts2.ApplicationInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.register(ApplicationConfig.class);
    servletContext.addListener(new ContextLoaderListener(context));

    CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
    characterEncodingFilter.setEncoding("UTF-8");
    characterEncodingFilter.setForceEncoding(true);

    EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD);

    FilterRegistration.Dynamic characterEncoding = servletContext.addFilter("characterEncoding",
            characterEncodingFilter);/*from   ww w  .  j  ava  2s  . c  o m*/
    characterEncoding.addMappingForUrlPatterns(dispatcherTypes, false, "/*");

    final FilterRegistration.Dynamic struts = servletContext.addFilter("struts",
            new StrutsPrepareAndExecuteFilter());
    struts.addMappingForUrlPatterns(dispatcherTypes, false, "/*");
}

From source file:ch.cyberduck.core.sds.SDSSearchFeature.java

@Override
public AttributedList<Path> search(final Path workdir, final Filter<Path> regex,
        final ListProgressListener listener) throws BackgroundException {
    try {//from   w  ww  . ja v  a 2  s.c  o m
        final AttributedList<Path> result = new AttributedList<>();
        final NodeList list = new NodesApi(session.getClient()).searchFsNodes(StringUtils.EMPTY,
                String.format("*%s*", regex.toPattern().pattern()), null, -1,
                Long.valueOf(new SDSNodeIdProvider(session).getFileid(workdir, listener)), null, null, null,
                null);
        final SDSAttributesFinderFeature feature = new SDSAttributesFinderFeature(session);
        for (Node node : list.getItems()) {
            final PathAttributes attributes = feature.toAttributes(node);
            final EnumSet<AbstractPath.Type> type;
            switch (node.getType()) {
            case ROOM:
                type = EnumSet.of(Path.Type.directory, Path.Type.volume);
                break;
            case FOLDER:
                type = EnumSet.of(Path.Type.directory);
                break;
            default:
                type = EnumSet.of(Path.Type.file);
                break;
            }
            result.add(new Path(new Path(node.getParentPath(), EnumSet.of(Path.Type.directory)), node.getName(),
                    type, attributes));
        }
        return result;
    } catch (ApiException e) {
        throw new SDSExceptionMappingService().map("Failure to read attributes of {0}", e, workdir);
    }
}

From source file:org.eel.kitchen.jsonschema.format.FormatAttribute.java

/**
 * Protected constructor/*from   w  ww.  java  2  s  .  c  o m*/
 *
 * <p>Its arguments are the node types recognized by the attribute. Only
 * one attribute recognizes more than one type: {@code utc-millisec} (it
 * can validate both numbers and integers).
 * </p>
 *
 * @param first first type
 * @param other other types, if any
 */
protected FormatAttribute(final NodeType first, final NodeType... other) {
    typeSet = EnumSet.of(first, other);
}

From source file:ch.cyberduck.core.b2.B2LargeUploadWriteFeatureTest.java

@Test
public void testWrite() throws Exception {
    final B2Session session = new B2Session(new Host(new B2Protocol(), new B2Protocol().getDefaultHostname(),
            new Credentials(System.getProperties().getProperty("b2.user"),
                    System.getProperties().getProperty("b2.key"))));
    session.open(new DisabledHostKeyCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final B2LargeUploadWriteFeature feature = new B2LargeUploadWriteFeature(session);
    final Path container = new Path("test-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final TransferStatus status = new TransferStatus();
    status.setLength(-1L);//from w ww  . j a  v  a2  s  .  c o m
    status.setTimestamp(1503654614004L);
    final Path file = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
    final OutputStream out = feature.write(file, status, new DisabledConnectionCallback());
    final byte[] content = new RandomStringGenerator.Builder().build().generate(6 * 1024 * 1024)
            .getBytes("UTF-8");
    final ByteArrayInputStream in = new ByteArrayInputStream(content);
    assertEquals(content.length, IOUtils.copy(in, out));
    in.close();
    out.close();
    assertTrue(new B2FindFeature(session).find(file));
    final byte[] compare = new byte[content.length];
    final InputStream stream = new B2ReadFeature(session).read(file,
            new TransferStatus().length(content.length), new DisabledConnectionCallback());
    IOUtils.readFully(stream, compare);
    stream.close();
    assertArrayEquals(content, compare);
    assertEquals(1503654614004L, new B2AttributesFinderFeature(session).find(file).getModificationDate());
    new B2DeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
    session.close();
}

From source file:ch.cyberduck.core.s3.S3LoggingFeature.java

@Override
public LoggingConfiguration getConfiguration(final Path file) throws BackgroundException {
    final Path bucket = containerService.getContainer(file);
    if (bucket.isRoot()) {
        return LoggingConfiguration.empty();
    }/*from w w w. ja v a 2 s .  c o m*/
    try {
        final StorageBucketLoggingStatus status = session.getClient()
                .getBucketLoggingStatusImpl(bucket.getName());
        final LoggingConfiguration configuration = new LoggingConfiguration(status.isLoggingEnabled(),
                status.getTargetBucketName());
        try {
            configuration.setContainers(new S3BucketListService(session).list(
                    new Path(String.valueOf(Path.DELIMITER), EnumSet.of(Path.Type.volume, Path.Type.directory)),
                    new DisabledListProgressListener()).toList());
        } catch (AccessDeniedException | InteroperabilityException e) {
            log.warn(String.format("Failure listing buckets. %s", e.getMessage()));
        }
        return configuration;
    } catch (ServiceException e) {
        try {
            throw new S3ExceptionMappingService().map("Failure to read attributes of {0}", e, file);
        } catch (AccessDeniedException | InteroperabilityException l) {
            log.warn(String.format("Missing permission to read logging configuration for %s %s",
                    bucket.getName(), e.getMessage()));
            return LoggingConfiguration.empty();
        }
    }
}

From source file:ch.cyberduck.core.b2.B2SearchFeatureTest.java

@Test
public void testSearchInBucket() throws Exception {
    final B2Session session = new B2Session(new Host(new B2Protocol(), new B2Protocol().getDefaultHostname(),
            new Credentials(System.getProperties().getProperty("b2.user"),
                    System.getProperties().getProperty("b2.key"))));
    final LoginConnectionService service = new LoginConnectionService(new DisabledLoginCallback(),
            new DisabledHostKeyCallback(), new DisabledPasswordStore(), new DisabledProgressListener());
    service.connect(session, PathCache.empty(), new DisabledCancelCallback());
    final String name = new AlphanumericRandomStringService().random();
    final Path bucket = new Path("test-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final Path file = new B2TouchFeature(session).touch(new Path(bucket, name, EnumSet.of(Path.Type.file)),
            new TransferStatus());
    final B2SearchFeature feature = new B2SearchFeature(session);
    assertNotNull(feature.search(bucket, new SearchFilter(name), new DisabledListProgressListener())
            .find(new SimplePathPredicate(file)));
    // Supports prefix matching only
    assertNull(feature.search(bucket, new SearchFilter(StringUtils.substring(name, 2)),
            new DisabledListProgressListener()).find(new SimplePathPredicate(file)));
    assertNotNull(feature.search(bucket, new SearchFilter(StringUtils.substring(name, 0, name.length() - 2)),
            new DisabledListProgressListener()).find(new SimplePathPredicate(file)));
    final Path subdir = new Path(bucket, new AlphanumericRandomStringService().random(),
            EnumSet.of(Path.Type.directory));
    assertNull(feature.search(subdir, new SearchFilter(name), new DisabledListProgressListener())
            .find(new SimplePathPredicate(file)));
    new B2DeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
    session.close();/*w w w .  j  a va 2s  . com*/
}

From source file:ch.cyberduck.core.sds.SDSSearchFeatureTest.java

@Test
public void testSearch() throws Exception {
    final Host host = new Host(new SDSProtocol(), "duck.ssp-europe.eu", new Credentials(
            System.getProperties().getProperty("sds.user"), System.getProperties().getProperty("sds.key")));
    final SDSSession session = new SDSSession(host, new DisabledX509TrustManager(),
            new DefaultX509KeyManager());
    session.open(new DisabledHostKeyCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final String name = new AlphanumericRandomStringService().random();
    final Path room = new SDSDirectoryFeature(session)
            .mkdir(new Path(new AlphanumericRandomStringService().random(),
                    EnumSet.of(Path.Type.directory, Path.Type.volume)), null, new TransferStatus());
    final Path directory = new SDSDirectoryFeature(session).mkdir(
            new Path(room, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)),
            null, new TransferStatus());
    final Path file = new SDSTouchFeature(session).touch(new Path(directory, name, EnumSet.of(Path.Type.file)),
            new TransferStatus());
    final SDSSearchFeature feature = new SDSSearchFeature(session);
    assertTrue(feature.search(room, new SearchFilter(name), new DisabledListProgressListener()).contains(file));
    assertTrue(feature/*from   ww  w  . j a  v  a  2  s  . c om*/
            .search(room, new SearchFilter(StringUtils.substring(name, 2)), new DisabledListProgressListener())
            .contains(file));
    assertTrue(feature.search(room, 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(room, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)),
                new SearchFilter(name), new DisabledListProgressListener()).contains(file));
        fail();
    } catch (NotfoundException e) {
        //
    }
    final Path subdir = new SDSDirectoryFeature(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 SDSTouchFeature(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 SDSDeleteFeature(session).delete(Collections.singletonList(room), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
}

From source file:eu.itesla_project.modules.histo.tools.HistoDbPrintForecastDiffTool.java

@Override
public void run(CommandLine line) throws Exception {
    OfflineConfig config = OfflineConfig.load();
    try (HistoDbClient histoDbClient = config.getHistoDbClientFactoryClass().newInstance().create()) {
        Interval interval = Interval.parse(line.getOptionValue("interval"));
        try (Reader reader = new InputStreamReader(histoDbClient.queryCsv(HistoQueryType.forecastDiff,
                EnumSet.allOf(Country.class), EnumSet.of(HistoDbEquip.loads, HistoDbEquip.gen),
                EnumSet.of(HistoDbAttr.P), interval, HistoDbHorizon.DACF, false, false))) {
            CharStreams.copy(reader, System.out);
        }// ww w . jav  a  2 s  .  c  o m
    }
}

From source file:ch.cyberduck.core.s3.S3SearchFeatureTest.java

@Test
public void testSearchInBucket() throws Exception {
    final S3Session session = new S3Session(new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(),
            new Credentials(System.getProperties().getProperty("s3.key"),
                    System.getProperties().getProperty("s3.secret"))));
    final LoginConnectionService service = new LoginConnectionService(new DisabledLoginCallback(),
            new DisabledHostKeyCallback(), new DisabledPasswordStore(), new DisabledProgressListener());
    service.connect(session, PathCache.empty(), new DisabledCancelCallback());
    final String name = new AlphanumericRandomStringService().random();
    final Path bucket = new Path("test-us-east-1-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final Path file = new S3TouchFeature(session).touch(new Path(bucket, name, EnumSet.of(Path.Type.file)),
            new TransferStatus());
    final S3SearchFeature feature = new S3SearchFeature(session);
    assertNotNull(feature.search(bucket, new SearchFilter(name), new DisabledListProgressListener())
            .find(new SimplePathPredicate(file)));
    assertNotNull(feature.search(bucket, new SearchFilter(StringUtils.substring(name, 2)),
            new DisabledListProgressListener()).find(new SimplePathPredicate(file)));
    assertNotNull(feature.search(bucket, new SearchFilter(StringUtils.substring(name, 0, name.length() - 2)),
            new DisabledListProgressListener()).find(new SimplePathPredicate(file)));
    final Path subdir = new Path(bucket, new AlphanumericRandomStringService().random(),
            EnumSet.of(Path.Type.directory));
    assertNull(feature.search(subdir, new SearchFilter(name), new DisabledListProgressListener())
            .find(new SimplePathPredicate(file)));
    new S3DefaultDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
    session.close();//  www.j a  v a  2 s .c  o  m
}

From source file:ch.cyberduck.core.sds.SDSWriteFeatureTest.java

@Test
public void testReadWrite() throws Exception {
    final Host host = new Host(new SDSProtocol(), "duck.ssp-europe.eu", new Credentials(
            System.getProperties().getProperty("sds.user"), System.getProperties().getProperty("sds.key")));
    final SDSSession session = new SDSSession(host, new DisabledX509TrustManager(),
            new DefaultX509KeyManager());
    session.open(new DisabledHostKeyCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final Path room = new SDSDirectoryFeature(session)
            .mkdir(new Path(new AlphanumericRandomStringService().random(),
                    EnumSet.of(Path.Type.directory, Path.Type.volume)), null, new TransferStatus());
    final byte[] content = RandomUtils.nextBytes(32769);
    final TransferStatus status = new TransferStatus();
    status.setLength(content.length);/*from   w w w .  j av a  2s.c  o m*/
    final Path test = new Path(room, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
    final SDSWriteFeature writer = new SDSWriteFeature(session);
    final HttpResponseOutputStream<VersionId> out = writer.write(test, status,
            new DisabledConnectionCallback());
    assertNotNull(out);
    new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out);
    final VersionId version = out.getStatus();
    assertNotNull(version);
    assertTrue(new DefaultFindFeature(session).find(test));
    final byte[] compare = new byte[content.length];
    final InputStream stream = new SDSReadFeature(session).read(test,
            new TransferStatus().length(content.length), new DisabledConnectionCallback());
    IOUtils.readFully(stream, compare);
    stream.close();
    assertArrayEquals(content, compare);
    new SDSDeleteFeature(session).delete(Collections.singletonList(room), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
    session.close();
}