List of usage examples for java.util EnumSet of
public static <E extends Enum<E>> EnumSet<E> of(E e)
From source file:ch.cyberduck.core.cryptomator.DAVReadFeatureTest.java
@Test public void testReadRange() 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 TransferStatus status = new TransferStatus(); final int length = 140000; final byte[] content = RandomUtils.nextBytes(length); status.setLength(content.length);//from w w w . java 2s . 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<>(session, new DAVWriteFeature(session), cryptomator); final Cryptor cryptor = cryptomator.getCryptor(); final FileHeader header = cryptor.fileHeaderCryptor().create(); status.setHeader(cryptor.fileHeaderCryptor().encryptHeader(header)); status.setNonces(new RandomNonceGenerator()); 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 DAVFindFeature(session), cryptomator).find(test)); Assert.assertEquals(content.length, new CryptoListService(session, session, cryptomator) .list(test.getParent(), new DisabledListProgressListener()).get(test).attributes().getSize()); Assert.assertEquals(content.length, writer.append(test, status.getLength(), PathCache.empty()).size, 0L); { final ByteArrayOutputStream buffer = new ByteArrayOutputStream(40000); final TransferStatus read = new TransferStatus(); read.setOffset(23); // offset within chunk read.setAppend(true); read.length(40000); // ensure to read at least two chunks final InputStream in = new CryptoReadFeature(session, new DAVReadFeature(session), cryptomator) .read(test, read, new DisabledConnectionCallback()); new StreamCopier(read, read).withLimit(40000L).transfer(in, buffer); final byte[] reference = new byte[40000]; System.arraycopy(content, 23, reference, 0, reference.length); assertArrayEquals(reference, buffer.toByteArray()); } { final ByteArrayOutputStream buffer = new ByteArrayOutputStream(40000); final TransferStatus read = new TransferStatus(); read.setOffset(65536); // offset at the beginning of a new chunk read.setAppend(true); read.length(40000); // ensure to read at least two chunks final InputStream in = new CryptoReadFeature(session, new DAVReadFeature(session), cryptomator) .read(test, read, new DisabledConnectionCallback()); new StreamCopier(read, read).withLimit(40000L).transfer(in, buffer); final byte[] reference = new byte[40000]; System.arraycopy(content, 65536, reference, 0, reference.length); assertArrayEquals(reference, buffer.toByteArray()); } { final ByteArrayOutputStream buffer = new ByteArrayOutputStream(40000); final TransferStatus read = new TransferStatus(); read.setOffset(65537); // offset at the beginning+1 of a new chunk read.setAppend(true); read.length(40000); // ensure to read at least two chunks final InputStream in = new CryptoReadFeature(session, new DAVReadFeature(session), cryptomator) .read(test, read, new DisabledConnectionCallback()); new StreamCopier(read, read).withLimit(40000L).transfer(in, buffer); final byte[] reference = new byte[40000]; System.arraycopy(content, 65537, reference, 0, reference.length); assertArrayEquals(reference, buffer.toByteArray()); } new CryptoDeleteFeature(session, new DAVDeleteFeature(session), cryptomator) .delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
From source file:ch.cyberduck.core.ftp.FTPMlsdListResponseReader.java
@Override public AttributedList<Path> read(final Path directory, final List<String> replies, final ListProgressListener listener) throws IOException, FTPInvalidListException, ConnectionCanceledException { final AttributedList<Path> children = new AttributedList<Path>(); // At least one entry successfully parsed boolean success = false; for (String line : replies) { final Map<String, Map<String, String>> file = this.parseFacts(line); if (null == file) { log.error(String.format("Error parsing line %s", line)); continue; }//from ww w . j a v a2 s.c o m for (Map.Entry<String, Map<String, String>> f : file.entrySet()) { final String name = f.getKey(); // size -- Size in octets // modify -- Last modification time // create -- Creation time // type -- Entry type // unique -- Unique id of file/directory // perm -- File permissions, whether read, write, execute is allowed for the login id. // lang -- Language of the file name per IANA [11] registry. // media-type -- MIME media-type of file contents per IANA registry. // charset -- Character set per IANA registry (if not UTF-8) final Map<String, String> facts = f.getValue(); if (!facts.containsKey("type")) { log.error(String.format("No type fact in line %s", line)); continue; } final Path parsed; if ("dir".equals(facts.get("type").toLowerCase(Locale.ROOT))) { parsed = new Path(directory, PathNormalizer.name(f.getKey()), EnumSet.of(Path.Type.directory)); } else if ("file".equals(facts.get("type").toLowerCase(Locale.ROOT))) { parsed = new Path(directory, PathNormalizer.name(f.getKey()), EnumSet.of(Path.Type.file)); } else if (facts.get("type").toLowerCase(Locale.ROOT).matches("os\\.unix=slink:.*")) { parsed = new Path(directory, PathNormalizer.name(f.getKey()), EnumSet.of(Path.Type.file, Path.Type.symboliclink)); // Parse symbolic link target in Type=OS.unix=slink:/foobar;Perm=;Unique=keVO1+4G4; foobar final String[] type = facts.get("type").split(":"); if (type.length == 2) { final String target = type[1]; if (target.startsWith(String.valueOf(Path.DELIMITER))) { parsed.setSymlinkTarget(new Path(target, EnumSet.of(Path.Type.file))); } else { parsed.setSymlinkTarget( new Path(String.format("%s/%s", directory.getAbsolute(), target), EnumSet.of(Path.Type.file))); } } else { log.warn(String.format("Missing symbolic link target for type %s in line %s", facts.get("type"), line)); continue; } } else { log.warn(String.format("Ignored type %s in line %s", facts.get("type"), line)); continue; } if (!success) { if (parsed.isDirectory() && directory.getName().equals(name)) { log.warn(String.format("Possibly bogus response line %s", line)); } else { success = true; } } if (name.equals(".") || name.equals("..")) { if (log.isDebugEnabled()) { log.debug(String.format("Skip %s", name)); } continue; } if (facts.containsKey("size")) { parsed.attributes().setSize(Long.parseLong(facts.get("size"))); } if (facts.containsKey("unix.uid")) { parsed.attributes().setOwner(facts.get("unix.uid")); } if (facts.containsKey("unix.owner")) { parsed.attributes().setOwner(facts.get("unix.owner")); } if (facts.containsKey("unix.gid")) { parsed.attributes().setGroup(facts.get("unix.gid")); } if (facts.containsKey("unix.group")) { parsed.attributes().setGroup(facts.get("unix.group")); } if (facts.containsKey("unix.mode")) { parsed.attributes().setPermission(new Permission(facts.get("unix.mode"))); } else if (facts.containsKey("perm")) { Permission.Action user = Permission.Action.none; final String flags = facts.get("perm"); if (StringUtils.contains(flags, 'r') || StringUtils.contains(flags, 'l')) { // RETR command may be applied to that object // Listing commands, LIST, NLST, and MLSD may be applied user.or(Permission.Action.read); } if (StringUtils.contains(flags, 'w') || StringUtils.contains(flags, 'm') || StringUtils.contains(flags, 'c')) { user.or(Permission.Action.write); } if (StringUtils.contains(flags, 'e')) { // CWD command naming the object should succeed user.or(Permission.Action.execute); } final Permission permission = new Permission(user, Permission.Action.none, Permission.Action.none); parsed.attributes().setPermission(permission); } if (facts.containsKey("modify")) { // Time values are always represented in UTC parsed.attributes().setModificationDate(this.parseTimestamp(facts.get("modify"))); } if (facts.containsKey("create")) { // Time values are always represented in UTC parsed.attributes().setCreationDate(this.parseTimestamp(facts.get("create"))); } children.add(parsed); } } if (!success) { throw new FTPInvalidListException(children); } return children; }
From source file:ch.cyberduck.core.dav.DAVListService.java
@Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { try {// w w w . j a va2 s . co m final AttributedList<Path> children = new AttributedList<Path>(); final List<DavResource> resources = session.getClient().list(new DAVPathEncoder().encode(directory), 1, Collections.<QName>emptySet()); for (final DavResource resource : resources) { // Try to parse as RFC 2396 final String href = PathNormalizer.normalize(resource.getHref().getPath(), true); if (href.equals(directory.getAbsolute())) { log.warn(String.format("Ignore resource %s", href)); // Do not include self if (resource.isDirectory()) { continue; } throw new NotfoundException(directory.getAbsolute()); } final PathAttributes attributes = new PathAttributes(); if (resource.getModified() != null) { attributes.setModificationDate(resource.getModified().getTime()); } if (resource.getCreation() != null) { attributes.setCreationDate(resource.getCreation().getTime()); } if (resource.getContentLength() != null) { attributes.setSize(resource.getContentLength()); } if (StringUtils.isNotBlank(resource.getEtag())) { attributes.setETag(resource.getEtag()); // Setting checksum is disabled. See #8798 // attributes.setChecksum(Checksum.parse(resource.getEtag())); } if (StringUtils.isNotBlank(resource.getDisplayName())) { attributes.setDisplayname(resource.getDisplayName()); } final Path file = new Path(directory, PathNormalizer.name(href), resource.isDirectory() ? EnumSet.of(Path.Type.directory) : EnumSet.of(Path.Type.file), attributes); children.add(file); listener.chunk(directory, children); } return children; } catch (SardineException e) { throw new DAVExceptionMappingService().map("Listing directory {0} failed", e, directory); } catch (IOException e) { throw new HttpExceptionMappingService().map(e, directory); } }
From source file:ch.cyberduck.core.openstack.SwiftSegmentService.java
public List<Path> list(final Path file) throws BackgroundException { try {/*from w w w .java2 s . c om*/ final Path container = containerService.getContainer(file); final Map<String, List<StorageObject>> segments = session.getClient().listObjectSegments( regionService.lookup(container), container.getName(), containerService.getKey(file)); if (null == segments) { // Not a large object return Collections.emptyList(); } final List<Path> objects = new ArrayList<Path>(); if (segments.containsKey(container.getName())) { for (StorageObject s : segments.get(container.getName())) { final Path segment = new Path(container, s.getName(), EnumSet.of(Path.Type.file)); segment.attributes().setSize(s.getSize()); try { segment.attributes().setModificationDate(dateParser.parse(s.getLastModified()).getTime()); } catch (InvalidDateException e) { log.warn( String.format("%s is not ISO 8601 format %s", s.getLastModified(), e.getMessage())); } if (StringUtils.isNotBlank(s.getMd5sum())) { segment.attributes().setChecksum(Checksum.parse(s.getMd5sum())); } objects.add(segment); } } return objects; } catch (GenericException e) { throw new SwiftExceptionMappingService().map("Failure to read attributes of {0}", e, file); } catch (IOException e) { throw new DefaultIOExceptionMappingService().map("Failure to read attributes of {0}", e, file); } }
From source file:ch.cyberduck.core.cryptomator.DAVWriteFeatureTest.java
@Test public void testWrite() 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 TransferStatus status = new TransferStatus(); final int length = 1048576; final byte[] content = RandomUtils.nextBytes(length); status.setLength(content.length);/*from w w w. ja v a 2 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 DAVWriteFeature(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 DAVFindFeature(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 DAVWriteFeature(session, new DefaultFindFeature(session), new DefaultAttributesFinderFeature(session), true), cryptomator).append(test, status.getLength(), PathCache.empty()).size, 0L); assertEquals(content.length, new CryptoWriteFeature<>(session, new DAVWriteFeature(session, new DAVFindFeature(session), new DAVAttributesFinderFeature(session), true), cryptomator).append(test, status.getLength(), PathCache.empty()).size, 0L); final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length); final InputStream in = new CryptoReadFeature(session, new DAVReadFeature(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 DAVDeleteFeature(session), cryptomator) .delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
From source file:ch.cyberduck.cli.SingleTransferItemFinderTest.java
@Test public void testDeferUploadNameFromLocal() throws Exception { final CommandLineParser parser = new PosixParser(); final String temp = System.getProperty("java.io.tmpdir"); final CommandLine input = parser.parse(TerminalOptionsBuilder.options(), new String[] { "--upload", "ftps://test.cyberduck.ch/remote/", String.format("%s/f", temp) }); final Set<TransferItem> found = new SingleTransferItemFinder().find(input, TerminalAction.upload, new Path("/remote/", EnumSet.of(Path.Type.directory))); assertFalse(found.isEmpty());//from w ww. ja va 2s. c om assertEquals(new TransferItem(new Path("/remote/f", EnumSet.of(Path.Type.file)), LocalFactory.get(String.format("%s/f", temp))), found.iterator().next()); }
From source file:ch.cyberduck.core.manta.MantaReadFeatureTest.java
@Test public void testReadRange() 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()); final Local local = new Local(System.getProperty("java.io.tmpdir"), new AlphanumericRandomStringService().random()); final int BYTES_TOTAL = 10;//00; final int BYTES_OFFSET = 1;//00; final byte[] content = RandomUtils.nextBytes(BYTES_TOTAL); final OutputStream out = local.getOutputStream(false); assertNotNull(out);/*from w w w . j a va2 s . c o m*/ IOUtils.write(content, out); out.close(); new DefaultUploadFeature<Void>(new MantaWriteFeature(session)).upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), new TransferStatus().length(content.length), new DisabledConnectionCallback()); final TransferStatus status = new TransferStatus(); status.setLength(content.length); status.setAppend(true); status.setOffset(BYTES_OFFSET); final MantaReadFeature read = new MantaReadFeature(session); assertTrue(read.offset(test)); final InputStream in = read.read(test, status.length(content.length - BYTES_OFFSET), new DisabledConnectionCallback()); assertNotNull(in); final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length - BYTES_OFFSET); new StreamCopier(status, status).transfer(in, buffer); final byte[] reference = new byte[content.length - BYTES_OFFSET]; System.arraycopy(content, BYTES_OFFSET, reference, 0, content.length - BYTES_OFFSET); assertArrayEquals(reference, buffer.toByteArray()); in.close(); new MantaDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); }
From source file:com.netflix.simianarmy.aws.janitor.crawler.ASGJanitorCrawler.java
@Override public EnumSet<? extends ResourceType> resourceTypes() { return EnumSet.of(AWSResourceType.ASG); }
From source file:com.neurotec.samples.panels.EnrollFromScanner.java
public EnrollFromScanner() { super();/* w w w . j a v a 2 s . c o m*/ requiredLicenses = new ArrayList<String>(); requiredLicenses.add("Biometrics.FingerExtraction"); requiredLicenses.add("Biometrics.FingerMatchingFast"); requiredLicenses.add("Biometrics.FingerMatching"); requiredLicenses.add("Biometrics.FingerQualityAssessment"); requiredLicenses.add("Biometrics.FingerSegmentation"); requiredLicenses.add("Biometrics.FingerSegmentsDetection"); requiredLicenses.add("Biometrics.Standards.Fingers"); requiredLicenses.add("Biometrics.Standards.FingerTemplates"); requiredLicenses.add("Devices.FingerScanners"); optionalLicenses = new ArrayList<String>(); optionalLicenses.add("Images.WSQ"); FingersTools.getInstance().getClient().setUseDeviceManager(true); deviceManager = FingersTools.getInstance().getClient().getDeviceManager(); deviceManager.setDeviceTypes(EnumSet.of(NDeviceType.FINGER_SCANNER)); deviceManager.initialize(); }
From source file:edu.uci.ics.pregelix.core.util.PregelixHyracksIntegrationUtil.java
public static void runJob(JobSpecification spec, String appName) throws Exception { spec.setFrameSize(FRAME_SIZE);/* w w w . j a va 2 s. c o m*/ spec.setReportTaskDetails(false); JobId jobId = hcc.startJob(spec, EnumSet.of(JobFlag.PROFILE_RUNTIME)); hcc.waitForCompletion(jobId); }