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.shared.DefaultCopyFeatureTest.java
@Test public void testCopy() 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 source = new Path(new SFTPHomeDirectoryService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)); final Path target = new Path(new SFTPHomeDirectoryService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)); new DefaultTouchFeature<Void>(new DefaultUploadFeature<Void>(new SFTPWriteFeature(session))).touch(source, new TransferStatus()); final byte[] content = RandomUtils.nextBytes(524); final TransferStatus status = new TransferStatus().length(content.length); final OutputStream out = new SFTPWriteFeature(session).write(source, status, new DisabledConnectionCallback()); assertNotNull(out);// w w w . j a v a2 s. c o m new StreamCopier(status, status).withLimit(new Long(content.length)) .transfer(new ByteArrayInputStream(content), out); out.close(); new DefaultCopyFeature(session).copy(source, target, new TransferStatus(), new DisabledConnectionCallback()); assertTrue(new DefaultFindFeature(session).find(source)); assertTrue(new DefaultFindFeature(session).find(target)); assertEquals(content.length, new DefaultAttributesFinderFeature(session).find(target).getSize()); new SFTPDeleteFeature(session).delete(Arrays.asList(source, target), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
From source file:ch.cyberduck.core.sftp.SFTPReadFeatureTest.java
@Test public void testRead() 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 = 39865; final byte[] content = RandomUtils.nextBytes(length); {/*from ww w .j a va 2s . 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); final InputStream in = new SFTPReadFeature(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 SFTPDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
From source file:ch.cyberduck.core.irods.IRODSListService.java
@Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { try {//from w w w .j a va2 s .c om final AttributedList<Path> children = new AttributedList<Path>(); final IRODSFileSystemAO fs = session.getClient(); final IRODSFile f = fs.getIRODSFileFactory().instanceIRODSFile(directory.getAbsolute()); if (!f.exists()) { throw new NotfoundException(directory.getAbsolute()); } for (File file : fs.getListInDirWithFileFilter(f, TrueFileFilter.TRUE)) { final String normalized = PathNormalizer.normalize(file.getAbsolutePath(), true); if (StringUtils.equals(normalized, directory.getAbsolute())) { continue; } final PathAttributes attributes = new PathAttributes(); final ObjStat stats = fs.getObjStat(file.getAbsolutePath()); attributes.setModificationDate(stats.getModifiedAt().getTime()); attributes.setCreationDate(stats.getCreatedAt().getTime()); attributes.setSize(stats.getObjSize()); attributes .setChecksum(Checksum.parse(Hex.encodeHexString(Base64.decodeBase64(stats.getChecksum())))); attributes.setOwner(stats.getOwnerName()); attributes.setGroup(stats.getOwnerZone()); children.add(new Path(directory, PathNormalizer.name(normalized), file.isDirectory() ? EnumSet.of(Path.Type.directory) : EnumSet.of(Path.Type.file), attributes)); listener.chunk(directory, children); } return children; } catch (JargonException e) { throw new IRODSExceptionMappingService().map("Listing directory {0} failed", e, directory); } }
From source file:com.twitter.hraven.hadoopJobMonitor.ClusterStatusChecker.java
/** * Get the app list from RM and check status of each *///from w w w .ja va2 s.com @Override public void run() { // 1. get the list of running apps LOG.info("Running " + ClusterStatusChecker.class.getName()); try { YarnConfiguration yConf = new YarnConfiguration(); LOG.info(yConf.get(YarnConfiguration.RM_ADDRESS)); LOG.info("Getting appList ..."); // TODO: in future hadoop API we will be able to filter the app list EnumSet<YarnApplicationState> states = EnumSet.of(YarnApplicationState.RUNNING); List<ApplicationReport> appList = rmDelegate.getApplications(states); LOG.info("appList received. size is: " + appList.size()); for (ApplicationReport appReport : appList) checkAppStatus(appReport); } catch (YarnRuntimeException e) { LOG.error("Error in getting application list from RM", e); } catch (YarnException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.newatlanta.appengine.vfs.provider.GaeRandomAccessContent.java
GaeRandomAccessContent(GaeFileObject gfo, RandomAccessMode m, boolean append) throws IOException { EnumSet<StandardOpenOption> options = EnumSet.of(StandardOpenOption.READ); if (m == RandomAccessMode.READWRITE) { options.add(StandardOpenOption.WRITE); gfo.doSetLastModTime(System.currentTimeMillis()); }//from w ww .ja v a 2s . c o m if (append) { options.add(StandardOpenOption.APPEND); } fileChannel = new GaeFileChannel(gfo, options); dataOutput = new DataOutputStream(Channels.newOutputStream(fileChannel)); dataInput = new GaeDataInputStream(Channels.newInputStream(fileChannel)); }
From source file:com.github.fge.jsonschema.core.keyword.syntax.checkers.draftv3.DraftV3DependenciesSyntaxChecker.java
@Override protected void checkDependency(final ProcessingReport report, final MessageBundle bundle, final String name, final SchemaTree tree) throws ProcessingException { final JsonNode node = getNode(tree).get(name); NodeType type;// w w w .j ava 2 s .c om type = NodeType.getNodeType(node); if (type == NodeType.STRING) return; if (type != NodeType.ARRAY) { report.error( newMsg(tree, bundle, "common.dependencies.value.incorrectType").putArgument("property", name) .putArgument("expected", dependencyTypes).putArgument("found", type)); return; } final int size = node.size(); /* * Yep, in draft v3, nothing prevents a dependency array from being * empty! This is stupid, so at least warn the user. */ if (size == 0) { report.warn(newMsg(tree, bundle, "common.array.empty").put("property", name)); return; } final Set<Equivalence.Wrapper<JsonNode>> set = Sets.newHashSet(); JsonNode element; boolean uniqueElements = true; for (int index = 0; index < size; index++) { element = node.get(index); type = NodeType.getNodeType(element); uniqueElements = set.add(EQUIVALENCE.wrap(element)); if (type == NodeType.STRING) continue; report.error(newMsg(tree, bundle, "common.array.element.incorrectType").put("property", name) .putArgument("index", index).putArgument("expected", EnumSet.of(NodeType.STRING)) .putArgument("found", type)); } /* * Similarly, there is nothing preventing duplicates. Equally stupid, * so warn the user. */ if (!uniqueElements) report.warn(newMsg(tree, bundle, "common.array.duplicateElements").put("property", name)); }
From source file:com.facebook.presto.geospatial.GeoFunctions.java
@Description("Returns a Geometry type Polygon object from Well-Known Text representation (WKT)") @ScalarFunction("ST_Polygon") @SqlType(GEOMETRY_TYPE_NAME)/*www .j a v a2 s .co m*/ public static Slice stPolygon(@SqlType(StandardTypes.VARCHAR) Slice input) { OGCGeometry geometry = OGCGeometry.fromText(input.toStringUtf8()); validateType("ST_Polygon", geometry, EnumSet.of(POLYGON)); return serialize(geometry); }
From source file:com.mnt.base.console.WebJettyController.java
protected void init() { log.info("Prepare to startup the Jetty Web Server..."); super.init(); String webRootPath = BaseConfiguration.getProperty("web_root_path"); if (CommonUtil.isEmpty(webRootPath)) { webRootPath = DEFAULT_WEB_ROOT_PATH; }// www .j av a2 s.c o m final WebAppContext webappContext = new WebAppContext(BaseConfiguration.getServerHome(true) + webRootPath, BaseConfiguration.getServerContextPath()); webappContext.setParentLoaderPriority(true); File tmpFolder = new File(BaseConfiguration.getServerHome() + "tmp"); if (!tmpFolder.exists()) { tmpFolder.mkdirs(); } webappContext.setTempDirectory(tmpFolder); webappContext.setAttribute("javax.servlet.context.tempdir", tmpFolder); jettyServer.setHandler(webappContext); super.setupExternalConf(new ExternalConfSetter() { @Override public void addServlet(Class<HttpServlet> servletClass, String pathSpec) throws Exception { HttpServlet servlet = (HttpServlet) (servletClass.newInstance()); webappContext.addServlet(new ServletHolder(servlet), pathSpec); } @Override public void addFilter(Class<Filter> filterClass, String pathSpec) throws Exception { webappContext.addFilter(filterClass, pathSpec, EnumSet.of(DispatcherType.REQUEST)); } }); // be end of the previous setting webappContext.addFilter(new FilterHolder(new WebAccessRouterFilter()), "/*", EnumSet.of(DispatcherType.REQUEST)); }
From source file:ch.cyberduck.core.cryptomator.DropboxDirectoryFeatureTest.java
@Test public void testMakeDirectoryLongFilenameEncrypted() throws Exception { 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 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(/* w w w . ja v a 2s. co m*/ new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator)); new CryptoDirectoryFeature<String>(session, new DropboxDirectoryFeature(session), new DropboxWriteFeature(session), cryptomator).mkdir(test, null, new TransferStatus()); assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(test)); new CryptoDeleteFeature(session, new DropboxDeleteFeature(session), cryptomator) .delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback()); }
From source file:ch.cyberduck.core.dav.DAVUploadFeatureTest.java
@Test(expected = AccessDeniedException.class) public void testAccessDenied() 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 Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString()); new DefaultLocalTouchFeature().touch(local); final Path test = new Path(new Path("/dav/accessdenied", EnumSet.of(Path.Type.directory)), "nosuchname", EnumSet.of(Path.Type.file)); try {//from w w w.ja v a 2s . c o m new DAVUploadFeature(new DAVWriteFeature(session)).upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), status, new DisabledConnectionCallback()); } catch (AccessDeniedException e) { assertEquals( "Unexpected response (403 Forbidden). Please contact your web hosting service provider for assistance.", e.getDetail()); throw e; } finally { local.delete(); session.close(); } }