List of usage examples for java.nio.file FileSystems getDefault
public static FileSystem getDefault()
From source file:MyWatch.java
public void watchRNDir(Path path) throws IOException, InterruptedException { try (WatchService watchService = FileSystems.getDefault().newWatchService()) { path.register(watchService, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_DELETE); while (true) { // retrieve and remove the next watch key final WatchKey key = watchService.take(); for (WatchEvent<?> watchEvent : key.pollEvents()) { final Kind<?> kind = watchEvent.kind(); if (kind == StandardWatchEventKinds.OVERFLOW) { continue; }//from w ww. j ava 2 s .c om final WatchEvent<Path> watchEventPath = (WatchEvent<Path>) watchEvent; final Path filename = watchEventPath.context(); System.out.println(kind + " -> " + filename); } boolean valid = key.reset(); if (!valid) { break; } } } }
From source file:org.lambdamatic.mongodb.apt.testutil.FileAssertion.java
public static FileAssertion assertThat(final String first, String... more) throws FileNotFoundException, IOException { final File file = FileSystems.getDefault().getPath(first, more).toFile(); return new FileAssertion(file); }
From source file:org.apache.druid.query.aggregation.datasketches.hll.GenerateTestData.java
private static void generateSketches() throws Exception { int lgK = 12; String date = "20170101"; Path rawPath = FileSystems.getDefault().getPath("hll_raw.tsv"); Path sketchPath = FileSystems.getDefault().getPath("hll_sketches.tsv"); try (BufferedWriter out1 = Files.newBufferedWriter(rawPath, StandardCharsets.UTF_8)) { try (BufferedWriter out2 = Files.newBufferedWriter(sketchPath, StandardCharsets.UTF_8)) { Random rand = ThreadLocalRandom.current(); int key = 0; for (int i = 0; i < 100; i++) { HllSketch sketch = new HllSketch(lgK); String dimension = Integer.toString(rand.nextInt(10) + 1); writeRawRecord(out1, date, dimension, key); sketch.update(key++);//from w w w . j ava 2 s . co m writeRawRecord(out1, date, dimension, key); sketch.update(key++); writeSketchRecord(out2, date, dimension, sketch); } } } }
From source file:us.colloquy.util.EpubExtractor.java
public static void getURIForAllLetters(Set<DocumentPointer> uriList, String letterDirectory, boolean useOnlyNumber) { Path pathToLetters = FileSystems.getDefault().getPath(letterDirectory); List<Path> results = new ArrayList<>(); int maxDepth = 6; try (Stream<Path> stream = Files.find(pathToLetters, maxDepth, (path, attr) -> String.valueOf(path).endsWith(".ncx"))) { stream.forEach(results::add);//w ww . ja v a2 s. co m // String joined = stream // .sorted() // .map(String::valueOf) // .collect(Collectors.joining("; ")); // // System.out.println("\nFound: " + joined); } catch (IOException e) { e.printStackTrace(); } System.out.println("files: " + results.size()); try { for (Path res : results) { Path parent = res.getParent(); // System.out.println("---------------------------------------------"); // System.out.println(parent.toString()); //use jsoup to list all files that contain something useful Document doc = Jsoup.parse(res.toFile(), "UTF-8"); String title = ""; for (Element element : doc.getElementsByTag("docTitle")) { //Letter letter = new Letter(); // StringBuilder content = new StringBuilder(); for (Element child : element.children()) { title = child.text(); // System.out.println("Title: " + title); } } for (Element element : doc.getElementsByTag("avantitul")) { for (Element child : element.children()) { String label = child.text(); if (StringUtils.isNotEmpty(label)) { if (label.matches( " ? ? .*")) { System.out.println("------------------ " + label); } } } } for (Element element : doc.getElementsByTag("navPoint")) { //Letter letter = new Letter(); // StringBuilder content = new StringBuilder(); for (Element child : element.children()) { String label = child.text(); if (StringUtils.isNotEmpty(label)) { if (label.matches("?")) { System.out.println("------------------ " + "?" + " -------------------"); } else if (label.contains(" ?")) { break; } String url = child.getElementsByTag("content").attr("src"); if (label.matches(".*\\d{1,3}.*[?--?A-Za-z]+.*") && StringUtils.isNotEmpty(url)) { DocumentPointer documentPointer = new DocumentPointer( parent.toString() + File.separator + url.replaceAll("#.*", ""), title); uriList.add(documentPointer); // System.out.println("nav point: " + label + " src " + parent.toString() // + System.lineSeparator() + url.replaceAll("#.*","")); } else if (label.matches(".*\\d{1,3}.*") && StringUtils.isNotEmpty(url) && useOnlyNumber) { DocumentPointer documentPointer = new DocumentPointer( parent.toString() + File.separator + url.replaceAll("#.*", ""), title); uriList.add(documentPointer); // System.out.println("nav point: " + label + " src " + parent.toString() // + System.lineSeparator() + url.replaceAll("#.*","")); } else { // System.out.println("nav point: " + label + " src " + child.getElementsByTag("content").attr("src")); } } } } } } catch (Exception e) { e.printStackTrace(); } // System.out.println("Size: " + uriList.size()); // for (DocumentPointer pointer : uriList) // { // //parse and // System.out.println(pointer.getSourse() + "\t" + pointer.getUri()); // } }
From source file:io.druid.query.aggregation.datasketches.tuple.GenerateTestData.java
private static void generateSketches() throws Exception { Path path = FileSystems.getDefault().getPath("array_of_doubles_sketch_data.tsv"); try (BufferedWriter out = Files.newBufferedWriter(path, StandardCharsets.UTF_8)) { Random rand = new Random(); int key = 0; for (int i = 0; i < 20; i++) { ArrayOfDoublesUpdatableSketch sketch = new ArrayOfDoublesUpdatableSketchBuilder() .setNominalEntries(1024).build(); sketch.update(key++, new double[] { 1 }); sketch.update(key++, new double[] { 1 }); out.write("2015010101"); out.write('\t'); out.write("product_" + (rand.nextInt(10) + 1)); out.write('\t'); out.write(Base64.encodeBase64String(sketch.compact().toByteArray())); out.newLine();//from ww w .j a v a2 s . co m } } }
From source file:org.apache.druid.query.aggregation.datasketches.tuple.GenerateTestData.java
private static void generateSketches() throws Exception { Path path = FileSystems.getDefault().getPath("array_of_doubles_sketch_data.tsv"); try (BufferedWriter out = Files.newBufferedWriter(path, StandardCharsets.UTF_8)) { Random rand = ThreadLocalRandom.current(); int key = 0; for (int i = 0; i < 20; i++) { ArrayOfDoublesUpdatableSketch sketch = new ArrayOfDoublesUpdatableSketchBuilder() .setNominalEntries(1024).build(); sketch.update(key++, new double[] { 1 }); sketch.update(key++, new double[] { 1 }); out.write("2015010101"); out.write('\t'); out.write("product_" + (rand.nextInt(10) + 1)); out.write('\t'); out.write(Base64.encodeBase64String(sketch.compact().toByteArray())); out.newLine();//from w ww . jav a2 s .c om } } }
From source file:com.elemenopy.backupcopy.config.BackupConfig.java
public static BackupConfig loadDefault() { logger.info("Looking for {} at root of classpath...", DEFAULT_CONFIG_FILE); BackupConfig config = loadFromClasspath(DEFAULT_CONFIG_FILE); if (config == null) { File home = FileSystems.getDefault().getPath(System.getProperty("user.home"), ".backupCopy").toFile(); logger.info("Config not found in classpath. Looking in {}...", home.getAbsolutePath()); config = loadFromFileSystem(new File(home, DEFAULT_CONFIG_FILE).getAbsolutePath()); }//www. ja v a2s . c o m if (config == null) { File workingDir = new File(System.getProperty("user.dir")); logger.info("Config not found in user home. Looking in {}...", workingDir.getAbsolutePath()); config = loadFromFileSystem(new File(workingDir, DEFAULT_CONFIG_FILE).getAbsolutePath()); } if (config == null) logger.warn("Config file {} not found at classpath root, working dir, or in user home directory.", DEFAULT_CONFIG_FILE); return config; }
From source file:SecurityWatch.java
public void watchVideoCamera(Path path) throws IOException, InterruptedException { watchService = FileSystems.getDefault().newWatchService(); register(path, StandardWatchEventKinds.ENTRY_CREATE); OUTERMOST: while (true) { final WatchKey key = watchService.poll(11, TimeUnit.SECONDS); if (key == null) { System.out.println("The video camera is jammed - security watch system is canceled!"); break; } else {//from ww w .j a v a 2 s . com for (WatchEvent<?> watchEvent : key.pollEvents()) { final Kind<?> kind = watchEvent.kind(); if (kind == StandardWatchEventKinds.OVERFLOW) { continue; } if (kind == StandardWatchEventKinds.ENTRY_CREATE) { //get the filename for the event final WatchEvent<Path> watchEventPath = (WatchEvent<Path>) watchEvent; final Path filename = watchEventPath.context(); final Path child = path.resolve(filename); if (Files.probeContentType(child).equals("image/jpeg")) { //print it out the video capture time SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss"); System.out.println("Video capture successfully at: " + dateFormat.format(new Date())); } else { System.out.println("The video camera capture format failed! This could be a virus!"); break OUTERMOST; } } } boolean valid = key.reset(); if (!valid) { break; } } } watchService.close(); }
From source file:SecurityWatch.java
public void watchVideoCamera(Path path) throws IOException, InterruptedException { watchService = FileSystems.getDefault().newWatchService(); register(path, StandardWatchEventKinds.ENTRY_CREATE); OUTERMOST: while (true) { final WatchKey key = watchService.poll(); if (key == null) { System.out.println("The video camera is jammed - security watch system is canceled!"); break; } else {/* ww w . jav a 2 s. c o m*/ for (WatchEvent<?> watchEvent : key.pollEvents()) { final Kind<?> kind = watchEvent.kind(); if (kind == StandardWatchEventKinds.OVERFLOW) { continue; } if (kind == StandardWatchEventKinds.ENTRY_CREATE) { //get the filename for the event final WatchEvent<Path> watchEventPath = (WatchEvent<Path>) watchEvent; final Path filename = watchEventPath.context(); final Path child = path.resolve(filename); if (Files.probeContentType(child).equals("image/jpeg")) { //print it out the video capture time SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss"); System.out.println("Video capture successfully at: " + dateFormat.format(new Date())); } else { System.out.println("The video camera capture format failed! This could be a virus!"); break OUTERMOST; } } } boolean valid = key.reset(); if (!valid) { break; } } } watchService.close(); }
From source file:net.sourceforge.pmd.docs.RuleSetResolverTest.java
@Test public void resolveAllRulesets() { Path basePath = FileSystems.getDefault().getPath(".").resolve("..").toAbsolutePath().normalize(); List<String> additionalRulesets = GenerateRuleDocsCmd.findAdditionalRulesets(basePath); filterRuleSets(additionalRulesets);// ww w .ja va 2 s.co m RuleSetFactory ruleSetFactory = new RuleSetFactory(); for (String filename : additionalRulesets) { try { ruleSetFactory.createRuleSet(filename); } catch (RuntimeException | RuleSetNotFoundException e) { fail("Couldn't load ruleset " + filename + ": " + e.getMessage()); } } }