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:com.netflix.simianarmy.aws.janitor.crawler.edda.EddaInstanceJanitorCrawler.java

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

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

@Test
public void testTransferAppend() throws Exception {
    final Host host = new Host(new SFTPProtocol(), "test.cyberduck.ch",
            new Credentials(System.getProperties().getProperty("sftp.user"),
                    System.getProperties().getProperty("sftp.password")));
    final SFTPSession session = new SFTPSession(host);
    session.open(new DisabledHostKeyCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
    final byte[] content = new byte[32770];
    new Random().nextBytes(content);
    final OutputStream out = local.getOutputStream(false);
    IOUtils.write(content, out);/*from w w  w .  ja  v a2 s . co  m*/
    out.close();
    final Path test = new Path(new SFTPHomeDirectoryService(session).find(), UUID.randomUUID().toString(),
            EnumSet.of(Path.Type.file));
    {
        final TransferStatus status = new TransferStatus().length(content.length / 2);
        new DefaultUploadFeature<Void>(new SFTPWriteFeature(session)).upload(test, local,
                new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), status,
                new DisabledConnectionCallback());
    }
    {
        final TransferStatus status = new TransferStatus().length(content.length / 2).skip(content.length / 2)
                .append(true);
        new DefaultUploadFeature<Void>(new SFTPWriteFeature(session)).upload(test, local,
                new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), status,
                new DisabledConnectionCallback());
    }
    final byte[] buffer = new byte[content.length];
    final Read read = session.getFeature(Read.class);
    final InputStream in = read.read(test, new TransferStatus().length(content.length),
            new DisabledConnectionCallback());
    IOUtils.readFully(in, buffer);
    in.close();
    assertArrayEquals(content, buffer);
    final Delete delete = session.getFeature(Delete.class);
    delete.delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
    local.delete();
    session.close();
}

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

@Test
public void testTouchLongFilenameEncrypted() throws Exception {
    final Host host = new Host(new DAVProtocol(), "test.cyberduck.ch",
            new Credentials(System.getProperties().getProperty("webdav.user"),
                    System.getProperties().getProperty("webdav.password")));
    host.setDefaultPath("/dav/basic");
    final DAVSession session = new DAVSession(host);
    session.open(new DisabledHostKeyCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    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 RandomStringGenerator.Builder().build().generate(130),
            EnumSet.of(Path.Type.file));
    final CryptoVault cryptomator = new CryptoVault(vault, new DisabledPasswordStore());
    cryptomator.create(session, null, new VaultCredentials("test"));
    session.withRegistry(/*from   w  ww  .ja v  a2  s.  c om*/
            new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
    new CryptoTouchFeature<String>(session,
            new DefaultTouchFeature<String>(new DAVUploadFeature(new DAVWriteFeature(session))),
            new DAVWriteFeature(session), cryptomator).touch(test, new TransferStatus());
    assertTrue(new CryptoFindFeature(session, new DAVFindFeature(session), cryptomator).find(test));
    new CryptoDeleteFeature(session, new DAVDeleteFeature(session), cryptomator)
            .delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
    session.close();
}

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

@Override
public void callback(final int returncode) {
    if (returncode == 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);
    }/*w w w. j a va 2 s  .  c  o  m*/
}

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

@Test
public void testDeleteFile() throws Exception {
    final Host host = new Host(new SpectraProtocol() {
        @Override//from   ww w  .  j a  va 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.volume));
    final Path test = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
    final byte[] content = RandomUtils.nextBytes(1024);
    final HttpResponseOutputStream<StorageObject> out = new S3WriteFeature(session).write(test,
            new TransferStatus().length(content.length), new DisabledConnectionCallback());
    IOUtils.write(content, out);
    out.close();
    assertTrue(new S3FindFeature(session).find(test));
    new S3MultipleDeleteFeature(session).delete(Arrays.asList(test, test), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
    assertFalse(new S3FindFeature(session).find(test));
    session.close();
}

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

@Test
public void testMakeDirectoryEncrypted() 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());
    final PathCache cache = new PathCache(100);
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final Path home = new DefaultHomeFinderService(session).find();
    final Path vault = new Path(home, new AlphanumericRandomStringService().random(),
            EnumSet.of(Path.Type.directory));
    final Path testdirectory = new Path(vault, new AlphanumericRandomStringService().random(),
            EnumSet.of(Path.Type.directory));
    final Path testdirectory2 = new Path(testdirectory, new AlphanumericRandomStringService().random(),
            EnumSet.of(Path.Type.directory));
    final Path testfile2 = new Path(testdirectory2, 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  w ww. j  a  v a  2s.c  o m
            new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
    new CryptoDirectoryFeature<Integer>(session, new FTPDirectoryFeature(session), new FTPWriteFeature(session),
            cryptomator).mkdir(testdirectory, null, new TransferStatus());
    assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).withCache(cache)
            .find(testdirectory));
    new CryptoDirectoryFeature<Integer>(session, new FTPDirectoryFeature(session), new FTPWriteFeature(session),
            cryptomator).mkdir(testdirectory2, null, new TransferStatus());
    assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).withCache(cache)
            .find(testdirectory2));
    assertFalse(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).withCache(cache)
            .find(testfile2));
    new CryptoDeleteFeature(session, new FTPDeleteFeature(session), cryptomator).delete(
            Arrays.asList(testdirectory2, testdirectory), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
    session.close();
}

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

@Override
public Set<TransferItem> find(final CommandLine input, final TerminalAction action, final Path remote)
        throws AccessDeniedException {
    if (input.getOptionValues(action.name()).length == 2) {
        final String path = input.getOptionValues(action.name())[1];
        // This only applies to a shell where the glob is not already expanded into multiple arguments
        if (StringUtils.containsAny(path, '*', '?')) {
            final Local directory = LocalFactory.get(FilenameUtils.getFullPath(path));
            if (directory.isDirectory()) {
                final PathMatcher matcher = FileSystems.getDefault()
                        .getPathMatcher(String.format("glob:%s", FilenameUtils.getName(path)));
                final Set<TransferItem> items = new HashSet<TransferItem>();
                for (Local file : directory.list(new NullFilter<String>() {
                    @Override//w ww . j a v a 2  s .com
                    public boolean accept(final String file) {
                        try {
                            return matcher.matches(Paths.get(file));
                        } catch (InvalidPathException e) {
                            log.warn(String.format("Failure obtaining path for file %s", file));
                        }
                        return false;
                    }
                })) {
                    items.add(new TransferItem(new Path(remote, file.getName(), EnumSet.of(Path.Type.file)),
                            file));
                }
                return items;
            }
        }
    }
    return new SingleTransferItemFinder().find(input, action, remote);
}

From source file:com.github.fge.jsonschema.syntax.checkers.draftv4.DraftV4DependenciesSyntaxChecker.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  w  w  . j  a v a2  s.co  m*/

    type = NodeType.getNodeType(node);

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

    final int size = node.size();

    if (size == 0) {
        report.error(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));
    }

    if (!uniqueElements)
        report.error(newMsg(tree, "elementsNotUnique").put("property", name));
}

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

@Test(expected = NotfoundException.class)
public void testReadNotFound() 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 TransferStatus status = new TransferStatus();
    new B2ReadFeature(session).read(
            new Path(new B2HomeFinderService(session).find(), "nosuchname", EnumSet.of(Path.Type.file)), status,
            new DisabledConnectionCallback());
}

From source file:ch.cyberduck.core.cryptomator.OneDriveWriteFeatureTest.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);/*from  ww w. ja  va2s. c  o m*/
    final Path home = new OneDriveHomeFinderFeature(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<Void> writer = new CryptoWriteFeature<Void>(session,
            new OneDriveWriteFeature(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 OneDriveFindFeature(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 OneDriveWriteFeature(session), cryptomator).append(test,
                    status.getLength(), PathCache.empty()).size,
            0L);
    assertEquals(content.length,
            new CryptoWriteFeature<>(session, new OneDriveWriteFeature(session), cryptomator).append(test,
                    status.getLength(), PathCache.empty()).size,
            0L);
    final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
    final InputStream in = new CryptoReadFeature(session, new OneDriveReadFeature(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 OneDriveDeleteFeature(session), cryptomator)
            .delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
}