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.AzureDirectoryFeatureTest.java
@Test public void testMakeDirectoryLongFilenameEncrypted() throws Exception { final Host host = new Host(new AzureProtocol(), "kahy9boj3eib.blob.core.windows.net", new Credentials(System.getProperties().getProperty("azure.account"), System.getProperties().getProperty("azure.key"))); final AzureSession session = new AzureSession(host); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final Path home = new Path("cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume)); final CryptoVault cryptomator = new CryptoVault( new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), new DisabledPasswordStore()); final Path vault = cryptomator.create(session, null, new VaultCredentials("test")); session.withRegistry(// w w w .j av a 2 s .co m new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator)); final Path test = new CryptoDirectoryFeature<Void>(session, new AzureDirectoryFeature(session, null), new AzureWriteFeature(session, null), cryptomator) .mkdir(new Path(vault, new RandomStringGenerator.Builder().build().generate(130), EnumSet.of(Path.Type.directory)), null, new TransferStatus()); assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(test)); new CryptoDeleteFeature(session, new AzureDeleteFeature(session, null), cryptomator) .delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
From source file:ch.cyberduck.core.cryptomator.S3DirectoryFeatureTest.java
@Test public void testMakeDirectoryLongFilenameEncrypted() throws Exception { final Host host = new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(), new Credentials( System.getProperties().getProperty("s3.key"), System.getProperties().getProperty("s3.secret"))); final S3Session session = new S3Session(host); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final Path home = new Path("test-us-east-1-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume)); final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)); final CryptoVault cryptomator = new CryptoVault(vault, new DisabledPasswordStore()); cryptomator.create(session, null, new VaultCredentials("test")); session.withRegistry(// w w w.j a v a 2s . c o m new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator)); final Path test = new CryptoDirectoryFeature<StorageObject>(session, new S3DirectoryFeature(session, new S3WriteFeature(session)), new S3WriteFeature(session), cryptomator) .mkdir(new Path(vault, new RandomStringGenerator.Builder().build().generate(130), EnumSet.of(Path.Type.directory)), null, new TransferStatus()); assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(test)); new CryptoDeleteFeature(session, new S3DefaultDeleteFeature(session), cryptomator) .delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
From source file:net.arp7.HdfsPerfTest.WriteFile.java
/** * Write a single file to HDFS.//from w ww . j av a 2 s .c o m * * @param file * @param fs * @param data * @param stats object to accumulate write stats. * @throws IOException * @throws InterruptedException */ private static void writeOneFile(final Path file, final FileSystem fs, final byte[] data, final FileIoStats stats) throws IOException, InterruptedException { final long startTime = System.nanoTime(); final EnumSet<CreateFlag> createFlags = EnumSet.of(CREATE, OVERWRITE); if (params.isLazyPersist()) { createFlags.add(LAZY_PERSIST); } LOG.info("Writing file " + file.toString()); final FSDataOutputStream os = fs.create(file, FsPermission.getFileDefault(), createFlags, Constants.BUFFER_SIZE, params.getReplication(), params.getBlockSize(), null); final long createEndTime = System.nanoTime(); stats.addCreateTime(createEndTime - startTime); final boolean isThrottled = params.maxWriteBps() > 0; final long expectedIoTimeNs = (isThrottled ? (((long) data.length * 1_000_000_000) / params.maxWriteBps()) : 0); try { long lastLoggedPercent = 0; long writeStartTime = System.nanoTime(); for (long j = 0; j < params.getFileSize() / params.getIoSize(); ++j) { final long ioStartTimeNs = (isThrottled ? System.nanoTime() : 0); os.write(data, 0, data.length); if (params.isHsync()) { os.hsync(); } else if (params.isHflush()) { os.hflush(); } final long ioEndTimeNs = (isThrottled ? System.nanoTime() : 0); Utils.enforceThrottle(ioEndTimeNs - ioStartTimeNs, expectedIoTimeNs); if (LOG.isDebugEnabled()) { long percentWritten = (j * params.getIoSize() * 100) / params.getFileSize(); if (percentWritten > lastLoggedPercent) { LOG.debug(" >> Wrote " + j * params.getIoSize() + "/" + params.getFileSize() + " [" + percentWritten + "%]"); lastLoggedPercent = percentWritten; } } } final long writeEndTime = System.nanoTime(); stats.addWriteTime(writeEndTime - writeStartTime); stats.incrFilesWritten(); stats.incrBytesWritten(params.getFileSize()); } finally { final long closeStartTime = System.nanoTime(); os.close(); final long closeEndTime = System.nanoTime(); stats.addCloseTime(closeEndTime - closeStartTime); } }
From source file:ch.algotrader.service.MarketDataCacheServiceImpl.java
@Override public double getForexRate(Currency baseCurrency, Currency transactionCurrency) { Validate.notNull(baseCurrency, "Base currency is null"); Validate.notNull(transactionCurrency, "Transaction currency is null"); if (baseCurrency.equals(transactionCurrency)) { return 1.0; }// w w w. ja va 2s.com final EnumSet<Currency> key = EnumSet.of(baseCurrency, transactionCurrency); Forex forex = this.forexMap.get(key); if (forex == null) { forex = this.lookupService.getForex(baseCurrency, transactionCurrency); if (forex == null) { throw new ForexAvailabilityException( "Forex does not exist: " + baseCurrency + "." + transactionCurrency); } this.forexMap.put(key, forex);//we may replace an existing forex entry due to racing but that's ok } final MarketDataEventVO marketDataEvent = getCurrentMarketDataEvent(forex.getId()); if (marketDataEvent == null) { throw new ForexAvailabilityException( "No exchange rate available for " + baseCurrency + "." + transactionCurrency); } if (forex.getBaseCurrency().equals(baseCurrency)) { // expected case return marketDataEvent.getCurrentValueDouble(); } else { // reverse case return 1.0 / marketDataEvent.getCurrentValueDouble(); } }
From source file:ch.cyberduck.core.cryptomator.AzureTouchFeatureTest.java
@Test public void testTouchLongFilenameEncryptedDefaultFeature() throws Exception { final Host host = new Host(new AzureProtocol(), "kahy9boj3eib.blob.core.windows.net", new Credentials(System.getProperties().getProperty("azure.account"), System.getProperties().getProperty("azure.key"))); final AzureSession session = new AzureSession(host); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final Path home = new Path("cyberduck", EnumSet.of(Path.Type.volume, Path.Type.directory)); final CryptoVault cryptomator = new CryptoVault( new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), new DisabledPasswordStore()); final Path vault = cryptomator.create(session, null, new VaultCredentials("test")); session.withRegistry(//from www . j a v a 2s. c o m new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator)); final Path test = new Path(vault, new RandomStringGenerator.Builder().build().generate(130), EnumSet.of(Path.Type.file)); new CryptoTouchFeature<Void>(session, new DefaultTouchFeature<Void>(new DefaultUploadFeature<Void>(new AzureWriteFeature(session, null))), new AzureWriteFeature(session, null), cryptomator).touch(test, new TransferStatus()); assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(test)); new CryptoDeleteFeature(session, new AzureDeleteFeature(session, null), cryptomator) .delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
From source file:ch.cyberduck.core.b2.B2SearchFeatureTest.java
@Test public void testSearchInRoot() 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")))); final LoginConnectionService service = new LoginConnectionService(new DisabledLoginCallback(), new DisabledHostKeyCallback(), new DisabledPasswordStore(), new DisabledProgressListener()); service.connect(session, PathCache.empty(), new DisabledCancelCallback()); final String name = new AlphanumericRandomStringService().random(); final Path bucket = new Path("test-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume)); final Path file = new B2TouchFeature(session).touch(new Path(bucket, name, EnumSet.of(Path.Type.file)), new TransferStatus()); final B2SearchFeature feature = new B2SearchFeature(session); assertNotNull(feature.search(bucket, new SearchFilter(name), new DisabledListProgressListener()) .find(new SimplePathPredicate(file))); // Supports prefix matching only assertNull(feature/*from w w w.j a va 2 s.c o m*/ .search(new Path("/", EnumSet.of(Path.Type.directory, Path.Type.volume)), new SearchFilter(StringUtils.substring(name, 2)), new DisabledListProgressListener()) .find(new SimplePathPredicate(file))); assertNotNull(feature.search(new Path("/", EnumSet.of(Path.Type.directory, Path.Type.volume)), new SearchFilter(StringUtils.substring(name, 0, name.length() - 2)), new DisabledListProgressListener()).find(new SimplePathPredicate(file))); new B2DeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
From source file:ch.cyberduck.core.s3.S3MultipartCopyFeatureTest.java
@Test public void testCopyAWS4Signature() throws Exception { final Host host = new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(), new Credentials( System.getProperties().getProperty("s3.key"), System.getProperties().getProperty("s3.secret"))); final S3Session session = new S3Session(host); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final Path container = new Path("test-eu-central-1-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume)); final Path test = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); final byte[] content = new RandomStringGenerator.Builder().build().generate(1000).getBytes(); final TransferStatus status = new TransferStatus().length(content.length); status.setChecksum(new SHA256ChecksumCompute().compute(new ByteArrayInputStream(content), status)); final OutputStream out = new S3WriteFeature(session).write(test, status, new DisabledConnectionCallback()); assertNotNull(out);/*from w w w . j a v a 2 s . c om*/ new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), out); out.close(); test.attributes().setSize(content.length); final Path copy = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); final S3MultipartCopyFeature feature = new S3MultipartCopyFeature(session, new S3AccessControlListFeature(session)); feature.copy(test, copy, status, new DisabledConnectionCallback()); assertTrue(new S3FindFeature(session).find(test)); assertEquals(content.length, new S3AttributesFinderFeature(session).find(test).getSize()); new S3DefaultDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); assertTrue(new S3FindFeature(session).find(copy)); assertEquals(content.length, new S3AttributesFinderFeature(session).find(copy).getSize()); new S3DefaultDeleteFeature(session).delete(Collections.singletonList(copy), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
From source file:ch.cyberduck.core.cryptomator.SwiftDirectoryFeatureTest.java
@Test public void testMakeDirectoryLongFilenameEncrypted() 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.directory)); 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 om new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator)); new CryptoDirectoryFeature<StorageObject>(session, new SwiftDirectoryFeature(session), new SwiftWriteFeature(session, new SwiftRegionService(session)), cryptomator).mkdir(test, null, new TransferStatus()); assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(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.SDSMultipartWriteFeatureTest.java
@Test public void testWriteZeroLength() 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 TransferStatus status = new TransferStatus(); final Path test = new Path(room, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); final SDSMultipartWriteFeature writer = new SDSMultipartWriteFeature(session); final HttpResponseOutputStream<VersionId> out = writer.write(test, status, new DisabledConnectionCallback()); assertNotNull(out);//from w w w . j av a 2 s. c om new StreamCopier(status, status).transfer(new NullInputStream(0L), out); final VersionId version = out.getStatus(); assertNotNull(version); assertTrue(new DefaultFindFeature(session).find(test)); new SDSDeleteFeature(session).delete(Collections.singletonList(room), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
From source file:ch.cyberduck.core.sds.SDSReadFeatureTest.java
@Test public void testReadInterrupt() 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()); final LoginConnectionService service = new LoginConnectionService(new DisabledLoginCallback(), new DisabledHostKeyCallback(), new DisabledPasswordStore(), new DisabledProgressListener()); service.connect(session, PathCache.empty(), new DisabledCancelCallback()); final byte[] content = RandomUtils.nextBytes(32769); final TransferStatus writeStatus = new TransferStatus(); writeStatus.setLength(content.length); 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, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); final SDSWriteFeature writer = new SDSWriteFeature(session); final HttpResponseOutputStream<VersionId> out = writer.write(test, writeStatus, new DisabledConnectionCallback()); assertNotNull(out);//from ww w.ja va 2 s.c o m new StreamCopier(writeStatus, writeStatus).transfer(new ByteArrayInputStream(content), out); // Unknown length in status final TransferStatus readStatus = new TransferStatus(); // Read a single byte { final InputStream in = new SDSReadFeature(session).read(test, readStatus, new DisabledConnectionCallback()); assertNotNull(in.read()); in.close(); } { final InputStream in = new SDSReadFeature(session).read(test, readStatus, new DisabledConnectionCallback()); assertNotNull(in); in.close(); } new SDSDeleteFeature(session).delete(Collections.singletonList(room), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }