List of usage examples for java.util EnumSet of
@SafeVarargs public static <E extends Enum<E>> EnumSet<E> of(E first, E... rest)
From source file:ch.cyberduck.core.cryptomator.SwiftTouchFeatureTest.java
@Test public void testTouchLongFilenameEncrypted() throws Exception { final Host host = new Host(new SwiftProtocol(), "identity.api.rackspacecloud.com", new Credentials(System.getProperties().getProperty("rackspace.key"), System.getProperties().getProperty("rackspace.secret"))); final SwiftSession session = new SwiftSession(host); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final Path home = new Path("/test.cyberduck.ch", EnumSet.of(Path.Type.volume, Path.Type.directory)); 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 . j a va 2 s . c o m*/ new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator)); final SwiftRegionService regionService = new SwiftRegionService(session); new CryptoTouchFeature<StorageObject>(session, new SwiftTouchFeature(session, regionService), new SwiftWriteFeature(session, regionService), cryptomator).touch(test, new TransferStatus()); assertTrue(new CryptoFindFeature(session, new SwiftFindFeature(session), cryptomator).find(test)); new CryptoDeleteFeature(session, new SwiftDeleteFeature(session), cryptomator) .delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
From source file:ch.cyberduck.core.sds.SDSDelegatingCopyFeatureTest.java
@Test public void testCopyFileServerSide() throws Exception { final Host host = new Host(new SDSProtocol(), "duck.ssp-europe.eu", new Credentials( System.getProperties().getProperty("sds.user"), System.getProperties().getProperty("sds.key"))); final SDSSession session = new SDSSession(host, new DisabledX509TrustManager(), new DefaultX509KeyManager()); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final Path room = new SDSDirectoryFeature(session) .mkdir(new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory, Path.Type.volume)), null, new TransferStatus()); final Path test = new SDSTouchFeature(session).touch( new Path(room, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus()); final Path copy = new Path(new SDSDirectoryFeature(session).mkdir( new Path(room, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), null, new TransferStatus()), test.getName(), EnumSet.of(Path.Type.file)); new SDSTouchFeature(session).touch(copy, new TransferStatus()); final SDSCopyFeature feature = new SDSCopyFeature(session); assertTrue(feature.isSupported(test, copy)); new SDSDelegatingCopyFeature(session, feature).copy(test, copy, new TransferStatus(), new DisabledConnectionCallback()); assertTrue(new SDSFindFeature(session).find(test)); assertTrue(new SDSFindFeature(session).find(copy)); new SDSDeleteFeature(session).delete(Collections.singletonList(room), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close();/*from ww w . jav a2 s. c o m*/ }
From source file:ch.cyberduck.core.cryptomator.B2LargeUploadWriteFeatureTest.java
@Test public void testWrite() 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 Path container = new Path("test-cyberduck", EnumSet.of(Path.Type.volume, Path.Type.directory)); final CryptoVault cryptomator = new CryptoVault(new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), new DisabledPasswordStore()); final Path vault = cryptomator.create(session, null, new VaultCredentials("test")); session.withRegistry(//from w w w. j a v a2s . c o m new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator)); final CryptoWriteFeature feature = new CryptoWriteFeature<VersionId>(session, new B2LargeUploadWriteFeature(session), cryptomator); final TransferStatus writeStatus = new TransferStatus(); final Cryptor cryptor = cryptomator.getCryptor(); final FileHeader header = cryptor.fileHeaderCryptor().create(); writeStatus.setHeader(cryptor.fileHeaderCryptor().encryptHeader(header)); writeStatus.setNonces(new RandomNonceGenerator()); writeStatus.setLength(-1L); final Path test = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)); final OutputStream out = feature.write(test, writeStatus, new DisabledConnectionCallback()); final byte[] content = RandomUtils.nextBytes(6 * 1024 * 1024); final ByteArrayInputStream in = new ByteArrayInputStream(content); final TransferStatus progress = new TransferStatus(); new StreamCopier(new TransferStatus(), progress).transfer(in, out); assertEquals(content.length, progress.getOffset()); assertTrue(new CryptoFindFeature(session, new B2FindFeature(session), cryptomator).find(test)); final byte[] compare = new byte[content.length]; final InputStream stream = new CryptoReadFeature(session, new B2ReadFeature(session), cryptomator) .read(test, new TransferStatus().length(content.length), new DisabledConnectionCallback()); IOUtils.readFully(stream, compare); stream.close(); assertArrayEquals(content, compare); new CryptoDeleteFeature(session, new B2DeleteFeature(session), cryptomator) .delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
From source file:com.github.fge.jsonschema.syntax.checkers.helpers.DraftV3TypeKeywordSyntaxChecker.java
@Override protected void checkValue(final Collection<JsonPointer> pointers, final ProcessingReport report, final SchemaTree tree) throws ProcessingException { final JsonNode node = tree.getNode().get(keyword); if (node.isTextual()) { if (!typeIsValid(node.textValue())) report.error(newMsg(tree, "incorrectPrimitiveType").put("valid", EnumSet.allOf(NodeType.class)) .put("found", node)); return;/*from www. ja va 2 s . c o m*/ } final int size = node.size(); final Set<Equivalence.Wrapper<JsonNode>> set = Sets.newHashSet(); JsonNode element; NodeType type; boolean uniqueItems = true; for (int index = 0; index < size; index++) { element = node.get(index); type = NodeType.getNodeType(element); uniqueItems = set.add(EQUIVALENCE.wrap(element)); if (type == OBJECT) { pointers.add(JsonPointer.of(keyword, index)); continue; } if (type != STRING) { report.error(newMsg(tree, "incorrectElementType").put("index", index) .put("expected", EnumSet.of(OBJECT, STRING)).put("found", type)); continue; } if (!typeIsValid(element.textValue())) report.error(newMsg(tree, "incorrectPrimitiveType").put("index", index) .put("valid", EnumSet.allOf(NodeType.class)).put("found", element)); } if (!uniqueItems) report.error(newMsg(tree, "elementsNotUnique")); }
From source file:ch.cyberduck.core.spectra.SpectraReadFeatureTest.java
@Test(expected = NotfoundException.class) public void testReadNotFound() throws Exception { final Host host = new Host(new SpectraProtocol() { @Override/*www .jav a 2 s .c om*/ 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 TransferStatus status = new TransferStatus(); final Path container = new Path("cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume)); final Path test = new Path(container, "nosuchname", EnumSet.of(Path.Type.file)); new SpectraBulkService(session).pre(Transfer.Type.download, Collections.singletonMap(test, status), new DisabledConnectionCallback()); new SpectraReadFeature(session).read(test, status, new DisabledConnectionCallback()); }
From source file:ch.cyberduck.core.sds.SDSDelegatingMoveFeatureTest.java
@Test public void testMove() throws Exception { final Host host = new Host(new SDSProtocol(), "duck.ssp-europe.eu", new Credentials( System.getProperties().getProperty("sds.user"), System.getProperties().getProperty("sds.key"))); final SDSSession session = new SDSSession(host, new DisabledX509TrustManager(), new DefaultX509KeyManager()); session.enableMetrics();//w w w. ja va 2 s .c o m session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final Path room = new SDSDirectoryFeature(session) .mkdir(new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory, Path.Type.volume)), null, new TransferStatus()); final Path test = new Path(room, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)); new SDSTouchFeature(session).touch(test, new TransferStatus()); final Path target = new Path(room, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)); new SDSDelegatingMoveFeature(session, new SDSMoveFeature(session)).move(test, target, new TransferStatus(), new Delete.DisabledCallback(), new DisabledConnectionCallback()); assertFalse(new SDSFindFeature(session).find(test)); assertTrue(new SDSFindFeature(session).find(target)); assertEquals(0, session.getMetrics().get(Copy.class)); new SDSDeleteFeature(session).delete(Collections.singletonList(room), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
From source file:ch.cyberduck.core.cryptomator.S3MultipartWriteFeatureTest.java
@Test public void testWrite() throws Exception { final S3Session session = new S3Session(new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(), new Credentials(System.getProperties().getProperty("s3.key"), System.getProperties().getProperty("s3.secret")))); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final Path home = new Path("test-eu-central-1-cyberduck", EnumSet.of(Path.Type.volume, Path.Type.directory)); 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(/* w w w.jav a 2s . com*/ new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator)); final CryptoWriteFeature feature = new CryptoWriteFeature<List<MultipartPart>>(session, new S3MultipartWriteFeature(session), cryptomator); final byte[] content = RandomUtils.nextBytes(6 * 1024 * 1024); final TransferStatus writeStatus = new TransferStatus(); final Cryptor cryptor = cryptomator.getCryptor(); final FileHeader header = cryptor.fileHeaderCryptor().create(); writeStatus.setHeader(cryptor.fileHeaderCryptor().encryptHeader(header)); writeStatus.setNonces(new RandomNonceGenerator()); writeStatus.setLength(-1L); final StatusOutputStream out = feature.write(test, writeStatus, new DisabledConnectionCallback()); final ByteArrayInputStream in = new ByteArrayInputStream(content); final TransferStatus progress = new TransferStatus(); new StreamCopier(new TransferStatus(), progress).transfer(in, out); assertEquals(content.length, progress.getOffset()); assertNotNull(out.getStatus()); assertTrue(new CryptoFindFeature(session, new S3FindFeature(session), cryptomator).find(test)); final byte[] compare = new byte[content.length]; final InputStream stream = new CryptoReadFeature(session, new S3ReadFeature(session), cryptomator) .read(test, new TransferStatus().length(content.length), new DisabledConnectionCallback()); IOUtils.readFully(stream, compare); stream.close(); assertArrayEquals(content, compare); new CryptoDeleteFeature(session, new S3DefaultDeleteFeature(session), cryptomator) .delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
From source file:io.druid.query.groupby.epinephelinae.LimitedTemporaryStorage.java
/** * Create a new temporary file. All methods of the returned output stream may throw * {@link TemporaryStorageFullException} if the temporary storage area fills up. * * @return output stream to the file// w w w.j a v a 2 s. co m * * @throws TemporaryStorageFullException if the temporary storage area is full * @throws IOException if something goes wrong while creating the file */ public LimitedOutputStream createFile() throws IOException { if (bytesUsed.get() >= maxBytesUsed) { throw new TemporaryStorageFullException(maxBytesUsed); } synchronized (files) { if (closed) { throw new ISE("Closed"); } FileUtils.forceMkdir(storageDirectory); final File theFile = new File(storageDirectory, StringUtils.format("%08d.tmp", files.size())); final EnumSet<StandardOpenOption> openOptions = EnumSet.of(StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE); final FileChannel channel = FileChannel.open(theFile.toPath(), openOptions); files.add(theFile); return new LimitedOutputStream(theFile, Channels.newOutputStream(channel)); } }
From source file:ch.cyberduck.core.spectra.SpectraUploadFeatureTest.java
@Test public void testUpload() throws Exception { final Host host = new Host(new SpectraProtocol() { @Override/* ww w . java 2 s .c o 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 Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString()); final int length = 32770; final byte[] content = RandomUtils.nextBytes(length); final OutputStream out = local.getOutputStream(false); IOUtils.write(content, out); out.close(); final Path container = new Path("cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume)); final Path test = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); final TransferStatus writeStatus = new TransferStatus().length(content.length); final SpectraBulkService bulk = new SpectraBulkService(session); bulk.pre(Transfer.Type.upload, Collections.singletonMap(test, writeStatus), new DisabledConnectionCallback()); final SpectraUploadFeature upload = new SpectraUploadFeature(new SpectraWriteFeature(session), new SpectraBulkService(session)); upload.upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), writeStatus, new DisabledConnectionCallback()); final byte[] buffer = new byte[content.length]; final TransferStatus readStatus = new TransferStatus().length(content.length); bulk.pre(Transfer.Type.download, Collections.singletonMap(test, readStatus), new DisabledConnectionCallback()); final InputStream in = new SpectraReadFeature(session).read(test, readStatus, new DisabledConnectionCallback()); IOUtils.readFully(in, buffer); in.close(); assertArrayEquals(content, buffer); new SpectraDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); local.delete(); session.close(); }
From source file:com.github.fge.jsonschema.core.keyword.syntax.checkers.draftv3.DraftV3TypeKeywordSyntaxChecker.java
@Override protected void checkValue(final Collection<JsonPointer> pointers, final MessageBundle bundle, final ProcessingReport report, final SchemaTree tree) throws ProcessingException { final JsonNode node = tree.getNode().get(keyword); if (node.isTextual()) { final String found = node.textValue(); if (!typeIsValid(found)) report.error(newMsg(tree, bundle, "common.typeDisallow.primitiveType.unknown") .putArgument("found", found).putArgument("valid", EnumSet.allOf(NodeType.class))); return;/* ww w. j ava 2 s.c o m*/ } final int size = node.size(); final Set<Equivalence.Wrapper<JsonNode>> set = Sets.newHashSet(); JsonNode element; NodeType type; boolean uniqueItems = true; for (int index = 0; index < size; index++) { element = node.get(index); type = NodeType.getNodeType(element); uniqueItems = set.add(EQUIVALENCE.wrap(element)); if (type == OBJECT) { pointers.add(JsonPointer.of(keyword, index)); continue; } if (type != STRING) { report.error(newMsg(tree, bundle, "common.array.element.incorrectType").putArgument("index", index) .putArgument("expected", EnumSet.of(OBJECT, STRING)).putArgument("found", type)); continue; } if (!typeIsValid(element.textValue())) report.error(newMsg(tree, bundle, "common.typeDisallow.primitiveType.unknown").put("index", index) .putArgument("found", element.textValue()) .putArgument("valid", EnumSet.allOf(NodeType.class))); } if (!uniqueItems) report.error(newMsg(tree, bundle, "common.array.duplicateElements")); }