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.cryptomator.DriveDirectoryFeatureTest.java

@Test
public void testMakeDirectoryLongFilenameEncrypted() throws Exception {
    final Path home = new DriveHomeFinderService(session).find();
    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(//from  w w w  .j ava 2s .co  m
            new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
    final Path test = new CryptoDirectoryFeature<Void>(session, new DriveDirectoryFeature(session),
            new DriveWriteFeature(session), cryptomator)
                    .mkdir(new Path(vault, new RandomStringGenerator.Builder().build().generate(130),
                            EnumSet.of(Path.Type.directory)), null, new TransferStatus());
    assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(test));
    new CryptoDeleteFeature(session, new DriveDeleteFeature(session), cryptomator)
            .delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
}

From source file:ch.cyberduck.core.dropbox.DropboxReadFeatureTest.java

@Test
public void testReadRange() throws Exception {
    final Path drive = new DefaultHomeFinderService(session).find();
    final Path test = new Path(drive, new AlphanumericRandomStringService().random(),
            EnumSet.of(Path.Type.file));
    new DropboxTouchFeature(session).touch(test, new TransferStatus());

    final Local local = new Local(System.getProperty("java.io.tmpdir"),
            new AlphanumericRandomStringService().random());
    final byte[] content = RandomUtils.nextBytes(1000);
    final OutputStream out = local.getOutputStream(false);
    assertNotNull(out);/*from  w  ww  .j  av  a 2  s. c o  m*/
    IOUtils.write(content, out);
    out.close();
    new DefaultUploadFeature<String>(new DropboxWriteFeature(session)).upload(test, local,
            new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(),
            new TransferStatus().length(content.length), new DisabledConnectionCallback());
    final TransferStatus status = new TransferStatus();
    status.setLength(content.length);
    status.setAppend(true);
    status.setOffset(100L);
    final DropboxReadFeature read = new DropboxReadFeature(session);
    assertTrue(read.offset(test));
    final InputStream in = read.read(test, status.length(content.length - 100),
            new DisabledConnectionCallback());
    assertNotNull(in);
    final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length - 100);
    new StreamCopier(status, status).transfer(in, buffer);
    final byte[] reference = new byte[content.length - 100];
    System.arraycopy(content, 100, reference, 0, content.length - 100);
    assertArrayEquals(reference, buffer.toByteArray());
    in.close();
    new DropboxDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
}

From source file:com.slytechs.utils.number.Version.java

/**
 * Initialized with major version.//from  w  w w.j  a  v  a  2  s.c  om
 * 
 * @param major
 *   major version
 */
public Version(int major) {
    this.major = major;

    this.detail = EnumSet.of(VersionDetail.Major);

    map.put(VersionDetail.Major, major);

}

From source file:com.spotify.docker.client.CompressedDirectory.java

/**
 * This method creates a gzip tarball of the specified directory. File permissions will be
 * retained. The file will be created in a temporary directory using the {@link
 * Files#createTempFile(String, String, FileAttribute[])} method. The returned object is
 * auto-closeable, and upon closing it, the archive file will be deleted.
 *
 * @param directory the directory to compress
 * @return a Path object representing the compressed directory
 * @throws IOException if the compressed directory could not be created.
 *///from   w  w  w. j  a  v a 2 s  .c  o  m
public static CompressedDirectory create(final Path directory) throws IOException {
    final Path file = Files.createTempFile("docker-client-", ".tar.gz");

    final Path dockerIgnorePath = directory.resolve(".dockerignore");
    final ImmutableSet<PathMatcher> ignoreMatchers = parseDockerIgnore(dockerIgnorePath);

    try (final OutputStream fileOut = Files.newOutputStream(file);
            final GzipCompressorOutputStream gzipOut = new GzipCompressorOutputStream(fileOut);
            final TarArchiveOutputStream tarOut = new TarArchiveOutputStream(gzipOut)) {
        tarOut.setLongFileMode(LONGFILE_POSIX);
        tarOut.setBigNumberMode(BIGNUMBER_POSIX);
        Files.walkFileTree(directory, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE,
                new Visitor(directory, ignoreMatchers, tarOut));

    } catch (Throwable t) {
        // If an error occurs, delete temporary file before rethrowing exception.
        try {
            Files.delete(file);
        } catch (IOException e) {
            // So we don't lose track of the reason the file was deleted... might be important
            t.addSuppressed(e);
        }

        throw t;
    }

    return new CompressedDirectory(file);
}

From source file:org.halkneistiyor.social.web.SignupController.java

private SocialUser createUser(SignupForm form, BindingResult formBinding) {
    SocialUser su = new SocialUser();
    su.setEmail(form.getEmail());//  w w w . j  a v a 2s.c  o m
    su.setFirstName(form.getFirstName());
    su.setLastName(form.getLastName());
    su.setEnabled(true);
    Set<UserRole> roles = EnumSet.of(UserRole.USER);
    if (UserServiceFactory.getUserService().isUserAdmin()) {
        roles.add(UserRole.ADMIN);
    }
    su.setRoles(roles);

    socialUserManager.registerUser(su);
    return su;
}

From source file:ch.cyberduck.core.ftp.FTPReadFeatureTest.java

@Test
public void testRead() 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 Path home = new FTPWorkdirService(session).find();
    final Path test = new Path(home, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
    session.getFeature(Touch.class).touch(test, new TransferStatus());
    final int length = 39865;
    final byte[] content = RandomUtils.nextBytes(length);
    {/*from   w  w  w.  ja va2 s .  c o  m*/
        final TransferStatus status = new TransferStatus().length(content.length);
        final OutputStream out = new FTPWriteFeature(session).write(test, status,
                new DisabledConnectionCallback());
        assertNotNull(out);
        new StreamCopier(status, status).withLimit(new Long(content.length))
                .transfer(new ByteArrayInputStream(content), out);
        out.close();
    }
    {
        final TransferStatus status = new TransferStatus();
        status.setLength(content.length);
        final InputStream in = new FTPReadFeature(session).read(test, status, new DisabledConnectionCallback());
        assertNotNull(in);
        final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
        new StreamCopier(status, status).withLimit(new Long(content.length)).transfer(in, buffer);
        in.close();
        assertArrayEquals(content, buffer.toByteArray());
    }
    new FTPDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
    session.close();
}

From source file:com.foilen.smalltools.tools.Hibernate51Tools.java

/**
 * Generate the SQL file. This is based on the code in {@link LocalSessionFactoryBuilder#scanPackages(String...)}
 *
 * @param dialect/*from ww  w .j  a v a2  s.  co  m*/
 *            the dialect (e.g: org.hibernate.dialect.MySQL5InnoDBDialect )
 * @param outputSqlFile
 *            where to put the generated SQL file
 * @param useUnderscore
 *            true: to have tables names like "employe_manager" ; false: to have tables names like "employeManager"
 * @param packagesToScan
 *            the packages where your entities are
 */
public static void generateSqlSchema(Class<? extends Dialect> dialect, String outputSqlFile,
        boolean useUnderscore, String... packagesToScan) {

    BootstrapServiceRegistry bootstrapServiceRegistry = new BootstrapServiceRegistryBuilder().build();

    MetadataSources metadataSources = new MetadataSources(bootstrapServiceRegistry);

    ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(
            false);
    scanner.addIncludeFilter(new AnnotationTypeFilter(Entity.class));
    scanner.addIncludeFilter(new AnnotationTypeFilter(Embeddable.class));
    scanner.addIncludeFilter(new AnnotationTypeFilter(MappedSuperclass.class));
    for (String pkg : packagesToScan) {
        for (BeanDefinition beanDefinition : scanner.findCandidateComponents(pkg)) {
            metadataSources.addAnnotatedClassName(beanDefinition.getBeanClassName());
        }
    }

    StandardServiceRegistryBuilder standardServiceRegistryBuilder = new StandardServiceRegistryBuilder(
            bootstrapServiceRegistry);
    standardServiceRegistryBuilder.applySetting(AvailableSettings.DIALECT, dialect.getName());
    StandardServiceRegistryImpl ssr = (StandardServiceRegistryImpl) standardServiceRegistryBuilder.build();
    MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder(ssr);

    if (useUnderscore) {
        metadataBuilder.applyImplicitNamingStrategy(new SpringImplicitNamingStrategy());
        metadataBuilder.applyPhysicalNamingStrategy(new SpringPhysicalNamingStrategy());
    }

    new SchemaExport() //
            .setHaltOnError(true) //
            .setOutputFile(outputSqlFile) //
            .setFormat(true) //
            .setDelimiter(";") //
            .execute(EnumSet.of(TargetType.SCRIPT), SchemaExport.Action.CREATE, metadataBuilder.build());

}

From source file:ch.cyberduck.core.dav.DAVReadFeatureTest.java

@Test
public void testReadChunkedTransfer() throws Exception {
    final Host host = new Host(new DAVSSLProtocol(), "svn.cyberduck.ch",
            new Credentials(PreferencesFactory.get().getProperty("connection.login.anon.name"), null));
    final DAVSession session = new DAVSession(host);
    final LoginConnectionService service = new LoginConnectionService(new DisabledLoginCallback(),
            new DisabledHostKeyCallback(), new DisabledPasswordStore(), new DisabledProgressListener());
    service.connect(session, PathCache.empty(), new DisabledCancelCallback());
    final Path test = new Path("/trunk/LICENSE.txt", EnumSet.of(Path.Type.file));
    // Unknown length in status
    final TransferStatus status = new TransferStatus() {
        @Override//from  w ww .j  a v  a  2s.  com
        public void setLength(long length) {
            assertEquals(923L, length);
            // Ignore update. As with unknown length for chunked transfer
        }
    };
    final Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
    assertEquals(-1L, local.attributes().getSize());
    new DefaultDownloadFeature(session.getFeature(Read.class)).download(test, local,
            new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), status,
            new DisabledLoginCallback(), new DisabledPasswordCallback());
    assertEquals(35147L, local.attributes().getSize());
}

From source file:ch.cyberduck.core.manta.MantaWriteFeatureTest.java

@Test
public void testWriteUnknownLength() throws Exception {
    final MantaWriteFeature feature = new MantaWriteFeature(session);
    final Path container = randomDirectory();
    new MantaDirectoryFeature(session).mkdir(container, "", new TransferStatus());
    final byte[] content = RandomUtils.nextBytes(5 * 1024 * 1024);

    final TransferStatus status = new TransferStatus();
    status.setLength(-1L);//from   ww  w  . j  av  a2  s. c o m
    final Path file = new Path(container, new AlphanumericRandomStringService().random(),
            EnumSet.of(Path.Type.file));
    final HttpResponseOutputStream<Void> out = feature.write(file, status, new DisabledConnectionCallback());
    final ByteArrayInputStream in = new ByteArrayInputStream(content);
    final int alloc = 1024;
    final byte[] buffer = new byte[alloc];
    assertEquals(content.length, IOUtils.copyLarge(in, out, buffer));
    out.close();
    final PathAttributes found = new MantaAttributesFinderFeature(session).find(file);
    assertEquals(found.getSize(), content.length);
    new MantaDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
}

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

@Override
public AttributedList<Path> list(final Path directory, final ListProgressListener listener)
        throws BackgroundException {
    final String prefix = this.createPrefix(directory);
    final Path bucket = containerService.getContainer(directory);
    final AttributedList<Path> children = new AttributedList<Path>();
    try {/*from   www .j a v a 2s  .  c om*/
        String priorLastKey = null;
        String priorLastVersionId = null;
        do {
            final VersionOrDeleteMarkersChunk chunk = session.getClient().listVersionedObjectsChunked(
                    bucket.getName(), prefix, String.valueOf(Path.DELIMITER),
                    preferences.getInteger("s3.listing.chunksize"), priorLastKey, priorLastVersionId, true);
            // Amazon S3 returns object versions in the order in which they were
            // stored, with the most recently stored returned first.
            final List<BaseVersionOrDeleteMarker> items = Arrays.asList(chunk.getItems());
            int i = 0;
            for (BaseVersionOrDeleteMarker marker : items) {
                final String key = PathNormalizer.normalize(marker.getKey());
                if (String.valueOf(Path.DELIMITER).equals(key)) {
                    log.warn(String.format("Skipping prefix %s", key));
                    continue;
                }
                if (new Path(bucket, key, EnumSet.of(Path.Type.directory)).equals(directory)) {
                    continue;
                }
                final PathAttributes attributes = new PathAttributes();
                if (!StringUtils.equals("null", marker.getVersionId())) {
                    // If you have not enabled versioning, then S3 sets the version ID value to null.
                    attributes.setVersionId(marker.getVersionId());
                }
                attributes.setRevision(++i);
                attributes.setDuplicate((marker.isDeleteMarker() && marker.isLatest()) || !marker.isLatest());
                attributes.setModificationDate(marker.getLastModified().getTime());
                attributes.setRegion(bucket.attributes().getRegion());
                if (marker instanceof S3Version) {
                    final S3Version object = (S3Version) marker;
                    attributes.setSize(object.getSize());
                    if (StringUtils.isNotBlank(object.getEtag())) {
                        attributes.setChecksum(Checksum.parse(object.getEtag()));
                        attributes.setETag(object.getEtag());
                    }
                    if (StringUtils.isNotBlank(object.getStorageClass())) {
                        attributes.setStorageClass(object.getStorageClass());
                    }
                }
                final Path f = new Path(directory, PathNormalizer.name(key), EnumSet.of(Path.Type.file),
                        attributes);
                children.add(f);
            }
            final String[] prefixes = chunk.getCommonPrefixes();
            for (String common : prefixes) {
                if (String.valueOf(Path.DELIMITER).equals(common)) {
                    log.warn(String.format("Skipping prefix %s", common));
                    continue;
                }
                final String key = PathNormalizer.normalize(common);
                if (new Path(bucket, key, EnumSet.of(Path.Type.directory)).equals(directory)) {
                    continue;
                }
                final PathAttributes attributes = new PathAttributes();
                attributes.setRegion(bucket.attributes().getRegion());
                final Path file = new Path(
                        String.format("%s%s%s", bucket.getAbsolute(), String.valueOf(Path.DELIMITER), key),
                        EnumSet.of(Path.Type.directory, Path.Type.placeholder), attributes);
                children.add(file);
            }
            priorLastKey = chunk.getNextKeyMarker();
            priorLastVersionId = chunk.getNextVersionIdMarker();
            listener.chunk(directory, children);
        } while (priorLastKey != null);
        return children;
    } catch (ServiceException e) {
        throw new S3ExceptionMappingService().map("Listing directory {0} failed", e, directory);
    }
}