List of usage examples for java.nio.file FileSystems getDefault
public static FileSystem getDefault()
From source file:com.playonlinux.filesystem.DirectoryWatcher.java
public DirectoryWatcher(ExecutorService executorService, Path observedDirectory) { try {//w ww.j av a 2 s . c o m validate(observedDirectory); this.observedDirectory = observedDirectory; this.watcher = FileSystems.getDefault().newWatchService(); observedDirectory.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY); executorService.submit(this::run); } catch (IOException e) { throw new RuntimeException( String.format("Unable to create watcher for %s", observedDirectory.toString())); } }
From source file:cane.brothers.e4.commander.utils.PathUtils.java
/** * @param path//from w ww . j a va2 s. c o m * @return */ public static String getAttributesString(Path path) { Set<String> views = FileSystems.getDefault().supportedFileAttributeViews(); if (views.contains("posix")) { //$NON-NLS-1$ return getPosixAttributesString(path); } else { return getDosAttributesString(path); } }
From source file:com.netflix.spinnaker.halyard.config.services.v1.GenerateService.java
public void generateConfig(NodeReference nodeReference) { for (SpinnakerComponent component : spinnakerComponents) { FileSystem defaultFileSystem = FileSystems.getDefault(); AtomicFileWriter writer = null;/* w w w . j a v a2 s. c o m*/ Path path = defaultFileSystem.getPath(spinnakerOutputPath, component.getConfigFileName()); log.info("Writing profile to " + path); try { writer = new AtomicFileWriter(path); writer.write(component.getFullConfig(nodeReference)); writer.commit(); } catch (IOException ioe) { ioe.printStackTrace(); throw new HalconfigException( new ProblemBuilder(Problem.Severity.FATAL, "Failed to write config for component " + component.getComponentName() + ": " + ioe.getMessage()).build()); } finally { if (writer != null) { writer.close(); } } } }
From source file:org.apache.druid.query.aggregation.datasketches.tuple.GenerateTestData.java
private static void generateBucketTestData() throws Exception { double meanTest = 10; double meanControl = 10.2; Path path = FileSystems.getDefault().getPath("bucket_test_data.tsv"); try (BufferedWriter out = Files.newBufferedWriter(path, StandardCharsets.UTF_8)) { Random rand = ThreadLocalRandom.current(); for (int i = 0; i < 1000; i++) { writeBucketTestRecord(out, "test", i, rand.nextGaussian() + meanTest); writeBucketTestRecord(out, "control", i, rand.nextGaussian() + meanControl); }/*from w w w . ja v a 2 s . com*/ } }
From source file:org.apache.fineract.infrastructure.dataexport.helper.FileHelper.java
/** * Creates a directory by creating all nonexistent parent directories first * /* w ww . j a v a2s . co m*/ * @param baseDirPathString -- the path string or initial part of the path string * @param morePathString -- additional strings to be joined to form the path string **/ public static Path createDirectories(final String baseDirPathString, String... morePathString) { Path directoryPath = null; try { // convert path string to Path object Path fullPath = FileSystems.getDefault().getPath(baseDirPathString, morePathString); // create the directory directoryPath = Files.createDirectories(fullPath); } catch (Exception exception) { logger.error(exception.getMessage(), exception); } return directoryPath; }
From source file:org.cyclop.test.AbstractTestCase.java
private static void setupHistory() throws Exception { Path tempPath = FileSystems.getDefault().getPath("target", "cyclop-history-test"); rmdir(tempPath);// w ww . ja va 2 s .com Files.createDirectory(tempPath); System.getProperties().setProperty("fileStore.folder", tempPath.toString()); }
From source file:es.molabs.io.utils.test.FileWatcherRunnableTest.java
@Test public void testEntryCreate() throws Throwable { URL file = getClass().getResource("/es/molabs/io/utils/test/filewatcher/"); // Deletes the file if already exists File newFile = new File(file.getFile() + File.separator + "test-create.txt"); if (newFile.exists()) newFile.delete();//from w w w . j ava 2 s . c om WatchService watchService = FileSystems.getDefault().newWatchService(); FileWatcherHandler handler = Mockito.mock(FileWatcherHandler.class); FileWatcherRunnable fileWatcherRunnable = new FileWatcherRunnable(watchService, handler); fileWatcherRunnable.addFile(file); executor.submit(fileWatcherRunnable); // Creates the file newFile.createNewFile(); // Waits the refresh time Thread.sleep(fileWatcherRunnable.getRefreshTime() + REFRESH_MARGIN); // Checks that the event handler has been called one time Mockito.verify(handler, Mockito.times(1)).entryCreate(Mockito.any()); // Stops the service watchService.close(); }
From source file:nl.verheulconsultants.monitorisp.service.Utilities.java
/** * Get the test directory for storing the session data. * * @return the path//w ww . j a va2 s. c om */ public static Path getTestHomeDir() { return FileSystems.getDefault().getPath(TESTHOMEDIR); }
From source file:net.sourceforge.pmd.docs.SidebarGeneratorTest.java
@Test public void testSidebar() throws IOException { Map<Language, List<RuleSet>> rulesets = new HashMap<>(); RuleSet ruleSet1 = new RuleSetFactory().createNewRuleSet("test", "test", "bestpractices.xml", Collections.emptyList(), Collections.emptyList(), Collections.emptyList()); RuleSet ruleSet2 = new RuleSetFactory().createNewRuleSet("test2", "test", "codestyle.xml", Collections.emptyList(), Collections.emptyList(), Collections.emptyList()); rulesets.put(LanguageRegistry.findLanguageByTerseName("java"), Arrays.asList(ruleSet1, ruleSet2)); rulesets.put(LanguageRegistry.findLanguageByTerseName("ecmascript"), Arrays.asList(ruleSet1)); SidebarGenerator generator = new SidebarGenerator(writer, FileSystems.getDefault().getPath("..")); List<Map<String, Object>> result = generator.generateRuleReferenceSection(rulesets); DumperOptions options = new DumperOptions(); options.setDefaultFlowStyle(FlowStyle.BLOCK); if (SystemUtils.IS_OS_WINDOWS) { options.setLineBreak(LineBreak.WIN); }/* w ww .j a va 2s.c om*/ String yaml = new Yaml(options).dump(result); String expected = MockedFileWriter.normalizeLineSeparators(IOUtils .toString(SidebarGeneratorTest.class.getResourceAsStream("sidebar.yml"), StandardCharsets.UTF_8)); assertEquals(expected, yaml); }
From source file:com.liferay.sync.engine.util.FileUtil.java
public static String getFilePathName(String first, String... more) { FileSystem fileSystem = FileSystems.getDefault(); Path filePath = fileSystem.getPath(first, more); return filePath.toString(); }