List of usage examples for java.nio.file Paths get
public static Path get(URI uri)
From source file:MyWatch.java
public static void main(String[] args) { final Path path = Paths.get("C:/tutorial"); MyWatch watch = new MyWatch(); try {//ww w . jav a 2 s . c om watch.watchRNDir(path); } catch (IOException | InterruptedException ex) { System.err.println(ex); } }
From source file:com.stackoverflow.so32806530.App.java
/** * Program EP./*from w w w.j av a 2 s .c o m*/ * @param args CLI args * * @throws URISyntaxException * @throws IOException */ public static void main(final String[] args) throws URISyntaxException, IOException { // ---------- Read response.xml ----- final String xml = new String( Files.readAllBytes(Paths.get(App.class.getClassLoader().getResource("response.xml").toURI())), Charset.forName("UTF-8")); // ---------- starts fake API server ----- final WireMockServer wireMockServer = new WireMockServer(WireMockConfiguration.wireMockConfig().port(8089)); wireMockServer.stubFor(get(urlMatching("/v2/discovery/events.*")).willReturn( aResponse().withHeader("Content-type", "application/xml").withStatus(200).withBody(xml))); wireMockServer.start(); // --------------------------------------- try { final String name = "foo"; final String APIKEY = "MYAPI"; final String URL = "http://localhost:8089/v2/discovery/events?apikey=" + APIKEY; final String readyUrl = URL + "&what=" + name; final RestTemplate restTemplate = new RestTemplate(); final EventsResponse eventResponse = restTemplate.getForObject(readyUrl, EventsResponse.class); log.info("Seatwave: {}", eventResponse.getEvents().size()); for (final Event event : eventResponse.getEvents()) { log.info("EventID: {}", event.getId()); } } catch (final Exception ex) { log.error("Something went wrong", ex); } // ---------- stops fake API server ------ wireMockServer.stop(); // --------------------------------------- }
From source file:DataCrawler.OpenAIRE.XMLGenerator.java
public static void main(String[] args) { String text = ""; try {/* w ww.j av a 2 s .co m*/ if (args.length < 4) { System.out.println("<command> template_file csv_file output_dir log_file [start_id]"); } // InputStream fis = new FileInputStream("E:/Downloads/result-r-00000"); InputStream fis = new FileInputStream(args[1]); BufferedReader br = new BufferedReader(new InputStreamReader(fis, Charset.forName("UTF-8"))); // String content = new String(Files.readAllBytes(Paths.get("publications_template.xml"))); String content = new String(Files.readAllBytes(Paths.get(args[0]))); Document doc = Jsoup.parse(content, "UTF-8", Parser.xmlParser()); // String outputDirectory = "G:/"; String outputDirectory = args[2]; // PrintWriter logWriter = new PrintWriter(new FileOutputStream("publication.log",false)); PrintWriter logWriter = new PrintWriter(new FileOutputStream(args[3], false)); Element objectId = null, title = null, publisher = null, dateofacceptance = null, bestlicense = null, resulttype = null, originalId = null, originalId2 = null; boolean start = true; // String startID = "dedup_wf_001::207a098867b64f3b5af505fa3aeecd24"; String startID = ""; if (args.length >= 5) { start = false; startID = args[4]; } String previousText = ""; while ((text = br.readLine()) != null) { /* For publications: 0. dri:objIdentifier context 9. title context 12. publisher context 18. dateofacceptance 19. bestlicense @classname 21. resulttype @classname 26. originalId context (Notice that the prefix is null and will use space to separate two different "originalId") */ if (!previousText.isEmpty()) { text = previousText + text; start = true; previousText = ""; } String[] items = text.split("!"); for (int i = 0; i < items.length; ++i) { items[i] = StringUtils.strip(items[i], "#"); } if (objectId == null) objectId = doc.getElementsByTag("dri:objIdentifier").first(); objectId.text(items[0]); if (!start && items[0].equals(startID)) { start = true; } if (title == null) title = doc.getElementsByTag("title").first(); title.text(items[9]); if (publisher == null) publisher = doc.getElementsByTag("publisher").first(); if (items.length < 12) { previousText = text; continue; } publisher.text(items[12]); if (dateofacceptance == null) dateofacceptance = doc.getElementsByTag("dateofacceptance").first(); dateofacceptance.text(items[18]); if (bestlicense == null) bestlicense = doc.getElementsByTag("bestlicense").first(); bestlicense.attr("classname", items[19]); if (resulttype == null) resulttype = doc.getElementsByTag("resulttype").first(); resulttype.attr("classname", items[21]); if (originalId == null || originalId2 == null) { Elements elements = doc.getElementsByTag("originalId"); String[] context = items[26].split(" "); if (elements.size() > 0) { if (elements.size() >= 1) { originalId = elements.get(0); if (context.length >= 1) { int indexOfnull = context[0].trim().indexOf("null"); String value = ""; if (indexOfnull != -1) { if (context[0].trim().length() >= (indexOfnull + 5)) value = context[0].trim().substring(indexOfnull + 5); } else { value = context[0].trim(); } originalId.text(value); } } if (elements.size() >= 2) { originalId2 = elements.get(1); if (context.length >= 2) { int indexOfnull = context[1].trim().indexOf("null"); String value = ""; if (indexOfnull != -1) { if (context[1].trim().length() >= (indexOfnull + 5)) value = context[1].trim().substring(indexOfnull + 5); } else { value = context[1].trim(); } originalId2.text(value); } } } } else { String[] context = items[26].split(" "); if (context.length >= 1) { int indexOfnull = context[0].trim().indexOf("null"); String value = ""; if (indexOfnull != -1) { if (context[0].trim().length() >= (indexOfnull + 5)) value = context[0].trim().substring(indexOfnull + 5); } else { value = context[0].trim(); } originalId.text(value); } if (context.length >= 2) { int indexOfnull = context[1].trim().indexOf("null"); String value = ""; if (indexOfnull != -1) { if (context[1].trim().length() >= (indexOfnull + 5)) value = context[1].trim().substring(indexOfnull + 5); } else { value = context[1].trim(); } originalId2.text(value); } } if (start) { String filePath = outputDirectory + items[0].replace(":", "#") + ".xml"; PrintWriter writer = new PrintWriter(new FileOutputStream(filePath, false)); logWriter.write(filePath + " > Start" + System.lineSeparator()); writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + System.lineSeparator()); writer.write(doc.getElementsByTag("response").first().toString()); writer.close(); logWriter.write(filePath + " > OK" + System.lineSeparator()); logWriter.flush(); } } logWriter.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:test.jackson.JacksonNsgiRegister.java
public static void main(String[] args) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.enable(SerializationFeature.INDENT_OUTPUT); String ngsiRcr = new String(Files.readAllBytes(Paths.get(NGSI_FILE))); RegisterContextRequest rcr = objectMapper.readValue(ngsiRcr, RegisterContextRequest.class); System.out.println(objectMapper.writeValueAsString(rcr)); LinkedHashMap association = (LinkedHashMap) rcr.getContextRegistration().get(0).getContextMetadata().get(0) .getValue();//from w w w .j av a 2 s. co m Association assocObject = objectMapper.convertValue(association, Association.class); System.out.println(assocObject.getAttributeAssociation().get(0).getSourceAttribute()); rcr.getContextRegistration().get(0).getContextRegistrationAttribute().get(1).getContextMetadata().get(0); // System.out.println(rcr.getContextRegistration().get(0).getContextMetadata().get(0).getValue().getClass().getCanonicalName()); // String assocJson = objectMapper.writeValueAsString(association); // Value assocObject = objectMapper.readValue(objectMapper.writeValueAsString(association), Value.class); // System.out.println(association.values().toString()); // System.out.println(assocJson); }
From source file:hk.mcc.utils.applog2es.Main.java
/** * @param args the command line arguments *//*w w w. ja v a2 s. c o m*/ public static void main(String[] args) throws Exception { String pathString = "G:\\tmp\\Archive20160902"; Path path = Paths.get(pathString); try (DirectoryStream<Path> stream = Files.newDirectoryStream(path, "app*.log")) { for (Path entry : stream) { List<AppLog> appLogs = new ArrayList<>(); try (AppLogParser appLogParser = new AppLogParser(Files.newInputStream(entry))) { AppLog nextLog = appLogParser.nextLog(); while (nextLog != null) { // System.out.println(nextLog); nextLog = appLogParser.nextLog(); appLogs.add(nextLog); } post2ES(appLogs); } catch (IOException ex) { Logger.getLogger(AppLogParser.class.getName()).log(Level.SEVERE, null, ex); } } } }
From source file:net.openhft.chronicle.queue.ChronicleReaderMain.java
public static void main(@NotNull String[] args) { final Options options = options(); final CommandLine commandLine = parseCommandLine(args, options); final Consumer<String> messageSink = commandLine.hasOption('l') ? s -> System.out.println(s.replaceAll("\n", "")) : System.out::println; final ChronicleReader chronicleReader = new ChronicleReader().withMessageSink(messageSink) .withBasePath(Paths.get(commandLine.getOptionValue('d'))); configureReader(chronicleReader, commandLine); chronicleReader.execute();/*from w w w . ja v a2s . c o m*/ }
From source file:cc.kave.commons.pointsto.evaluation.runners.ProjectStoreRunner.java
public static void main(String[] args) throws IOException { Path storeDir = Paths.get(args[0]); try (ProjectUsageStore store = new ProjectUsageStore(storeDir)) { List<ICoReTypeName> types = new ArrayList<>(store.getAllTypes()); types.sort(new TypeNameComparator()); System.out.println(/*from w ww. j av a 2 s. c om*/ types.stream().filter(t -> t.getIdentifier().contains("KaVE.")).collect(Collectors.toList())); // if (args.length == 1 || args[1].equals("countFilteredUsages")) { // countFilteredUsages(types, store); // } else if (args[1].equals("countRecvCallSites")) { // countRecvCallSites(types, store); // } // methodPropabilities(types, store); } }
From source file:ListFiles.java
public static void main(String[] args) { try {/*from www . ja v a2 s . c o m*/ Path path = Paths.get("/home"); ListFiles listFiles = new ListFiles(); Files.walkFileTree(path, listFiles); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:listduplicatingfiles.ListDuplicatingFiles.java
public static void main(String[] args) { ListDuplicatingFiles l = new ListDuplicatingFiles(); Path myPath = Paths.get("/home/eli/eli"); l.listDuplicatingFiles(myPath);//from www .ja v a2s.co m }
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. ja va2 s. c om*/ } if (!walk.found) { System.out.println("The file " + searchFile + " was not found!"); } }