List of usage examples for java.util EnumSet of
public static <E extends Enum<E>> EnumSet<E> of(E e)
From source file:Numbers.java
public static void main(String[] args) { EnumSet<Numbers> set1 = EnumSet.of(Numbers.FOUR); System.out.println("Set1:" + set1); // create a set2 which has all elements that set1 doesn't have EnumSet<Numbers> set2 = EnumSet.complementOf(set1); System.out.println("Set2:" + set2); }
From source file:Numbers.java
public static void main(String[] args) { // create a set EnumSet<Numbers> set;//from w w w . j a v a2 s . c o m // add one element set = EnumSet.of(Numbers.FIVE); System.out.println(set); // add another element which replaces the previous set = EnumSet.of(Numbers.THREE); System.out.println(set); }
From source file:Test.java
public static void main(String[] args) { try {//w ww .j a v a 2 s. c o m Path source = Paths.get("/home"); Path target = Paths.get("/backup"); Files.walkFileTree(source, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new CopyDirectory(source, target)); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Test.java
public static void main(String args[]) throws Exception { ExecutorService pool = new ScheduledThreadPoolExecutor(3); AsynchronousFileChannel fileChannel = AsynchronousFileChannel.open(Paths.get("data.txt"), EnumSet.of(StandardOpenOption.READ), pool); CompletionHandler<Integer, ByteBuffer> handler = new CompletionHandler<Integer, ByteBuffer>() { public synchronized void completed(Integer result, ByteBuffer attachment) { for (int i = 0; i < attachment.limit(); i++) { System.out.print((char) attachment.get(i)); }//from ww w.jav a2 s.com } public void failed(Throwable e, ByteBuffer attachment) { } }; final int bufferCount = 5; ByteBuffer buffers[] = new ByteBuffer[bufferCount]; for (int i = 0; i < bufferCount; i++) { buffers[i] = ByteBuffer.allocate(10); fileChannel.read(buffers[i], i * 10, buffers[i], handler); } pool.awaitTermination(1, TimeUnit.SECONDS); for (ByteBuffer byteBuffer : buffers) { for (int i = 0; i < byteBuffer.limit(); i++) { System.out.println((char) byteBuffer.get(i)); } } }
From source file:Test.java
public static void main(String args[]) throws Exception { ExecutorService pool = new ScheduledThreadPoolExecutor(3); AsynchronousFileChannel fileChannel = AsynchronousFileChannel.open(Paths.get("data.txt"), EnumSet.of(StandardOpenOption.READ), pool); CompletionHandler<Integer, ByteBuffer> handler = new CompletionHandler<Integer, ByteBuffer>() { @Override/*from w ww .ja v a 2s . c o m*/ public synchronized void completed(Integer result, ByteBuffer attachment) { for (int i = 0; i < attachment.limit(); i++) { System.out.println((char) attachment.get(i)); } } @Override public void failed(Throwable e, ByteBuffer attachment) { } }; final int bufferCount = 5; ByteBuffer buffers[] = new ByteBuffer[bufferCount]; for (int i = 0; i < bufferCount; i++) { buffers[i] = ByteBuffer.allocate(10); fileChannel.read(buffers[i], i * 10, buffers[i], handler); } pool.awaitTermination(1, TimeUnit.SECONDS); for (ByteBuffer byteBuffer : buffers) { for (int i = 0; i < byteBuffer.limit(); i++) { System.out.print((char) byteBuffer.get(i)); } } }
From source file:Search.java
public static void main(String[] args) throws IOException { Path searchFile = Paths.get("Demo.jpg"); Search walk = new Search(searchFile); EnumSet<FileVisitOption> opts = EnumSet.of(FileVisitOption.FOLLOW_LINKS); Iterable<Path> dirs = FileSystems.getDefault().getRootDirectories(); for (Path root : dirs) { if (!walk.found) { Files.walkFileTree(root, opts, Integer.MAX_VALUE, walk); }/*from w w w. j a va2 s .c o m*/ } if (!walk.found) { System.out.println("The file " + searchFile + " was not found!"); } }
From source file:http2.Main.java
public static void main(String[] args) throws Exception { AnnotationConfigWebApplicationContext cxt = new AnnotationConfigWebApplicationContext(); cxt.register(WebConfig.class); DispatcherServlet dispatcherServlet = new DispatcherServlet(cxt); Server server = new Server(); ServletContextHandler context = new ServletContextHandler(); context.setResourceBase("src/main/webapp"); context.addServlet(new ServletHolder("default", DefaultServlet.class), ""); context.addServlet(new ServletHolder(dispatcherServlet), "/"); context.addFilter(new FilterHolder(new PushCacheFilter()), "/*", EnumSet.of(DispatcherType.REQUEST)); server.setHandler(context);//from ww w .jav a 2 s . c o m HttpConfiguration httpConfig = new HttpConfiguration(); httpConfig.setSecureScheme("https"); httpConfig.setSecurePort(8443); httpConfig.setSendXPoweredBy(true); httpConfig.setSendServerVersion(true); HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig); httpsConfig.addCustomizer(new SecureRequestCustomizer()); ServerConnector httpConnector = new ServerConnector(server, new HttpConnectionFactory(httpConfig)); httpConnector.setPort(8080); server.addConnector(httpConnector); ServerConnector http2Connector = createHttp2Connector(server, httpsConfig); http2Connector.setPort(8443); server.addConnector(http2Connector); ALPN.debug = true; server.start(); server.dumpStdErr(); server.join(); }
From source file:org.wallride.tools.Hbm2ddl.java
public static void main(String[] args) throws Exception { String locationPattern = "classpath:/org/wallride/domain/*"; final BootstrapServiceRegistry registry = new BootstrapServiceRegistryBuilder().build(); final MetadataSources metadataSources = new MetadataSources(registry); final StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder(registry); registryBuilder.applySetting(AvailableSettings.DIALECT, ExtendedMySQL5InnoDBDialect.class.getCanonicalName()); registryBuilder.applySetting(AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS, true); registryBuilder.applySetting(AvailableSettings.PHYSICAL_NAMING_STRATEGY, PhysicalNamingStrategySnakeCaseImpl.class); final PathMatchingResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver(); final Resource[] resources = resourcePatternResolver.getResources(locationPattern); final SimpleMetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory(); for (Resource resource : resources) { MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource); AnnotationMetadata metadata = metadataReader.getAnnotationMetadata(); if (metadata.hasAnnotation(Entity.class.getName())) { metadataSources.addAnnotatedClass(Class.forName(metadata.getClassName())); }//from w ww .ja va 2 s. com } final StandardServiceRegistryImpl registryImpl = (StandardServiceRegistryImpl) registryBuilder.build(); final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder(registryImpl); new SchemaExport().setHaltOnError(true).setDelimiter(";").create(EnumSet.of(TargetType.STDOUT), metadataBuilder.build()); }
From source file:com.github.zk1931.pulsefs.Main.java
public static void main(String[] args) throws Exception { // Options for command arguments. Options options = new Options(); Option port = OptionBuilder.withArgName("port").hasArg(true).isRequired(true).withDescription("port number") .create("port"); Option addr = OptionBuilder.withArgName("addr").hasArg(true).withDescription("addr (ip:port) for Zab.") .create("addr"); Option join = OptionBuilder.withArgName("join").hasArg(true).withDescription("the addr of server to join.") .create("join"); Option dir = OptionBuilder.withArgName("dir").hasArg(true).withDescription("the directory for logs.") .create("dir"); Option help = OptionBuilder.withArgName("h").hasArg(false).withLongOpt("help") .withDescription("print out usages.").create("h"); Option timeout = OptionBuilder.withArgName("timeout").hasArg(true) .withDescription("session timeout(seconds)").create("timeout"); options.addOption(port).addOption(addr).addOption(join).addOption(dir).addOption(timeout).addOption(help); CommandLineParser parser = new BasicParser(); CommandLine cmd;//from w w w . j ava 2s . c o m String usage = "./bin/pulsefs -port port [Options]"; try { cmd = parser.parse(options, args); if (cmd.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(usage, options); return; } } catch (ParseException exp) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(usage, options); return; } PulseFSConfig config = new PulseFSConfig(); if (cmd.hasOption("addr")) { config.setServerId(cmd.getOptionValue("addr")); } if (cmd.hasOption("join")) { config.setJoinPeer(cmd.getOptionValue("join")); } if (cmd.hasOption("dir")) { config.setLogDir(cmd.getOptionValue("dir")); } if (cmd.hasOption("timeout")) { String sessionTimeout = cmd.getOptionValue("timeout"); config.setSessionTimeout(Integer.parseInt(sessionTimeout)); } if (cmd.hasOption("port")) { config.setPort(Integer.parseInt(cmd.getOptionValue("port"))); } Server server = new Server(config.getPort()); // Suppress "Server" header in HTTP response. for (Connector y : server.getConnectors()) { for (ConnectionFactory x : y.getConnectionFactories()) { if (x instanceof HttpConnectionFactory) { ((HttpConnectionFactory) x).getHttpConfiguration().setSendServerVersion(false); } } } PulseFS fs = new PulseFS(config); SessionFilter sessionFilter = new SessionFilter(fs); FilterHolder filters = new FilterHolder(sessionFilter); ServletContextHandler pulsefs = new ServletContextHandler(ServletContextHandler.SESSIONS); pulsefs.setContextPath(PulseFSConfig.PULSEFS_ROOT); pulsefs.setAllowNullPathInfo(true); pulsefs.addServlet(new ServletHolder(new PulseFSHandler(fs)), "/*"); pulsefs.addFilter(filters, "/*", EnumSet.of(DispatcherType.REQUEST)); ServletContextHandler servers = new ServletContextHandler(ServletContextHandler.SESSIONS); servers.setContextPath(PulseFSConfig.PULSEFS_SERVERS_PATH); // Redirects /pulsefs/servers to /pulsefs/servers/ servers.setAllowNullPathInfo(true); servers.addServlet(new ServletHolder(new PulseFSServersHandler(fs)), "/*"); servers.addFilter(filters, "/*", EnumSet.of(DispatcherType.REQUEST)); ServletContextHandler tree = new ServletContextHandler(ServletContextHandler.SESSIONS); tree.setContextPath("/"); tree.addServlet(new ServletHolder(new TreeHandler(fs)), "/*"); tree.addFilter(filters, "/*", EnumSet.of(DispatcherType.REQUEST)); ServletContextHandler sessions = new ServletContextHandler(ServletContextHandler.SESSIONS); sessions.setContextPath(PulseFSConfig.PULSEFS_SESSIONS_PATH); // Redirects /pulsefs/sessions to /pulsefs/sessions/ sessions.setAllowNullPathInfo(true); sessions.addServlet(new ServletHolder(new PulseFSSessionsHandler(fs)), "/*"); sessions.addFilter(filters, "/*", EnumSet.of(DispatcherType.REQUEST)); ContextHandlerCollection contexts = new ContextHandlerCollection(); contexts.setHandlers(new Handler[] { sessions, servers, pulsefs, tree }); server.setHandler(contexts); server.start(); server.join(); }
From source file:com.github.houbin217jz.thumbnail.Thumbnail.java
public static void main(String[] args) { Options options = new Options(); options.addOption("s", "src", true, "????????????"); options.addOption("d", "dst", true, ""); options.addOption("r", "ratio", true, "/??, 30%???0.3????????"); options.addOption("w", "width", true, "(px)"); options.addOption("h", "height", true, "?(px)"); options.addOption("R", "recursive", false, "???????"); HelpFormatter formatter = new HelpFormatter(); String formatstr = "java -jar thumbnail.jar " + "[-s/--src <path>] " + "[-d/--dst <path>] " + "[-r/--ratio double] " + "[-w/--width integer] " + "[-h/--height integer] " + "[-R/--recursive] "; CommandLineParser parser = new PosixParser(); CommandLine cmd = null;/*from w w w . j av a2 s.c o m*/ try { cmd = parser.parse(options, args); } catch (ParseException e1) { formatter.printHelp(formatstr, options); return; } final Path srcDir, dstDir; final Integer width, height; final Double ratio; // if (cmd.hasOption("s")) { srcDir = Paths.get(cmd.getOptionValue("s")).toAbsolutePath(); } else { srcDir = Paths.get("").toAbsolutePath(); //?? } // if (cmd.hasOption("d")) { dstDir = Paths.get(cmd.getOptionValue("d")).toAbsolutePath(); } else { formatter.printHelp(formatstr, options); return; } if (!Files.exists(srcDir, LinkOption.NOFOLLOW_LINKS) || !Files.isDirectory(srcDir, LinkOption.NOFOLLOW_LINKS)) { System.out.println("[" + srcDir.toAbsolutePath() + "]??????"); return; } if (Files.exists(dstDir, LinkOption.NOFOLLOW_LINKS)) { if (!Files.isDirectory(dstDir, LinkOption.NOFOLLOW_LINKS)) { //???????? System.out.println("????????"); return; } } else { //???????? try { Files.createDirectories(dstDir); } catch (IOException e) { e.printStackTrace(); return; } } //?? if (cmd.hasOption("w") && cmd.hasOption("h")) { try { width = Integer.valueOf(cmd.getOptionValue("width")); height = Integer.valueOf(cmd.getOptionValue("height")); } catch (NumberFormatException e) { System.out.println("??????"); return; } } else { width = null; height = null; } //? if (cmd.hasOption("r")) { try { ratio = Double.valueOf(cmd.getOptionValue("r")); } catch (NumberFormatException e) { System.out.println("?????"); return; } } else { ratio = null; } if (width != null && ratio != null) { System.out.println("??????????????"); return; } if (width == null && ratio == null) { System.out.println("????????????"); return; } // int maxDepth = 1; if (cmd.hasOption("R")) { maxDepth = Integer.MAX_VALUE; } try { //Java 7 ??@see http://docs.oracle.com/javase/jp/7/api/java/nio/file/Files.html Files.walkFileTree(srcDir, EnumSet.of(FileVisitOption.FOLLOW_LINKS), maxDepth, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path path, BasicFileAttributes basicFileAttributes) throws IOException { //???&??? String filename = path.getFileName().toString().toLowerCase(); if (filename.endsWith(".jpg") || filename.endsWith(".jpeg")) { //Jpeg?? /* * relative??: * rootPath: /a/b/c/d * filePath: /a/b/c/d/e/f.jpg * rootPath.relativize(filePath) = e/f.jpg */ /* * resolve?? * rootPath: /a/b/c/output * relativePath: e/f.jpg * rootPath.resolve(relativePath) = /a/b/c/output/e/f.jpg */ Path dst = dstDir.resolve(srcDir.relativize(path)); if (!Files.exists(dst.getParent(), LinkOption.NOFOLLOW_LINKS)) { Files.createDirectories(dst.getParent()); } doResize(path.toFile(), dst.toFile(), width, height, ratio); } return FileVisitResult.CONTINUE; } }); } catch (IOException e) { e.printStackTrace(); } }