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.DriveWriteFeatureTest.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 .ja v  a2  s.  c  o m
    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"));
    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<Void> writer = new CryptoWriteFeature<Void>(session,
            new DriveWriteFeature(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());
    Assert.assertNotNull(out);
    new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out);
    out.close();
    Assert.assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(test));
    Assert.assertEquals(content.length,
            new CryptoAttributesFeature(session, new DefaultAttributesFinderFeature(session), cryptomator)
                    .find(test).getSize());
    Assert.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 DriveReadFeature(session), cryptomator).read(test,
            new TransferStatus().length(content.length), new DisabledConnectionCallback());
    new StreamCopier(status, status).transfer(in, buffer);
    Assert.assertArrayEquals(content, buffer.toByteArray());
    new CryptoDeleteFeature(session, new DriveDeleteFeature(session), cryptomator)
            .delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
}

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

@Test
public void testFind() throws Exception {
    File.createTempFile("temp", ".duck");
    final File f = File.createTempFile("temp", ".duck");
    File.createTempFile("temp", ".false");

    final CommandLineParser parser = new PosixParser();
    final CommandLine input = parser.parse(TerminalOptionsBuilder.options(),
            new String[] { "--upload", "rackspace://cdn.cyberduck.ch/remote", f.getParent() + "/*.duck" });

    final Set<TransferItem> found = new GlobTransferItemFinder().find(input, TerminalAction.upload,
            new Path("/cdn.cyberduck.ch/remote", EnumSet.of(Path.Type.file)));
    assertFalse(found.isEmpty());/* ww  w.j ava 2s.  c  o  m*/
    assertTrue(found.contains(
            new TransferItem(new Path(new Path("/cdn.cyberduck.ch/remote", EnumSet.of(Path.Type.directory)),
                    f.getName(), EnumSet.of(Path.Type.file)), new Local(f.getAbsolutePath()))));
}

From source file:com.google.code.linkedinapi.client.examples.PostNetworkUpdateExample.java

/**
 * Process command line options and call the service.
 *///from w  w  w .  j  a  va2  s. c o m
private static void processCommandLine(CommandLine line, Options options) {
    if (line.hasOption(HELP_OPTION)) {
        printHelp(options);
    } else if (line.hasOption(CONSUMER_KEY_OPTION) && line.hasOption(CONSUMER_SECRET_OPTION)
            && line.hasOption(ACCESS_TOKEN_OPTION) && line.hasOption(ACCESS_TOKEN_SECRET_OPTION)) {
        final String consumerKeyValue = line.getOptionValue(CONSUMER_KEY_OPTION);
        final String consumerSecretValue = line.getOptionValue(CONSUMER_SECRET_OPTION);
        final String accessTokenValue = line.getOptionValue(ACCESS_TOKEN_OPTION);
        final String tokenSecretValue = line.getOptionValue(ACCESS_TOKEN_SECRET_OPTION);

        final LinkedInApiClientFactory factory = LinkedInApiClientFactory.newInstance(consumerKeyValue,
                consumerSecretValue);
        final LinkedInApiClient client = factory.createLinkedInApiClient(accessTokenValue, tokenSecretValue);

        if (line.hasOption(UPDATE_TEXT_OPTION)) {
            final String updateText = line.getOptionValue(UPDATE_TEXT_OPTION);
            client.postNetworkUpdate(updateText);
            System.out.println("Your update has been posted. Check the LinkedIn site for confirmation.");
        }
        System.out.println("Fetching your network updates of type:" + NetworkUpdateType.SHARED_ITEM);
        Network network = client.getNetworkUpdates(EnumSet.of(NetworkUpdateType.SHARED_ITEM));
        printResult(network);
    } else {
        printHelp(options);
    }
}

From source file:io.lavagna.web.api.PermissionController.java

@RequestMapping(value = "/api/role/ANONYMOUS/toggle-search-permission", method = RequestMethod.POST)
public void toggleSearchPermission(@RequestBody ToggleSearchPermission addSearch) {
    Set<Permission> permissions = EnumSet.of(Permission.READ);
    if (addSearch.value) {
        permissions.add(Permission.SEARCH);
    }//w ww  .jav a  2s.  c  o m
    permissionService.updatePermissionsToRole(new Role("ANONYMOUS"), permissions);
    eventEmitter.emitUpdatePermissionsToRole();
}

From source file:ch.cyberduck.ui.cocoa.controller.DownloadController.java

@Override
public void callback(final int returncode) {
    switch (returncode) {
    case DEFAULT_OPTION:
        final Host host = HostParser.parse(urlField.stringValue());
        final Path file = new Path(PathNormalizer.normalize(host.getDefaultPath(), true),
                EnumSet.of(detector.detect(host.getDefaultPath())));
        host.setDefaultPath(file.getParent().getAbsolute());
        final Transfer transfer = new DownloadTransfer(host, file, LocalFactory
                .get(PreferencesFactory.get().getProperty("queue.download.folder"), file.getName()));
        TransferControllerFactory.get().start(transfer, new TransferOptions());
        break;/*from ww w  .  ja v  a 2s.  c o  m*/
    }
}

From source file:ch.cyberduck.core.googledrive.DriveSearchFeatureTest.java

@Test
public void testSearchFolder() throws Exception {
    final String name = new AlphanumericRandomStringService().random();
    final Path workdir = new DriveDirectoryFeature(session).mkdir(
            new Path(new DriveHomeFinderService(session).find(), new AlphanumericRandomStringService().random(),
                    EnumSet.of(Path.Type.directory)),
            null, new TransferStatus());
    final Path file = new DriveTouchFeature(session).touch(new Path(workdir, name, EnumSet.of(Path.Type.file)),
            new TransferStatus());
    final DriveSearchFeature feature = new DriveSearchFeature(session);
    assertTrue(//  w w w.j av  a 2 s.co  m
            feature.search(workdir, new SearchFilter(name), new DisabledListProgressListener()).contains(file));
    // Supports prefix matching only
    assertFalse(feature.search(workdir, new SearchFilter(StringUtils.substring(name, 2)),
            new DisabledListProgressListener()).contains(file));
    final AttributedList<Path> result = feature.search(workdir,
            new SearchFilter(StringUtils.substring(name, 0, name.length() - 2)),
            new DisabledListProgressListener());
    assertTrue(result.contains(file));
    assertEquals(workdir, result.get(result.indexOf(file)).getParent());
    final Path subdir = new DriveDirectoryFeature(session).mkdir(
            new Path(workdir, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)),
            null, new TransferStatus());
    assertFalse(
            feature.search(subdir, new SearchFilter(name), new DisabledListProgressListener()).contains(file));
    new DriveDeleteFeature(session).delete(Arrays.asList(file, subdir), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
}

From source file:ch.cyberduck.ui.cocoa.controller.FileController.java

@Override
public void callback(final int returncode) {
    final Path directory = new UploadTargetFinder(workdir).find(selected);
    switch (returncode) {
    case DEFAULT_OPTION:
    case ALTERNATE_OPTION:
        this.callback(returncode, new Path(directory, inputField.stringValue(), EnumSet.of(Path.Type.file)));
        break;//from  ww w .j ava2s.  co m
    }
}

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

/**
 * @param file File reference/*  www .ja  va 2s .  c o  m*/
 * @return File id of unfinished large upload
 */
public List<B2FileInfoResponse> find(final Path file) throws BackgroundException {
    if (log.isDebugEnabled()) {
        log.debug(String.format("Finding multipart uploads for %s", file));
    }
    try {
        final List<B2FileInfoResponse> uploads = new ArrayList<B2FileInfoResponse>();
        // This operation lists in-progress multipart uploads. An in-progress multipart upload is a
        // multipart upload that has been initiated, using the Initiate Multipart Upload request, but has
        // not yet been completed or aborted.
        String startFileId = null;
        do {
            final B2ListFilesResponse chunk;
            chunk = session.getClient()
                    .listUnfinishedLargeFiles(new B2FileidProvider(session)
                            .getFileid(containerService.getContainer(file), new DisabledListProgressListener()),
                            startFileId, null);
            for (B2FileInfoResponse upload : chunk.getFiles()) {
                if (file.isDirectory()) {
                    final Path parent = new Path(containerService.getContainer(file), upload.getFileName(),
                            EnumSet.of(Path.Type.file)).getParent();
                    if (parent.equals(file)) {
                        uploads.add(upload);
                    }
                } else {
                    if (StringUtils.equals(upload.getFileName(), containerService.getKey(file))) {
                        uploads.add(upload);
                    }
                }
            }
            if (log.isInfoEnabled()) {
                log.info(String.format("Found %d previous multipart uploads for %s", uploads.size(), file));
            }
            startFileId = chunk.getNextFileId();
        } while (startFileId != null);
        if (log.isInfoEnabled()) {
            for (B2FileInfoResponse upload : uploads) {
                log.info(String.format("Found multipart upload %s for %s", upload, file));
            }
        }
        // Uploads are listed in the order they were started, with the oldest one first
        Collections.sort(uploads, new Comparator<B2FileInfoResponse>() {
            @Override
            public int compare(final B2FileInfoResponse o1, final B2FileInfoResponse o2) {
                return o1.getUploadTimestamp().compareTo(o2.getUploadTimestamp());
            }
        });
        Collections.reverse(uploads);
        return uploads;
    } catch (B2ApiException e) {
        throw new B2ExceptionMappingService().map("Upload {0} failed", e, file);
    } catch (IOException e) {
        throw new DefaultIOExceptionMappingService().map("Cannot delete {0}", e, file);
    }
}

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

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

    type = NodeType.getNodeType(node);

    if (type != NodeType.ARRAY) {
        report.error(
                newMsg(tree, bundle, "common.dependencies.value.incorrectType").putArgument("property", name)
                        .putArgument("expected", dependencyTypes).putArgument("found", type));
        return;
    }

    final int size = node.size();

    if (size == 0) {
        report.error(newMsg(tree, bundle, "common.array.empty").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, bundle, "common.array.element.incorrectType").put("property", name)
                .putArgument("index", index).putArgument("expected", EnumSet.of(NodeType.STRING))
                .putArgument("found", type));
    }

    if (!uniqueElements)
        report.error(newMsg(tree, bundle, "common.array.duplicateElements").put("property", name));
}

From source file:ch.cyberduck.core.irods.IRODSReadFeatureTest.java

@Test
public void testRead() throws Exception {
    final ProtocolFactory factory = new ProtocolFactory(
            new HashSet<>(Collections.singleton(new IRODSProtocol())));
    final Profile profile = new ProfilePlistReader(factory)
            .read(new Local("../profiles/iRODS (iPlant Collaborative).cyberduckprofile"));
    final Host host = new Host(profile, profile.getDefaultHostname(),
            new Credentials(System.getProperties().getProperty("irods.key"),
                    System.getProperties().getProperty("irods.secret")));

    final IRODSSession session = new IRODSSession(host);
    session.open(new DisabledHostKeyCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());

    final Path test = new Path(new IRODSHomeFinderService(session).find(), UUID.randomUUID().toString(),
            EnumSet.of(Path.Type.file));
    assertFalse(session.getFeature(Find.class).find(test));

    final byte[] content = RandomUtils.nextBytes(2048);
    final TransferStatus status = new TransferStatus();
    status.setLength(content.length);/*w  w  w .  j a v a  2s  .  c  o  m*/
    status.setAppend(false);
    final OutputStream out = new IRODSWriteFeature(session).write(test, status,
            new DisabledConnectionCallback());
    assertNotNull(out);

    new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out);
    out.close();
    assertTrue(session.getFeature(Find.class).find(test));

    final InputStream in = new IRODSReadFeature(session).read(test, status, new DisabledConnectionCallback());
    assertNotNull(in);
    in.close();

    session.getFeature(Delete.class).delete(Arrays.asList(test), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
    assertFalse(session.getFeature(Find.class).find(test));
    session.close();
}