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.openstack.SwiftSegmentService.java

public Path getSegment(final Path file, final Long size, int segmentNumber) {
    return new Path(this.getSegmentsDirectory(file, size), String.format("%08d", segmentNumber),
            EnumSet.of(Path.Type.file));
}

From source file:com.amazonaws.codepipeline.jenkinsplugin.CompressionTools.java

public static List<File> addFilesToCompress(final Path pathToCompress, final BuildListener listener)
        throws IOException {
    final List<File> files = new ArrayList<>();

    if (pathToCompress != null) {
        Files.walkFileTree(pathToCompress, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE,
                new SimpleFileVisitor<Path>() {
                    @Override/*w w w .ja  v a  2s .  co  m*/
                    public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs)
                            throws IOException {
                        files.add(file.toFile());
                        return FileVisitResult.CONTINUE;
                    }

                    @Override
                    public FileVisitResult visitFileFailed(final Path file, final IOException e)
                            throws IOException {
                        if (e != null) {
                            LoggingHelper.log(listener, "Failed to visit file '%s'. Error: %s.",
                                    file.toString(), e.getMessage());
                            LoggingHelper.log(listener, e);
                            throw e;
                        }
                        return FileVisitResult.CONTINUE;
                    }
                });
    }

    return files;
}

From source file:fr.xebia.extras.selma.codegen.CustomMapperWrapper.java

void emitCustomMappersFields(JavaWriter writer, boolean assign) throws IOException {
    for (TypeElement customMapperField : customMapperFields) {
        final String field = String.format(CUSTOM_MAPPER_FIELD_TPL,
                customMapperField.getSimpleName().toString());
        if (assign) {
            if (customMapperField.getKind() != ElementKind.INTERFACE
                    && !(customMapperField.getKind() == ElementKind.CLASS
                            && customMapperField.getModifiers().contains(ABSTRACT))) {
                TypeConstructorWrapper constructorWrapper = new TypeConstructorWrapper(context,
                        customMapperField);
                // assign the customMapper field to a newly created instance passing to it the declared source params
                writer.emitStatement("this.%s = new %s(%s)", field,
                        customMapperField.getQualifiedName().toString(),
                        constructorWrapper.hasMatchingSourcesConstructor ? context.newParams() : "");
            }//from w  ww. java 2  s  .  c  o  m
        } else {
            writer.emitEmptyLine();
            writer.emitJavadoc("This field is used for custom Mapping");
            if (ioC == IoC.SPRING) {
                writer.emitAnnotation("org.springframework.beans.factory.annotation.Autowired");
            }
            writer.emitField(customMapperField.asType().toString(),
                    String.format(CUSTOM_MAPPER_FIELD_TPL, customMapperField.getSimpleName().toString()),
                    EnumSet.of(PRIVATE));

            writer.emitEmptyLine();
            writer.emitJavadoc("Custom Mapper setter for " + field);

            EnumSet<Modifier> modifiers = EnumSet.of(PUBLIC, FINAL);
            if (ioC == IoC.CDI) {
                modifiers = EnumSet.of(PUBLIC);
            }
            writer.beginMethod("void", "setCustomMapper" + customMapperField.getSimpleName(), modifiers,
                    customMapperField.asType().toString(), "mapper");
            writer.emitStatement("this.%s = mapper", field);
            writer.endMethod();
            writer.emitEmptyLine();
        }
    }
}

From source file:ch.cyberduck.core.Archive.java

/**
 * @param files Files/* w ww. java 2 s  . c  o  m*/
 * @return Archived path for files
 */
public Path getArchive(final List<Path> files) {
    if (files.size() == 0) {
        return null;
    }
    if (files.size() == 1) {
        return new Path(files.get(0).getParent(),
                String.format("%s.%s", files.get(0).getName(), this.getIdentifier()),
                EnumSet.of(Path.Type.file));
    }
    return new Path(files.get(0).getParent(),
            String.format("%s.%s", LocaleFactory.localizedString("Archive", "Archive"), this.getIdentifier()),
            EnumSet.of(Path.Type.file));
}

From source file:ch.cyberduck.core.sftp.SFTPReadFeatureTest.java

@Test
public void testReadRange() 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 Path home = new SFTPHomeDirectoryService(session).find();
    final Path test = new Path(home, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
    new SFTPTouchFeature(session).touch(test, new TransferStatus());
    final int length = 1048576;
    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);
        final OutputStream out = new SFTPWriteFeature(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);
        status.setAppend(true);
        status.setOffset(100L);
        final InputStream in = new SFTPReadFeature(session).read(test, status,
                new DisabledConnectionCallback());
        assertNotNull(in);
        final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length - 100);
        new StreamCopier(status, status).withLimit(new Long(content.length - 100)).transfer(in, buffer);
        in.close();
        final byte[] reference = new byte[content.length - 100];
        System.arraycopy(content, 100, reference, 0, content.length - 100);
        assertArrayEquals(reference, buffer.toByteArray());
    }
    new SFTPDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
    session.close();
}

From source file:com.dm.estore.config.WebAppInitializer.java

private void registerFilters(ServletContext servletContext) {
    FilterRegistration.Dynamic securityFilter = servletContext.addFilter(SECURITY_FILTER_NAME,
            new DelegatingFilterProxy());
    securityFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, REST_SERVLET_MAPPING);
    securityFilter.setAsyncSupported(true);

    FilterRegistration.Dynamic applicationFilter = servletContext.addFilter(APP_FILTER_NAME,
            new ApplicationFilter());
    applicationFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD),
            false, APP_FILTER_MAPPING);/*from   w w  w .j  a  va2s  . c om*/
    applicationFilter.setAsyncSupported(true);
}

From source file:de.ingrid.interfaces.csw.cache.AbstractFileCache.java

/**
 * Get document ids from a directory and all sub directories
 * /*from w w w . j a  va 2 s .  c o  m*/
 * @param directory
 *            The start directory
 * @return Set
 */
protected Set<Serializable> getDocumentIds(File directory) {
    Set<Serializable> documentIds = new HashSet<Serializable>();

    EnumSet<FileVisitOption> opts = EnumSet.of(FileVisitOption.FOLLOW_LINKS);
    CacheFileLister cfl = new CacheFileLister(documentIds);
    try {
        Files.walkFileTree(directory.toPath(), opts, Integer.MAX_VALUE, cfl);
    } catch (IOException e) {
        log.error("Error getting document IDs from cache.");
    }

    return documentIds;
}

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

/**
 * Create file/folder with Cryptomator, read with Cyberduck
 *//*w  ww.  j a  v  a 2  s . co m*/
@Test
public void testCryptomatorInteroperabilityTests() throws Exception {
    // create folder
    final java.nio.file.Path targetFolder = cryptoFileSystem.getPath("/",
            new AlphanumericRandomStringService().random());
    Files.createDirectory(targetFolder);
    // create file and write some random content
    java.nio.file.Path targetFile = targetFolder
            .resolve(new RandomStringGenerator.Builder().build().generate(100));
    final byte[] content = RandomUtils.nextBytes(48768);
    Files.write(targetFile, content);

    // read with Cyberduck and compare
    final Host host = new Host(new SFTPProtocol(), "localhost", PORT_NUMBER, new Credentials("empty", "empty"));
    final SFTPSession session = new SFTPSession(host);
    session.open(new DisabledHostKeyCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final Path home = new SFTPHomeDirectoryService(session).find();
    final Path vault = new Path(home, "vault", EnumSet.of(Path.Type.directory));
    final CryptoVault cryptomator = new CryptoVault(vault, new DisabledPasswordStore()).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(passphrase);
                }
            });
    session.withRegistry(
            new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
    Path p = new Path(new Path(vault, targetFolder.getFileName().toString(), EnumSet.of(Path.Type.directory)),
            targetFile.getFileName().toString(), EnumSet.of(Path.Type.file));
    final InputStream read = new CryptoReadFeature(session, new SFTPReadFeature(session), cryptomator).read(p,
            new TransferStatus(), new DisabledConnectionCallback());
    final byte[] readContent = new byte[content.length];
    IOUtils.readFully(read, readContent);
    assertArrayEquals(content, readContent);
    session.close();
}

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

@Test
public void testUploadDirectoryServerRoot() throws Exception {
    final CommandLineParser parser = new PosixParser();
    final CommandLine input = parser.parse(TerminalOptionsBuilder.options(),
            new String[] { "--upload", "ftps://test.cyberduck.ch/", System.getProperty("java.io.tmpdir") });

    final Set<TransferItem> found = new SingleTransferItemFinder().find(input, TerminalAction.upload,
            new Path("/", EnumSet.of(Path.Type.directory)));
    assertFalse(found.isEmpty());/* w ww .ja v  a  2 s .  com*/
    final Iterator<TransferItem> iter = found.iterator();
    final Local temp = LocalFactory.get(System.getProperty("java.io.tmpdir"));
    assertTrue(temp.getType().contains(Path.Type.directory));
    assertEquals(new TransferItem(new Path("/", EnumSet.of(Path.Type.directory)), temp), iter.next());
}

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

@Test(expected = NotfoundException.class)
public void testReadInvalidRange() throws Exception {
    final Path drive = new OneDriveHomeFinderFeature(session).find();
    final Path test = new Path(drive, new AlphanumericRandomStringService().random(),
            EnumSet.of(Path.Type.file));
    new OneDriveTouchFeature(session).touch(test, new TransferStatus());
    final OneDriveReadFeature read = new OneDriveReadFeature(session);
    final InputStream in = read.read(test, new TransferStatus().skip(1).append(true),
            new DisabledConnectionCallback());
    assertNull(in);// w  ww.j a  v  a2  s. c om
}