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.DropboxWriteFeatureTest.java

@Test
public void testWrite() throws Exception {
    final TransferStatus status = new TransferStatus();
    final int length = 1048576;
    final byte[] content = RandomUtils.nextBytes(length);
    status.setLength(content.length);// w w w .  j  a v a2  s .  c  o m
    final Path home = new DefaultHomeFinderService(session).find();
    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(
            new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
    final CryptoWriteFeature<String> writer = new CryptoWriteFeature<String>(session,
            new DropboxWriteFeature(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 DropboxFindFeature(session), cryptomator).find(test));
    assertEquals(content.length, new CryptoListService(session, session, cryptomator)
            .list(test.getParent(), new DisabledListProgressListener()).get(test).attributes().getSize());
    assertEquals(content.length,
            new CryptoWriteFeature<>(session,
                    new DropboxWriteFeature(session, new DefaultFindFeature(session),
                            new DefaultAttributesFinderFeature(session), 150000000L),
                    cryptomator).append(test, status.getLength(), PathCache.empty()).size,
            0L);
    assertEquals(content.length,
            new CryptoWriteFeature<>(session,
                    new DropboxWriteFeature(session, new DropboxFindFeature(session),
                            new DropboxAttributesFinderFeature(session), 150000000L),
                    cryptomator).append(test, status.getLength(), PathCache.empty()).size,
            0L);
    final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
    final InputStream in = new CryptoReadFeature(session, new DropboxReadFeature(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 DropboxDeleteFeature(session), cryptomator)
            .delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
}

From source file:com.netflix.simianarmy.aws.janitor.crawler.edda.EddaELBJanitorCrawler.java

@Override
public EnumSet<? extends ResourceType> resourceTypes() {
    return EnumSet.of(AWSResourceType.ELB);
}

From source file:com.metamx.common.parsers.JSONPathParser.java

/**
 * Constructor//from  ww  w. j  ava2s.c  o m
 *
 * @param fieldSpecs        List of field specifications.
 * @param useFieldDiscovery If true, automatically add root fields seen in the JSON document to the parsed object Map.
 *                          Only fields that contain a singular value or flat list (list containing no subobjects or lists) are automatically added.
 * @param mapper            Optionally provide an ObjectMapper, used by the parser for reading the input JSON.
 */
public JSONPathParser(List<FieldSpec> fieldSpecs, boolean useFieldDiscovery, ObjectMapper mapper) {
    this.fieldSpecs = fieldSpecs;
    this.fieldPathMap = generateFieldPaths(fieldSpecs);
    this.useFieldDiscovery = useFieldDiscovery;
    this.mapper = mapper == null ? new ObjectMapper() : mapper;

    // Avoid using defaultConfiguration, as this depends on json-smart which we are excluding.
    this.jsonPathConfig = Configuration.builder().jsonProvider(new JacksonJsonProvider())
            .mappingProvider(new JacksonMappingProvider()).options(EnumSet.of(Option.SUPPRESS_EXCEPTIONS))
            .build();
}

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

public Path toPath(final MantaObject object) {
    return new Path(object.getPath(),
            object.isDirectory() ? EnumSet.of(Path.Type.directory) : EnumSet.of(Path.Type.file));
}

From source file:com.github.fge.jsonschema.syntax.checkers.draftv3.DraftV3DependenciesSyntaxChecker.java

@Override
protected void checkDependency(final ProcessingReport report, final String name, final SchemaTree tree)
        throws ProcessingException {
    final JsonNode node = getNode(tree).get(name);
    NodeType type;//from  w  ww. j a v a  2 s. c  o  m

    type = NodeType.getNodeType(node);

    if (type == NodeType.STRING)
        return;

    if (type != NodeType.ARRAY) {
        report.error(newMsg(tree, "incorrectDependencyValue").put("property", name)
                .put("expected", dependencyTypes).put("found", type));
        return;
    }

    final int size = node.size();

    /*
     * Yep, in draft v3, nothing prevents a dependency array from being
     * empty! This is stupid, so at least warn the user.
     */
    if (size == 0) {
        report.warn(newMsg(tree, "emptyArray").put("property", name));
        return;
    }

    final Set<Equivalence.Wrapper<JsonNode>> set = Sets.newHashSet();

    JsonNode element;
    boolean uniqueElements = true;

    for (int index = 0; index < size; index++) {
        element = node.get(index);
        type = NodeType.getNodeType(element);
        uniqueElements = set.add(EQUIVALENCE.wrap(element));
        if (type == NodeType.STRING)
            continue;
        report.error(newMsg(tree, "incorrectElementType").put("property", name).put("index", index)
                .put("expected", EnumSet.of(NodeType.STRING)).put("found", type));
    }

    /*
     * Similarly, there is nothing preventing duplicates. Equally stupid,
     * so warn the user.
     */
    if (!uniqueElements)
        report.warn(newMsg(tree, "elementsNotUnique").put("property", name));
}

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

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

    final Set<TransferItem> found = new SingleTransferItemFinder().find(input, TerminalAction.upload,
            new Path("/cdn.cyberduck.ch/remote", EnumSet.of(Path.Type.file)));
    assertTrue(found.isEmpty());//from w ww . j ava2 s. c  om
}

From source file:de.thomasbolz.renamer.Renamer.java

/**
 * Step 1 of the renaming process:/*  www.j a  v a2s. c o m*/
 * Analysis steps in the renaming process. Walks the whole file tree of the source directory and creates a CopyTask
 * for each file or directory that is found and does not match the exclusion list.
 * @return a list of all CopyTasks
 */
public Map<Path, List<CopyTask>> prepareCopyTasks() {

    try {
        Files.walkFileTree(source, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE,
                new SimpleFileVisitor<Path>() {

                    /**
                     * If we find a directory create/copy it and add a counter
                     *
                     * @param dir
                     * @param attrs
                     * @return
                     * @throws java.io.IOException
                     */
                    @Override
                    public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
                            throws IOException {
                        Path targetdir = target.resolve(source.relativize(dir));
                        copyTasks.put(dir, new ArrayList<CopyTask>());
                        return FileVisitResult.CONTINUE;
                    }

                    @Override
                    public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                        if (!file.getFileName().toString().toLowerCase().matches(EXLUSION_REGEX)) {
                            copyTasks.get(file.getParent()).add(new CopyTask(file, null));
                        } else {
                            excludedFiles.add(file);
                        }
                        return FileVisitResult.CONTINUE;
                    }
                });
    } catch (IOException e) {
        e.printStackTrace();
    }
    sortCopyTasks();
    //        generateTargetFilenames();
    return copyTasks;
}

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

@Test
public void testPostChecksum() throws Exception {
    final StorageObject o = new StorageObject("f");
    o.setMd5sum("d41d8cd98f00b204e9800998ecf8427e");
    final SwiftSession session = new SwiftSession(new Host(new SwiftProtocol()));
    new SwiftSmallObjectUploadFeature(new SwiftWriteFeature(session, new SwiftRegionService(session)))
            .post(new Path("/f", EnumSet.of(Path.Type.file)), MessageDigest.getInstance("MD5"), o);
}

From source file:com.ejisto.util.collector.MockedFieldCollector.java

@Override
public Set<Characteristics> characteristics() {
    return EnumSet.of(Characteristics.CONCURRENT);
}

From source file:ch.cyberduck.core.cryptomator.features.CryptoReadFeatureTest.java

@Test
public void testCalculations() throws Exception {
    final NullSession session = new NullSession(new Host(new TestProtocol())) {
        @Override/* w  w  w  .  j  av  a2s  .  co  m*/
        @SuppressWarnings("unchecked")
        public <T> T _getFeature(final Class<T> type) {
            if (type == Read.class) {
                return (T) new Read() {
                    @Override
                    public InputStream read(final Path file, final TransferStatus status,
                            final ConnectionCallback callback) throws BackgroundException {
                        final String masterKey = "{\n" + "  \"scryptSalt\": \"NrC7QGG/ouc=\",\n"
                                + "  \"scryptCostParam\": 16384,\n" + "  \"scryptBlockSize\": 8,\n"
                                + "  \"primaryMasterKey\": \"Q7pGo1l0jmZssoQh9rXFPKJE9NIXvPbL+HcnVSR9CHdkeR8AwgFtcw==\",\n"
                                + "  \"hmacMasterKey\": \"xzBqT4/7uEcQbhHFLC0YmMy4ykVKbuvJEA46p1Xm25mJNuTc20nCbw==\",\n"
                                + "  \"versionMac\": \"hlNr3dz/CmuVajhaiGyCem9lcVIUjDfSMLhjppcXOrM=\",\n"
                                + "  \"version\": 5\n" + "}";
                        return IOUtils.toInputStream(masterKey, Charset.defaultCharset());
                    }

                    @Override
                    public boolean offset(final Path file) throws BackgroundException {
                        return false;
                    }
                };
            }
            return super._getFeature(type);
        }
    };
    final Path home = new Path("/", EnumSet.of((Path.Type.directory)));
    final CryptoVault vault = new CryptoVault(home, new DisabledPasswordStore());
    assertEquals(home, vault.load(session, new DisabledPasswordCallback() {
        @Override
        public Credentials prompt(final Host bookmark, final String title, final String reason,
                final LoginOptions options) throws LoginCanceledException {
            return new VaultCredentials("vault");
        }
    }).getHome());
    CryptoReadFeature read = new CryptoReadFeature(null, null, vault);
    {
        assertEquals(0, read.chunk(0));
        assertEquals(0, read.chunk(1));
        assertEquals(1, read.chunk(32768));
        assertEquals(1, read.chunk(32769));
    }
    {
        assertEquals(88, read.align(1));
        assertEquals(88, read.align(88));
        assertEquals(88, read.align(89));
        assertEquals(88, read.align(15342));
        assertEquals(88, read.align(32767));
        assertEquals(88 + 48 + 32768, read.align(32768));
        assertEquals(88 + 48 + 32768, read.align(32769));
    }
    {
        assertEquals(24, read.position(24));
        assertEquals(0, read.position(0));
        assertEquals(0, read.position(32768));
        assertEquals(1, read.position(32769));
    }
    vault.close();
}