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:ch.cyberduck.core.b2.B2LargeUploadServiceTest.java

@Test
public void testUpload() 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 test = new Path(bucket, UUID.randomUUID().toString() + ".txt", EnumSet.of(Path.Type.file));
    final Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());

    // Each segment, except the last, must be larger than 100MB.
    final int length = 100 * 1024 * 1024 + 1;
    final byte[] content = RandomUtils.nextBytes(length);

    final OutputStream out = local.getOutputStream(false);
    IOUtils.write(content, out);//from w  ww  . j a v  a  2  s  .  c  o m
    out.close();
    final TransferStatus status = new TransferStatus();
    status.setLength(content.length);
    final Checksum checksum = new SHA1ChecksumCompute().compute(new ByteArrayInputStream(content),
            new TransferStatus());
    status.setChecksum(checksum);

    final B2LargeUploadService upload = new B2LargeUploadService(session, new B2WriteFeature(session),
            PreferencesFactory.get().getLong("b2.upload.largeobject.size"),
            PreferencesFactory.get().getInteger("b2.upload.largeobject.concurrency"));

    upload.upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(),
            status, new DisabledConnectionCallback());
    assertEquals(checksum, new B2AttributesFinderFeature(session).find(test).getChecksum());

    assertTrue(status.isComplete());
    assertFalse(status.isCanceled());
    assertEquals(content.length, status.getOffset());

    assertTrue(new DefaultFindFeature(session).find(test));
    final InputStream in = new B2ReadFeature(session).read(test, new TransferStatus(),
            new DisabledConnectionCallback());
    final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
    new StreamCopier(status, status).transfer(in, buffer);
    in.close();
    buffer.close();
    assertArrayEquals(content, buffer.toByteArray());
    new B2DeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
    local.delete();
    session.close();
}

From source file:com.github.fge.jsonschema.core.keyword.syntax.checkers.AbstractSyntaxChecker.java

/**
 * Main constructor//  w w w .j  a  v  a 2s  . co m
 *
 * @param keyword the keyword name
 * @param first the first valid type for this keyword's value
 * @param other other valid types for this keyword's value (if any)
 */
protected AbstractSyntaxChecker(final String keyword, final NodeType first, final NodeType... other) {
    this.keyword = keyword;
    types = EnumSet.of(first, other);
}

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

@Test
public void testWriteChecksumFailure() 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 Path bucket = new Path("test-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final Path file = new Path(bucket, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
    final TransferStatus status = new TransferStatus();
    final byte[] content = RandomUtils.nextBytes(1);
    status.setLength(content.length);/*w w w.  j a  v  a2s  . c  o  m*/
    status.setChecksum(Checksum.parse("da39a3ee5e6b4b0d3255bfef95601890afd80709"));
    final HttpResponseOutputStream<BaseB2Response> out = new B2WriteFeature(session).write(file, status,
            new DisabledConnectionCallback());
    IOUtils.write(content, out);
    try {
        out.close();
        fail();
    } catch (IOException e) {
        assertTrue(e.getCause() instanceof ChecksumException);
    } finally {
        session.close();
    }
}

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

@Test(expected = NotfoundException.class)
public void testUploadInvalidContainer() 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.setSignatureVersion(S3Protocol.AuthenticationHeaderSignatureVersion.AWS2);
    session.open(new DisabledHostKeyCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final S3ThresholdUploadService m = new S3ThresholdUploadService(session, 5 * 1024L);
    final Path container = new Path("nosuchcontainer.cyberduck.ch",
            EnumSet.of(Path.Type.directory, Path.Type.volume));
    final Path test = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
    final Local local = new NullLocal(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
    final TransferStatus status = new TransferStatus();
    m.upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(),
            status, null);//w  w  w  .  j a  va  2s . c o  m
}

From source file:bit.changepurse.wdk.http.TestHTTPRequest.java

@Test
public void testBuild() {
    for (HTTPMethod method : HTTPMethod.values()) {
        try {//  w w w .j  a  v a  2s  . c  o  m
            HTTPRequest request = new HTTPRequest();
            request.setMethod(method);
            request.setUrl(TEST_URL);
            HttpRequestBase apacheRequest = request.build();
            assertThat(apacheRequest, instanceOf(mapping.get(method)));
            assertThat(apacheRequest.getURI(), equalTo(newURI(TEST_URL)));
        } catch (HTTPException exception) {
            assertThat(method, not(isIn(EnumSet.of(HTTPMethod.GET, HTTPMethod.POST))));
        }
    }
}

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

@Override
public Space get() throws BackgroundException {
    try {/*  ww  w. j a va  2s. c  o m*/
        final Path home = new DefaultHomeFinderService(session).find();
        if (!home.isRoot()) {
            final Node node = new NodesApi(session.getClient()).getFsNode(StringUtils.EMPTY,
                    Long.parseLong(
                            new SDSNodeIdProvider(session).getFileid(home, new DisabledListProgressListener())),
                    null);
            if (null == node.getQuota()) {
                log.warn(String.format("No quota set for node %s", home));
            } else {
                return new Space(node.getSize(), node.getQuota() - node.getSize());
            }
        }
        final CustomerData info = new UserApi(session.getClient()).getCustomerInfo(StringUtils.EMPTY, null);
        return new Space(info.getSpaceUsed(), info.getSpaceLimit() - info.getSpaceUsed());
    } catch (ApiException e) {
        throw new SDSExceptionMappingService().map("Failure to read attributes of {0}", e,
                new Path(String.valueOf(Path.DELIMITER), EnumSet.of(Path.Type.volume, Path.Type.directory)));
    }
}

From source file:ch.cyberduck.core.sds.SDSMultipartWriteFeatureTest.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(-1L);/*from w w  w  . j  a v a2 s.  co  m*/
    final Path test = new Path(room, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
    final SDSMultipartWriteFeature writer = new SDSMultipartWriteFeature(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();
}

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

@Test
public void testMakeDirectoryEncrypted() throws Exception {
    final Host host = new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(), new Credentials(
            System.getProperties().getProperty("s3.key"), System.getProperties().getProperty("s3.secret")));
    final S3Session session = new S3Session(host);
    session.open(new DisabledHostKeyCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final Path home = new Path("test-us-east-1-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final Path vault = new Path(home, new AlphanumericRandomStringService().random(),
            EnumSet.of(Path.Type.directory));
    final CryptoVault cryptomator = new CryptoVault(vault, new DisabledPasswordStore());
    cryptomator.create(session, null, new VaultCredentials("test"));
    session.withRegistry(//www . ja v  a  2s  .co m
            new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
    final Path test = new CryptoDirectoryFeature<StorageObject>(session,
            new S3DirectoryFeature(session, new S3WriteFeature(session)), new S3WriteFeature(session),
            cryptomator)
                    .mkdir(new Path(vault, new AlphanumericRandomStringService().random(),
                            EnumSet.of(Path.Type.directory)), null, new TransferStatus());
    assertTrue(test.getType().contains(Path.Type.placeholder));
    assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(test));
    new CryptoDeleteFeature(session, new S3DefaultDeleteFeature(session), cryptomator)
            .delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
    session.close();
}

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

@Test
public void testMakeDirectoryEncrypted() throws Exception {
    final Host host = new Host(new AzureProtocol(), "kahy9boj3eib.blob.core.windows.net",
            new Credentials(System.getProperties().getProperty("azure.account"),
                    System.getProperties().getProperty("azure.key")));
    final AzureSession session = new AzureSession(host);
    session.open(new DisabledHostKeyCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final Path home = new Path("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"));
    session.withRegistry(//  w  w w .ja v  a 2 s  . c  o  m
            new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
    final Path test = new CryptoDirectoryFeature<Void>(session, new AzureDirectoryFeature(session, null),
            new AzureWriteFeature(session, null), cryptomator)
                    .mkdir(new Path(vault, new AlphanumericRandomStringService().random(),
                            EnumSet.of(Path.Type.directory)), null, new TransferStatus());
    assertTrue(test.getType().contains(Path.Type.placeholder));
    assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(test));
    new CryptoDeleteFeature(session, new AzureDeleteFeature(session, null), cryptomator)
            .delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
    session.close();
}

From source file:com.econcept.init.MainWebAppplicationInitializer.java

@Override
public void onStartup(ServletContext pContainer) throws ServletException {
    // Create the 'root' Spring application context
    AnnotationConfigWebApplicationContext lRootContext = new AnnotationConfigWebApplicationContext();
    lRootContext.scan("com.econcept.init");

    // Manage the lifecycle of the root application context
    pContainer.addListener(new ContextLoaderListener(lRootContext));

    // Register and map the dispatcher servlet
    ServletRegistration.Dynamic lDispatcher = pContainer.addServlet("CFXServlet", CXFServlet.class);
    lDispatcher.addMapping("/rest/*");

    // Apply Spring OAuthSecurity to both forward and request dispatcher
    FilterRegistration.Dynamic lFilter = pContainer.addFilter("unicodeFilter", new UnicodeFilter());
    lFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), true, "/*");

    // Apply Spring OAuthSecurity to both forward and request dispatcher
    lFilter = pContainer.addFilter("securityFilter", new DelegatingFilterProxy("springSecurityFilterChain"));
    lFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), true, "/*");

    pContainer.addListener(AppHttpSessionListener.class);

}