List of usage examples for java.util.logging Logger getLogger
@CallerSensitive public static Logger getLogger(String name)
From source file:com.fantasy.Application.java
public static void main(String[] args) throws ParseException, Exception { ConfigurableApplicationContext context; context = SpringApplication.run(AggregatorConfig.class); SpaceDelimitedCommandLineParser<YearFlag, YearContainer> argParser; argParser = context.getBean(SpaceDelimitedCommandLineParser.class); YearContainer container = argParser.parseFor(YearFlag.class, args); String packageName = container.getPackageName(); String className = container.getClassName(); int year = container.getYear(); List<Class> taskRunners = findTypes(packageName); Class runner = null;//from ww w . ja v a2 s. co m if (Objects.nonNull(taskRunners)) { for (Class cl : taskRunners) { if (cl.getSimpleName().equalsIgnoreCase(className)) { runner = cl; break; } } if (Objects.nonNull(runner)) { Task task = (Task) context.getBean(runner); if (Objects.nonNull(task)) { if (task instanceof ContextUser) { ((ContextUser) task).haveContext(context); } if (task instanceof YearlyTask) { ((YearlyTask) task).setYear(year); } try { task.run(); } catch (InterruptedException ex) { Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex); } finally { if (Objects.nonNull(context)) { context.close(); } } } } } }
From source file:com.rest.samples.getReportFromJasperServerWithSeparateAuth.java
public static void main(String[] args) { // TODO code application logic here String host = "10.49.28.3"; String port = "8081"; String reportName = "vencimientos"; String params = "feini=2016-09-30&fefin=2016-09-30"; String url = "http://{host}:{port}/jasperserver/rest_v2/reports/Reportes/{reportName}.pdf?{params}"; url = url.replace("{host}", host); url = url.replace("{port}", port); url = url.replace("{reportName}", reportName); url = url.replace("{params}", params); try {//from w w w .ja v a 2 s . c o m CredentialsProvider cp = new BasicCredentialsProvider(); cp.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("username", "password")); CloseableHttpClient hc = HttpClientBuilder.create().setDefaultCredentialsProvider(cp).build(); HttpGet getMethod = new HttpGet(url); getMethod.addHeader("accept", "application/pdf"); HttpResponse res = hc.execute(getMethod); if (res.getStatusLine().getStatusCode() != 200) { throw new RuntimeException("Failed : HTTP eror code: " + res.getStatusLine().getStatusCode()); } InputStream is = res.getEntity().getContent(); OutputStream os = new FileOutputStream(new File("vencimientos.pdf")); int read = 0; byte[] bytes = new byte[2048]; while ((read = is.read(bytes)) != -1) { os.write(bytes, 0, read); } is.close(); os.close(); if (Desktop.isDesktopSupported()) { File pdfFile = new File("vencimientos.pdf"); Desktop.getDesktop().open(pdfFile); } } catch (IOException ex) { Logger.getLogger(SamplesUseHttpclient.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.jaqpot.core.service.client.jpdi.JPDIClientFactory.java
public static void main(String[] args) throws IOException, InterruptedException, ExecutionException { CloseableHttpAsyncClient asyncClient = HttpAsyncClientBuilder.create().build(); asyncClient.start();//from w w w .j a v a2s . co m HttpGet request = new HttpGet("http://www.google.com"); request.addHeader("Accept", "text/html"); Future f = asyncClient.execute(request, new FutureCallback<HttpResponse>() { @Override public void completed(HttpResponse t) { System.out.println("completed"); try { String result = new BufferedReader(new InputStreamReader(t.getEntity().getContent())).lines() .collect(Collectors.joining("\n")); System.out.println(result); } catch (IOException ex) { Logger.getLogger(JPDIClientFactory.class.getName()).log(Level.SEVERE, null, ex); } catch (UnsupportedOperationException ex) { Logger.getLogger(JPDIClientFactory.class.getName()).log(Level.SEVERE, null, ex); } } @Override public void failed(Exception excptn) { System.out.println("failed"); } @Override public void cancelled() { System.out.println("cancelled"); } }); f.get(); asyncClient.close(); }
From source file:edu.ucla.cs.scai.swim.qa.ontology.dbpedia.tipicality.DbpediaCsvDownload.java
public static void main(String args[]) throws FileNotFoundException, IOException { Document doc = null;//from www. j av a 2 s . c o m try { doc = Jsoup.connect(DBpediaOntology.DBPEDIA_CLASSES_URL).get(); } catch (IOException ex) { Logger.getLogger(DBpediaOntology.class.getName()).log(Level.SEVERE, null, ex); } download(doc.body().children().get(1).children().get(1)); }
From source file:com.rest.samples.GetJSON.java
public static void main(String[] args) { // TODO code application logic here // String url = "https://api.adorable.io/avatars/list"; String url = "http://freemusicarchive.org/api/get/albums.json?api_key=60BLHNQCAOUFPIBZ&limit=5"; try {/*from ww w.j a v a2 s. c o m*/ HttpClient hc = HttpClientBuilder.create().build(); HttpGet getMethod = new HttpGet(url); getMethod.addHeader("accept", "application/json"); HttpResponse res = hc.execute(getMethod); if (res.getStatusLine().getStatusCode() != 200) { throw new RuntimeException("Failed : HTTP eror code: " + res.getStatusLine().getStatusCode()); } InputStream is = res.getEntity().getContent(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); JsonParser parser = new JsonParser(); JsonElement element = parser.parse(br); if (element.isJsonObject()) { JsonObject jsonObject = element.getAsJsonObject(); Set<Map.Entry<String, JsonElement>> jsonEntrySet = jsonObject.entrySet(); for (Map.Entry<String, JsonElement> entry : jsonEntrySet) { if (entry.getValue().isJsonArray() && entry.getValue().getAsJsonArray().size() > 0) { JsonArray jsonArray = entry.getValue().getAsJsonArray(); Set<Map.Entry<String, JsonElement>> internalJsonEntrySet = jsonArray.get(0) .getAsJsonObject().entrySet(); for (Map.Entry<String, JsonElement> entrie : internalJsonEntrySet) { System.out.println("---> " + entrie.getKey() + " --> " + entrie.getValue()); } } else { System.out.println(entry.getKey() + " --> " + entry.getValue()); } } } String output; while ((output = br.readLine()) != null) { System.out.println(output); } } catch (IOException ex) { Logger.getLogger(SamplesUseHttpclient.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.siva.javamultithreading.MultiThreadExecutor.java
public static void main(String[] args) throws ExecutionException, IOException { //Populate the data List<DomainObject> list = new ArrayList<>(); DomainObject object = null;//from w ww.j a va 2s. com for (int i = 0; i < 230000; i++) { object = new DomainObject(); object.setId("ID" + i); object.setName("NAME" + i); object.setComment("COMMENT" + i); list.add(object); } int maxNoOfRows = 40000; int noOfThreads = 1; int remaining = 0; if (list.size() > 40000) { noOfThreads = list.size() / maxNoOfRows; remaining = list.size() % maxNoOfRows; if (remaining > 0) { noOfThreads++; } } List<List<DomainObject>> dos = ListUtils.partition(list, maxNoOfRows); ExecutorService threadPool = Executors.newFixedThreadPool(noOfThreads); CompletionService<HSSFWorkbook> pool = new ExecutorCompletionService<>(threadPool); // Excel creation through multiple threads long startTime = System.currentTimeMillis(); for (List<DomainObject> listObj : dos) { pool.submit(new ExcelChunkSheetWriter(listObj)); } HSSFWorkbook hSSFWorkbook = null; HSSFWorkbook book = new HSSFWorkbook(); HSSFSheet sheet = book.createSheet("Report"); try { for (int i = 0; i < 5; i++) { hSSFWorkbook = pool.take().get(); System.out.println( "sheet row count : sheet.PhysicalNumberOfRows() = " + sheet.getPhysicalNumberOfRows()); int currentCount = sheet.getPhysicalNumberOfRows(); int incomingCount = hSSFWorkbook.getSheetAt(0).getPhysicalNumberOfRows(); if ((currentCount + incomingCount) > 60000) { sheet = book.createSheet("Report" + i); } ExcelUtil.copySheets(book, sheet, hSSFWorkbook.getSheetAt(0)); } } catch (InterruptedException ex) { Logger.getLogger(MultiThreadExecutor.class.getName()).log(Level.SEVERE, null, ex); } catch (ExecutionException ex) { Logger.getLogger(MultiThreadExecutor.class.getName()).log(Level.SEVERE, null, ex); } try { writeFile(book, new FileOutputStream("Report.xls")); } catch (Exception e) { e.printStackTrace(); } //System.out.println("No of Threads : " + noOfThreads + " Size : " + list.size() + " remaining : " + remaining); long endTime = System.currentTimeMillis(); System.out.println("Time taken: " + (endTime - startTime) + " ms"); threadPool.shutdown(); //startProcess(); }
From source file:com.rest.samples.getReportFromJasperServerWithSeparateAuthFormatURL.java
public static void main(String[] args) { // TODO code application logic here Map<String, String> params = new HashMap<String, String>(); params.put("host", "10.49.28.3"); params.put("port", "8081"); params.put("reportName", "vencimientos"); params.put("parametros", "feini=2016-09-30&fefin=2016-09-30"); StrSubstitutor sub = new StrSubstitutor(params, "{", "}"); String urlTemplate = "http://{host}:{port}/jasperserver/rest_v2/reports/Reportes/{reportName}.pdf?{parametros}"; String url = sub.replace(urlTemplate); try {/*from w ww .j a v a2 s . c o m*/ CredentialsProvider cp = new BasicCredentialsProvider(); cp.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("jasperadmin", "jasperadmin")); CloseableHttpClient hc = HttpClientBuilder.create().setDefaultCredentialsProvider(cp).build(); HttpGet getMethod = new HttpGet(url); getMethod.addHeader("accept", "application/pdf"); HttpResponse res = hc.execute(getMethod); if (res.getStatusLine().getStatusCode() != 200) { throw new RuntimeException("Failed : HTTP eror code: " + res.getStatusLine().getStatusCode()); } InputStream is = res.getEntity().getContent(); OutputStream os = new FileOutputStream(new File("vencimientos.pdf")); int read = 0; byte[] bytes = new byte[2048]; while ((read = is.read(bytes)) != -1) { os.write(bytes, 0, read); } is.close(); os.close(); if (Desktop.isDesktopSupported()) { File pdfFile = new File("vencimientos.pdf"); Desktop.getDesktop().open(pdfFile); } } catch (IOException ex) { Logger.getLogger(SamplesUseHttpclient.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:groovesquid.Main.java
public static void main(String[] args) { System.setSecurityManager(null); log.log(Level.INFO, "Groovesquid v{0} running on {1} {2} ({3}) in {4}", new Object[] { version, System.getProperty("java.vm.name"), System.getProperty("java.runtime.version"), System.getProperty("java.vm.vendor"), System.getProperty("java.home") }); // show gui//from ww w.j a v a 2 s .c om // apple os x System.setProperty("apple.laf.useScreenMenuBar", "true"); System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Groovesquid"); // antialising System.setProperty("awt.useSystemAAFontSettings", "lcd"); System.setProperty("swing.aatext", "true"); // flackering bg fix System.setProperty("sun.awt.noerasebackground", "true"); System.setProperty("sun.java2d.noddraw", "true"); Toolkit.getDefaultToolkit().setDynamicLayout(true); try { //UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception ex) { log.log(Level.SEVERE, null, ex); } // load languages languages = loadLanguages(); // Load config config = loadConfig(); // GUI try { gui = (GUI) config.getGuiClass().newInstance(); } catch (InstantiationException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } settings = new Settings(); about = new About(); // Update Checker new UpdateCheckThread().start(); // init grooveshark (every 25min) new InitThread().start(); }
From source file:de.jgoestl.massdatagenerator.MassDataGenerator.java
/** * @param args the command line arguments */// ww w . j av a 2s.c o m public static void main(String[] args) { // CommandLine options Options options = new Options(); options.addOption("i", "input", true, "The input file"); options.addOption("o", "output", true, "The output file"); options.addOption("c", "count", true, "The amount of generatet data"); options.addOption("d", "dateFormat", true, "A custom date format"); options.addOption("h", "help", false, "Show this"); CommandLineParser parser = new GnuParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException ex) { Logger.getLogger(MassDataGenerator.class.getName()).log(Level.SEVERE, null, ex); System.exit(1); } // Show the help if (cmd.hasOption("help") || !cmd.hasOption("input") || !cmd.hasOption("output") || !cmd.hasOption("count")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("massDataGenerator", options); System.out.println("\nFollowing in your input file will be replaced:"); System.out.println("#UUID# - A random UUID"); System.out.println("#SEQ# - A consecutive number (starting with 1)"); System.out.println("#DATE# - The current date (YYYY-MM-d h:m:s.S)"); System.exit(0); } // Get values and validate String inputFilePath = cmd.getOptionValue("input"); String outputPath = cmd.getOptionValue("output"); int numberOfData = getNumberOfData(cmd); validate(inputFilePath, outputPath, numberOfData); DateFormat dateFormat = getDateFormat(cmd); // Read, generte and write Data String inputString = null; inputString = readInputFile(inputFilePath, inputString); StringBuilder output = generateOutput(numberOfData, inputString, dateFormat); writeOutput(outputPath, output); }
From source file:edu.washington.data.sentimentreebank.StanfordNLPDict.java
public static void main(String args[]) { Options options = new Options(); options.addOption("d", "dict", true, "dictionary file."); options.addOption("s", "sentiment", true, "sentiment value file."); CommandLineParser parser = new GnuParser(); try {//from w w w. jav a2 s .c o m CommandLine line = parser.parse(options, args); if (!line.hasOption("dict") && !line.hasOption("sentiment")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("StanfordNLPDict", options); return; } Path dictPath = Paths.get(line.getOptionValue("dict")); Path sentimentPath = Paths.get(line.getOptionValue("sentiment")); StanfordNLPDict snlp = new StanfordNLPDict(dictPath, sentimentPath); String sentence = "take off"; System.out.printf("sentence [%1$s] %2$s\n", sentence, String.valueOf(snlp.getPhraseSentiment(sentence))); } catch (ParseException exp) { System.err.println("Parsing failed. Reason: " + exp.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("StanfordNLPDict", options); } catch (IOException ex) { Logger.getLogger(StanfordNLPDict.class.getName()).log(Level.SEVERE, null, ex); } }