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.manta.MantaReadFeatureTest.java

@Test
public void testReadInterrupt() throws Exception {
    final Path drive = new MantaDirectoryFeature(session).mkdir(randomDirectory(), "", new TransferStatus());
    final Path test = new Path(drive, new AlphanumericRandomStringService().random(),
            EnumSet.of(Path.Type.file));
    new MantaTouchFeature(session).touch(test, new TransferStatus());
    // Unknown length in status
    final TransferStatus status = new TransferStatus();
    // Read a single byte
    {/*  ww  w . j a v a 2  s.c o  m*/
        final InputStream in = new MantaReadFeature(session).read(test, status,
                new DisabledConnectionCallback());
        assertNotNull(in.read());
        in.close();
    }
    {
        final InputStream in = new MantaReadFeature(session).read(test, status,
                new DisabledConnectionCallback());
        assertNotNull(in);
        in.close();
    }
    final MantaDeleteFeature delete = new MantaDeleteFeature(session);
    delete.delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}

From source file:hudson.plugins.clearcase.ucm.service.BaselineService.java

public ActivitiesDelta compareWithVersions(Baseline from, Baseline to, String viewPath) throws IOException {
    return compare(from, to, EnumSet.of(DiffBlOptions.VERSIONS), viewPath);
}

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

@Test
public void testListDefault() 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 ListService list = new FTPDefaultListService(session, new DisabledPasswordStore(),
            new DisabledLoginCallback(), new CompositeFileEntryParser(Arrays.asList(new UnixFTPEntryParser())),
            FTPListService.Command.list);
    final Path directory = new FTPWorkdirService(session).find();
    final Path file = new Path(directory, new AlphanumericRandomStringService().random(),
            EnumSet.of(Path.Type.file));
    new DefaultTouchFeature<Integer>(new DefaultUploadFeature<Integer>(new FTPWriteFeature(session)))
            .touch(file, new TransferStatus());
    assertTrue(list.list(directory, new DisabledListProgressListener()).contains(file));
    new FTPDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
    session.close();//  w w  w  .  j  av  a2  s .co  m
}

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

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

From source file:ch.cyberduck.core.onedrive.OneDriveSearchFeature.java

@Override
public AttributedList<Path> search(final Path workdir, final Filter<Path> regex,
        final ListProgressListener listener) throws BackgroundException {
    final AttributedList<Path> list = new AttributedList<>();
    // The query text used to search for items. Values may be matched across several fields including filename, metadata, and file content.
    final Iterator<OneDriveItem.Metadata> iterator = session.toFolder(workdir)
            .search(regex.toPattern().pattern()).iterator();
    while (iterator.hasNext()) {
        final OneDriveItem.Metadata metadata;
        try {//www.  j  a v a 2  s  . c  o  m
            metadata = iterator.next();
        } catch (OneDriveRuntimeException e) {
            log.warn(e);
            continue;
        }
        list.add(
                new Path(
                        String.format("/%s/%s/%s", metadata.getParentReference().getDriveId(),
                                StringUtils.removeStart(metadata.getParentReference().getPath(),
                                        "/drive/root:"),
                                metadata.getName()),
                        metadata.isFolder() ? EnumSet.of(Path.Type.directory) : EnumSet.of(Path.Type.file),
                        attributes.convert(metadata)));
    }
    return list;
}

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

@Override
public AttributedList<Path> list(final Path directory, final ListProgressListener listener)
        throws BackgroundException {
    if (log.isDebugEnabled()) {
        log.debug(String.format("List containers for %s", session));
    }/*w  w w  .  j  a  v a 2 s  .c  om*/
    try {
        if (session.getHost().getCredentials().isAnonymousLogin()) {
            // Listing all buckets not supported for thirdparty buckets
            if (StringUtils.isEmpty(this.getContainer(session.getHost()))) {
                if (StringUtils.isNotBlank(session.getHost().getDefaultPath())) {
                    if (containerService.isContainer(
                            new Path(session.getHost().getDefaultPath(), EnumSet.of(Path.Type.directory)))) {
                        final Path bucket = containerService.getContainer(
                                new Path(session.getHost().getDefaultPath(), EnumSet.of(Path.Type.directory)));
                        log.info(String.format("Using default %s path to determine bucket name %s",
                                session.getHost().getDefaultPath(), bucket));
                        final AttributedList<Path> buckets = new AttributedList<>(
                                Collections.singletonList(bucket));
                        listener.chunk(directory, buckets);
                        return buckets;
                    }
                }
                log.warn(String.format("No bucket name given in hostname %s", session.getHost().getHostname()));
                final Path bucket = new Path(session.getHost().getHostname(),
                        EnumSet.of(Path.Type.volume, Path.Type.directory));
                final AttributedList<Path> buckets = new AttributedList<>(Collections.singletonList(bucket));
                listener.chunk(directory, buckets);
                return buckets;
            } else {
                final Path bucket = new Path(this.getContainer(session.getHost()),
                        EnumSet.of(Path.Type.volume, Path.Type.directory));
                final AttributedList<Path> buckets = new AttributedList<>(Collections.singletonList(bucket));
                listener.chunk(directory, buckets);
                return buckets;
            }
        } else {
            // If bucket is specified in hostname, try to connect to this particular bucket only.
            final String bucketname = this.getContainer(session.getHost());
            if (StringUtils.isNotEmpty(bucketname)) {
                final Path bucket = new Path(bucketname, EnumSet.of(Path.Type.volume, Path.Type.directory));
                final AttributedList<Path> buckets = new AttributedList<>(Collections.singletonList(bucket));
                listener.chunk(directory, buckets);
                return buckets;
            } else {
                final AttributedList<Path> buckets = new AttributedList<Path>();
                // List all buckets owned
                for (StorageBucket b : session.getClient().listAllBuckets()) {
                    final Path bucket = new Path(b.getName(),
                            EnumSet.of(Path.Type.volume, Path.Type.directory));
                    if (b.getOwner() != null) {
                        // Null if the owner is not available
                        bucket.attributes().setOwner(b.getOwner().getId());
                    }
                    bucket.attributes().setCreationDate(b.getCreationDate().getTime());
                    if (b.isLocationKnown()) {
                        bucket.attributes().setRegion(b.getLocation());
                    }
                    if (region.getIdentifier() != null) {
                        final String location;
                        if (!b.isLocationKnown()) {
                            location = session.getFeature(Location.class).getLocation(bucket).getIdentifier();
                        } else {
                            location = b.getLocation();
                        }
                        if (!StringUtils.equals(location, region.getIdentifier())) {
                            log.warn(String.format("Skip bucket %s in region %s", bucket, location));
                            continue;
                        }
                        bucket.attributes().setRegion(location);
                    }
                    buckets.add(bucket);
                    listener.chunk(directory, buckets);
                }
                return buckets;
            }
        }
    } catch (ServiceException e) {
        throw new S3ExceptionMappingService().map("Listing directory {0} failed", e, directory);
    }
}

From source file:it.geosolutions.geonetwork.GeonetworkUpdateWithInfoTest.java

@Test
public void testUpdateMetadata() throws Exception {
    if (!runIntegrationTest())
        return;/* w ww . j a v a 2  s . c  o m*/

    GNInsertConfiguration cfg = createDefaultInsertConfiguration();

    GNPrivConfiguration pcfg = new GNPrivConfiguration();

    pcfg.addPrivileges(GNPrivConfiguration.GROUP_GUEST, EnumSet.of(GNPriv.FEATURED));
    pcfg.addPrivileges(GNPrivConfiguration.GROUP_INTRANET, EnumSet.of(GNPriv.DYNAMIC, GNPriv.FEATURED));
    pcfg.addPrivileges(GNPrivConfiguration.GROUP_ALL, EnumSet.of(GNPriv.VIEW, GNPriv.DYNAMIC, GNPriv.FEATURED));
    pcfg.addPrivileges(2, EnumSet.allOf(GNPriv.class));

    File file = loadFile("metadata.xml");
    assertNotNull(file);

    GNClient client = createClientAndLogin();
    long id = client.insertMetadata(cfg, file);

    client.setPrivileges(id, pcfg);

    //=== using the custom service
    MetadataInfo info = null;

    // first try: the service is installed?
    try {
        info = GNMetadataGetInfo.get(client.getConnection(), gnServiceURL, id, false);
        LOGGER.info("Basic metadataInfo by id is " + info);
        assertNotNull(info);
        assertNull(info.getVersion());
        assertEquals(id, info.getId());
    } catch (GNServerException ex) {
        if (ex.getHttpCode() == 404) {
            LOGGER.error("metadata.info.get is not installed on GeoNetwork. Skipping test.");
            assumeTrue(false);
        } else
            throw ex;
    }

    info = GNMetadataGetInfo.get(client.getConnection(), gnServiceURL, info.getUuid(), false);
    LOGGER.info("Basic metadataInfo by UUID is " + info);
    assertNotNull(info);
    assertNull(info.getVersion());
    assertEquals(id, info.getId());

    info = GNMetadataGetInfo.get(client.getConnection(), gnServiceURL, id, true);
    LOGGER.info("MetadataInfo is " + info);

    assertNotNull(info);
    assertEquals(Integer.valueOf(2), info.getVersion()); // the md has just been created
    assertEquals(id, info.getId());

    Element md = client.get(id);
    //        XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
    //        outputter.output(md, System.out);

    final String UPDATED_TEXT = "Updated title";
    {
        Element chstr = getTitleElement(md);
        assertEquals("TEST GeoBatch Action: GeoNetwork", chstr.getText());
        chstr.setText(UPDATED_TEXT);
    }

    File tempFile = File.createTempFile("gnm_info_update", ".xml");
    FileUtils.forceDeleteOnExit(tempFile);
    XMLOutputter fileOutputter = new XMLOutputter(Format.getCompactFormat());
    FileUtils.writeStringToFile(tempFile, fileOutputter.outputString(md));

    GNMetadataUpdate.update(client.getConnection(), gnServiceURL, id, Integer.toString(info.getVersion()),
            tempFile);

    {
        Element md2 = client.get(id);
        Element chstr = getTitleElement(md2);
        assertEquals(UPDATED_TEXT, chstr.getText());
    }

    info = GNMetadataGetInfo.get(client.getConnection(), gnServiceURL, id, true);
    //        String version3 = GNMetadataGetVersion.get(client.getConnection(), gnServiceURL, id);
    LOGGER.info("New MetadataInfo is " + info);

    assertNotNull(info.getVersion());
    assertEquals(Integer.valueOf(4), info.getVersion()); // the md has been updated once

    // try bad version number
    try {
        GNMetadataUpdate.update(client.getConnection(), gnServiceURL, id, "9999", tempFile);
        fail("Bad version exception not trapped");
    } catch (GNServerException e) {
        LOGGER.info("Bad version number error trapped properly (" + e.getMessage() + ")");
    }

    //        client.deleteMetadata(id);
}

From source file:com.cloudera.RenameTest.java

public static void testFileContextRename(URI uri) throws Exception {
    FileContext fc = FileContext.getFileContext(uri);
    Path testDir = new Path(new Path(uri), "testdir");
    System.out.println("mkdir " + testDir);
    fc.mkdir(testDir, new FsPermission((short) 0755), true);
    Path testFile = new Path(new Path(uri), "testfile");
    System.out.println("create " + testFile);
    FSDataOutputStream fos = fc.create(testFile, EnumSet.of(CREATE));
    fos.close();//from www  . j a v  a 2  s.  co  m
    System.out.println("rename " + testFile + " -> " + testDir);
    fc.rename(testFile, testDir);
}

From source file:ch.cyberduck.core.nio.LocalReadFeatureTest.java

@Test
public void testRead() throws Exception {
    final LocalSession session = new LocalSession(
            new Host(new LocalProtocol(), new LocalProtocol().getDefaultHostname()));
    session.open(new DisabledHostKeyCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final Path workdir = new LocalHomeFinderFeature(session).find();
    final Path test = new Path(workdir, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
    new LocalTouchFeature(session).touch(test, new TransferStatus());
    final int length = 39865;
    final byte[] content = RandomUtils.nextBytes(length);
    {//  w  w w  .j a  v a 2  s  . co m
        final TransferStatus status = new TransferStatus().length(content.length).exists(true);
        final OutputStream out = new LocalWriteFeature(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 LocalReadFeature(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 LocalDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
    session.close();
}

From source file:com.github.fge.jsonschema.syntax.checkers.draftv4.RequiredSyntaxChecker.java

@Override
protected void checkValue(final Collection<JsonPointer> pointers, final ProcessingReport report,
        final SchemaTree tree) throws ProcessingException {
    final JsonNode node = getNode(tree);
    final int size = node.size();

    if (size == 0) {
        report.error(newMsg(tree, "emptyArray"));
        return;// w ww  .ja  v  a2 s .c  om
    }

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

    boolean uniqueElements = true;
    JsonNode element;
    NodeType type;

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

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