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:io.gumga.security.WebConfigForTest.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();

    servletContext.setInitParameter("javax.servlet.jsp.jstl.fmt.localizationContext", "messages");
    EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD);
    CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
    characterEncodingFilter.setEncoding("UTF-8");
    characterEncodingFilter.setForceEncoding(true);
    FilterRegistration.Dynamic characterEncoding = servletContext.addFilter("characterEncoding",
            characterEncodingFilter);/*from   w  w w .  j av a  2s  .co m*/
    characterEncoding.addMappingForUrlPatterns(dispatcherTypes, true, "/*");

    rootContext.setServletContext(servletContext);
    rootContext.register(WebConfigForTest.class);
    rootContext.refresh();

}

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

@Test
public void testMove() 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(),
            PathCache.empty());//from w w  w . j av  a2s  .co  m
    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 test = new Path(room, new AlphanumericRandomStringService().random(),
            EnumSet.of(Path.Type.file));
    new SDSTouchFeature(session).touch(test, new TransferStatus());
    final Path target = new Path(room, new AlphanumericRandomStringService().random(),
            EnumSet.of(Path.Type.file));
    new SDSMoveFeature(session).move(test, target, new TransferStatus(), new Delete.DisabledCallback(),
            new DisabledConnectionCallback());
    assertFalse(new SDSFindFeature(session).find(test));
    assertTrue(new SDSFindFeature(session).find(target));
    new SDSDeleteFeature(session).delete(Collections.singletonList(room), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
    session.close();
}

From source file:ch.cyberduck.core.shared.DefaultFindFeatureTest.java

@Test
public void testFindLargeUpload() 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 Path bucket = new Path("test-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    session.open(new DisabledHostKeyCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final Path file = new Path(bucket, new AlphanumericRandomStringService().random(),
            EnumSet.of(Path.Type.file));
    final StatusOutputStream<VersionId> out = new B2LargeUploadWriteFeature(session).write(file,
            new TransferStatus(), new DisabledConnectionCallback());
    IOUtils.copyLarge(new ByteArrayInputStream(RandomUtils.nextBytes(100)), out);
    out.close();// www. j  av a  2  s  .co  m
    assertTrue(new DefaultFindFeature(session).find(file));
    session.close();
}

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

@Test(expected = NotfoundException.class)
public void testReadNotFound() 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 TransferStatus status = new TransferStatus();
    final Path room = new SDSDirectoryFeature(session)
            .mkdir(new Path(new AlphanumericRandomStringService().random(),
                    EnumSet.of(Path.Type.directory, Path.Type.volume)), null, new TransferStatus());
    try {/*from  w w  w .  ja  v a2s  .c o  m*/
        new SDSReadFeature(session).read(new Path(room, "nosuchname", EnumSet.of(Path.Type.file)), status,
                new DisabledConnectionCallback());
    } finally {
        new SDSDeleteFeature(session).delete(Collections.singletonList(room), new DisabledLoginCallback(),
                new Delete.DisabledCallback());
        session.close();
    }
}

From source file:ch.cyberduck.core.cryptomator.SwiftLargeUploadWriteFeatureTest.java

@Test
public void testWrite() throws Exception {
    final Host host = new Host(new SwiftProtocol(), "identity.api.rackspacecloud.com",
            new Credentials(System.getProperties().getProperty("rackspace.key"),
                    System.getProperties().getProperty("rackspace.secret")));
    final SwiftSession session = new SwiftSession(host);
    session.open(new DisabledHostKeyCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final Path home = new Path("test.cyberduck.ch", EnumSet.of(Path.Type.volume, Path.Type.directory));
    home.attributes().setRegion("DFW");
    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.file));
    final CryptoVault cryptomator = new CryptoVault(vault, new DisabledPasswordStore());
    cryptomator.create(session, null, new VaultCredentials("test"));
    session.withRegistry(//from ww w  .j  a  v a2  s . c o m
            new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
    final SwiftRegionService regionService = new SwiftRegionService(session);
    final CryptoWriteFeature feature = new CryptoWriteFeature<List<StorageObject>>(session,
            new SwiftLargeUploadWriteFeature(session, regionService,
                    new SwiftSegmentService(session, ".segments-test/")),
            cryptomator);
    final TransferStatus writeStatus = new TransferStatus();
    final Cryptor cryptor = cryptomator.getCryptor();
    final FileHeader header = cryptor.fileHeaderCryptor().create();
    writeStatus.setHeader(cryptor.fileHeaderCryptor().encryptHeader(header));
    writeStatus.setNonces(new RandomNonceGenerator());
    writeStatus.setLength(-1L);
    final OutputStream out = feature.write(test, writeStatus, new DisabledConnectionCallback());
    final byte[] content = RandomUtils.nextBytes(6 * 1024 * 1024);
    final ByteArrayInputStream in = new ByteArrayInputStream(content);
    final TransferStatus progress = new TransferStatus();
    new StreamCopier(new TransferStatus(), progress).transfer(in, out);
    assertEquals(content.length, progress.getOffset());
    assertTrue(new CryptoFindFeature(session, new SwiftFindFeature(session), cryptomator).find(test));
    final byte[] compare = new byte[content.length];
    final InputStream stream = new CryptoReadFeature(session, new SwiftReadFeature(session, regionService),
            cryptomator).read(test, new TransferStatus().length(content.length),
                    new DisabledConnectionCallback());
    IOUtils.readFully(stream, compare);
    stream.close();
    assertArrayEquals(content, compare);
    new CryptoDeleteFeature(session, new SwiftDeleteFeature(session), cryptomator)
            .delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
    session.close();
}

From source file:ch.cyberduck.core.spectra.SpectraWriteFeatureTest.java

@Test
public void testWriteOverwrite() throws Exception {
    final Host host = new Host(new SpectraProtocol() {
        @Override//from w  w w  .  java 2s  .  co  m
        public Scheme getScheme() {
            return Scheme.http;
        }
    }, System.getProperties().getProperty("spectra.hostname"),
            Integer.valueOf(System.getProperties().getProperty("spectra.port")),
            new Credentials(System.getProperties().getProperty("spectra.user"),
                    System.getProperties().getProperty("spectra.key")));
    final SpectraSession session = new SpectraSession(host, new DisabledX509TrustManager(),
            new DefaultX509KeyManager());
    session.open(new DisabledHostKeyCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final Path container = new Path("cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final Path test = new Path(container, new AlphanumericRandomStringService().random(),
            EnumSet.of(Path.Type.file));
    final byte[] content = RandomUtils.nextBytes(1000);
    final TransferStatus status = new TransferStatus().length(content.length);
    status.setChecksum(new CRC32ChecksumCompute().compute(new ByteArrayInputStream(content), status));
    // Allocate
    final SpectraBulkService bulk = new SpectraBulkService(session);
    bulk.pre(Transfer.Type.upload, Collections.singletonMap(test, status), new DisabledConnectionCallback());
    {
        final OutputStream out = new SpectraWriteFeature(session).write(test, status,
                new DisabledConnectionCallback());
        assertNotNull(out);
        new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content),
                out);
        out.close();
    }
    assertEquals(content.length, new S3AttributesFinderFeature(session).find(test).getSize());
    // Overwrite
    bulk.pre(Transfer.Type.upload, Collections.singletonMap(test, status.exists(true)),
            new DisabledConnectionCallback());
    {
        final OutputStream out = new SpectraWriteFeature(session).write(test, status.exists(true),
                new DisabledConnectionCallback());
        new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content),
                out);
        out.close();
    }
    assertEquals(content.length, new S3AttributesFinderFeature(session).find(test).getSize());
    new SpectraDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
    session.close();
}

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

@Test
public void getFileIdFile() 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());
    final LoginConnectionService service = new LoginConnectionService(new DisabledLoginCallback(),
            new DisabledHostKeyCallback(), new DisabledPasswordStore(), new DisabledProgressListener());
    service.connect(session, PathCache.empty(), new DisabledCancelCallback());
    final Path bucket = new SDSDirectoryFeature(session)
            .mkdir(new Path(new AlphanumericRandomStringService().random(),
                    EnumSet.of(Path.Type.directory, Path.Type.volume)), null, new TransferStatus());
    final String name = new AlphanumericRandomStringService().random();
    final Path file = new SDSTouchFeature(session).touch(new Path(bucket, name, EnumSet.of(Path.Type.file)),
            new TransferStatus());
    assertNotNull(new SDSNodeIdProvider(session).getFileid(file, new DisabledListProgressListener()));
    try {//  w ww . j a  v a  2  s  .  c  om
        assertNull(new SDSNodeIdProvider(session).getFileid(
                new Path(bucket, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)),
                new DisabledListProgressListener()));
        fail();
    } catch (NotfoundException e) {
        // Expected
    }
    try {
        assertNull(new SDSNodeIdProvider(session).getFileid(
                new Path(bucket, name, EnumSet.of(Path.Type.directory)), new DisabledListProgressListener()));
        fail();
    } catch (NotfoundException e) {
        // Expected
    }
    new SDSDeleteFeature(session).delete(Arrays.asList(file, bucket), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
    session.close();
}

From source file:ch.cyberduck.core.openstack.SwiftContainerListService.java

@Override
public AttributedList<Path> list(final Path directory, final ListProgressListener listener)
        throws BackgroundException {
    if (log.isDebugEnabled()) {
        log.debug(String.format("List containers for %s", session));
    }/*from   w  w w .  j  a v a 2s.  c  o  m*/
    try {
        final AttributedList<Path> containers = new AttributedList<Path>();
        final int limit = preferences.getInteger("openstack.list.container.limit");
        final Client client = session.getClient();
        for (final Region region : client.getRegions()) {
            if (this.region.getIdentifier() != null) {
                if (!StringUtils.equals(region.getRegionId(), this.region.getIdentifier())) {
                    log.warn(String.format("Skip region %s", region));
                    continue;
                }
            }
            // List all containers
            List<Container> chunk;
            String marker = null;
            do {
                chunk = client.listContainers(region, limit, marker);
                for (final Container f : chunk) {
                    final PathAttributes attributes = new PathAttributes();
                    attributes.setRegion(f.getRegion().getRegionId());
                    containers.add(new Path(String.format("/%s", f.getName()),
                            EnumSet.of(Path.Type.volume, Path.Type.directory), attributes));
                    marker = f.getName();
                }
                listener.chunk(directory, containers);
            } while (!chunk.isEmpty());
        }
        return containers;
    } catch (GenericException e) {
        throw new SwiftExceptionMappingService().map("Listing directory {0} failed", e, directory);
    } catch (IOException e) {
        throw new DefaultIOExceptionMappingService().map(e);
    }
}

From source file:ch.cyberduck.core.cryptomator.B2WriteFeatureTest.java

@Test
public void testWrite() throws Exception {
    final Host host = new Host(new B2Protocol(), new B2Protocol().getDefaultHostname(), new Credentials(
            System.getProperties().getProperty("b2.user"), System.getProperties().getProperty("b2.key")));
    final B2Session session = new B2Session(host);
    session.open(new DisabledHostKeyCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final TransferStatus status = new TransferStatus();
    final int length = 1048576;
    final byte[] content = RandomUtils.nextBytes(length);
    status.setLength(content.length);/*from   w w  w  . j a  v  a 2 s  .  c  o m*/
    final Path home = new Path("/test-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final CryptoVault cryptomator = new CryptoVault(
            new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)),
            new DisabledPasswordStore());
    final Path vault = cryptomator.create(session, null, new VaultCredentials("test"));
    final Path test = new Path(vault, new AlphanumericRandomStringService().random(),
            EnumSet.of(Path.Type.file));
    session.withRegistry(
            new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
    final CryptoWriteFeature<BaseB2Response> writer = new CryptoWriteFeature<BaseB2Response>(session,
            new B2WriteFeature(session), cryptomator);
    final Cryptor cryptor = cryptomator.getCryptor();
    final FileHeader header = cryptor.fileHeaderCryptor().create();
    status.setHeader(cryptor.fileHeaderCryptor().encryptHeader(header));
    status.setNonces(new RotatingNonceGenerator(cryptomator.numberOfChunks(content.length)));
    status.setChecksum(writer.checksum(test).compute(new ByteArrayInputStream(content), status));
    final OutputStream out = writer.write(test, status, new DisabledConnectionCallback());
    assertNotNull(out);
    new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out);
    out.close();
    assertTrue(new CryptoFindFeature(session, new B2FindFeature(session), cryptomator).find(test));
    assertEquals(content.length,
            new CryptoAttributesFeature(session, new B2AttributesFinderFeature(session), cryptomator).find(test)
                    .getSize());
    assertEquals(content.length, writer.append(test, status.getLength(), PathCache.empty()).size, 0L);
    final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
    final InputStream in = new CryptoReadFeature(session, new B2ReadFeature(session), cryptomator).read(test,
            new TransferStatus().length(content.length), new DisabledConnectionCallback());
    new StreamCopier(status, status).transfer(in, buffer);
    assertArrayEquals(content, buffer.toByteArray());
    new CryptoDeleteFeature(session, new B2DeleteFeature(session), cryptomator)
            .delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
    session.close();
}

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

@Test
public void testUpload() 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"))));
    session.open(new DisabledHostKeyCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final S3SingleUploadService service = new S3SingleUploadService(session,
            new S3WriteFeature(session, new S3DisabledMultipartService()));
    final Path container = new Path("test-us-east-1-cyberduck",
            EnumSet.of(Path.Type.directory, Path.Type.volume));
    final String name = UUID.randomUUID().toString() + ".txt";
    final Path test = new Path(container, name, EnumSet.of(Path.Type.file));
    final Local local = new Local(System.getProperty("java.io.tmpdir"), name);
    final String random = new RandomStringGenerator.Builder().build().generate(1000);
    final OutputStream out = local.getOutputStream(false);
    IOUtils.write(random, out, Charset.defaultCharset());
    out.close();// w w  w  .  j  av  a  2s  . c  o m
    final TransferStatus status = new TransferStatus();
    status.setLength(random.getBytes().length);
    status.setMime("text/plain");
    service.upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED),
            new DisabledStreamListener(), status, new DisabledLoginCallback());
    assertTrue(new S3FindFeature(session).find(test));
    final PathAttributes attributes = new S3AttributesFinderFeature(session).find(test);
    assertEquals(random.getBytes().length, attributes.getSize());
    final Map<String, String> metadata = new S3MetadataFeature(session, new S3AccessControlListFeature(session))
            .getMetadata(test);
    assertFalse(metadata.isEmpty());
    assertEquals("text/plain", metadata.get("Content-Type"));
    new S3DefaultDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
    local.delete();
    session.close();
}