List of usage examples for java.nio.file FileSystems getDefault
public static FileSystem getDefault()
From source file:com.acmutv.ontoqa.tool.io.IOManagerTest.java
/** * Tests directory listing with filter./*from w w w.j a v a 2 s . c o m*/ */ @Test public void test_listAllFiles_withExtension() throws IOException { String directory = IOManagerTest.class.getResource("/tool/io/").getPath(); List<Path> actual = IOManager.allFiles(directory, "*.txt"); actual.sort(Comparator.naturalOrder()); List<Path> expected = new ArrayList<>(); expected.add( FileSystems.getDefault().getPath(IOManagerTest.class.getResource("/tool/io/sample.txt").getPath())); expected.sort(Comparator.naturalOrder()); Assert.assertEquals(expected, actual); }
From source file:uk.gov.gchq.gaffer.miniaccumulocluster.MiniAccumuloClusterController.java
protected void watchShutdown() { LOGGER.info("Watching Shutdown File " + clusterPath + "/" + SHUTDOWN_FILENAME); try {//from w w w. java 2 s.c o m WatchService watcher = FileSystems.getDefault().newWatchService(); clusterPath.register(watcher, ENTRY_CREATE); OUTER: while (true) { WatchKey key; try { key = watcher.take(); } catch (final InterruptedException e) { return; } for (final WatchEvent<?> event : key.pollEvents()) { final WatchEvent.Kind<?> kind = event.kind(); if (kind == OVERFLOW) { continue; } final WatchEvent<Path> ev = (WatchEvent<Path>) event; final Path filename = ev.context(); LOGGER.debug("Filename changed " + filename); if (filename.toString().equals(SHUTDOWN_FILENAME)) { MiniAccumuloClusterController.this.stop(); break OUTER; } } boolean valid = key.reset(); if (!valid) { break; } } LOGGER.info("Finished Watching Shutdown"); } catch (final IOException e) { LOGGER.error("Failed to watch shutdown", e); } }
From source file:org.commonjava.test.compile.CompilerFixture.java
public List<File> scan(final File directory, final String pattern) throws IOException { final PathMatcher matcher = FileSystems.getDefault() .getPathMatcher("glob:" + directory.getCanonicalPath() + "/" + pattern); final List<File> sources = new ArrayList<>(); Files.walkFileTree(directory.toPath(), new SimpleFileVisitor<Path>() { @Override/*from w w w. j av a 2 s . c o m*/ public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { if (matcher.matches(file)) { sources.add(file.toFile()); } return FileVisitResult.CONTINUE; } }); return sources; }
From source file:cpd3314.project.CPD3314ProjectTest.java
@Test public void testSortAAndLimitAndOutput() throws Exception { System.out.println("main"); String[] args = { "-sort=A", "-o=a", "-limit=10" }; CPD3314Project.main(args);//from ww w. j ava 2 s. co m File expected = FileSystems.getDefault().getPath("testFiles", "sortA.xml").toFile(); File result = new File("a.xml"); assertTrue("Output File Doesn't Exist", result.exists()); assertXMLFilesEqual(expected, result); }
From source file:com.liferay.sync.engine.SyncSystemTest.java
protected void addFile(Path testFilePath, JsonNode stepJsonNode) throws Exception { SyncSite syncSite = getSyncSite(stepJsonNode); String dependency = getString(stepJsonNode, "dependency"); Path dependencyFilePath = getDependencyFilePath(testFilePath, dependency); FileSystem fileSystem = FileSystems.getDefault(); dependency = getString(stepJsonNode, "target", dependency.replace("common" + fileSystem.getSeparator(), "")); Path targetFilePath = Paths.get(FileUtil.getFilePathName(syncSite.getFilePathName(), dependency)); Files.copy(dependencyFilePath, targetFilePath); }
From source file:business.services.FileService.java
public HttpEntity<InputStreamResource> download(Long id) { try {/*w ww. ja v a 2s . com*/ File attachment = fileRepository.findOne(id); if (attachment == null) { throw new FileNotFound(); } FileSystem fileSystem = FileSystems.getDefault(); Path path = fileSystem.getPath(uploadPath, attachment.getFilename()); InputStream input = new FileInputStream(path.toFile()); InputStreamResource resource = new InputStreamResource(input); HttpHeaders headers = new HttpHeaders(); if (attachment.getMimeType() != null) { headers.setContentType(MediaType.valueOf(attachment.getMimeType())); } else { headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); } headers.set("Content-Disposition", "attachment; filename=" + attachment.getName().replace(" ", "_")); HttpEntity<InputStreamResource> response = new HttpEntity<InputStreamResource>(resource, headers); return response; } catch (IOException e) { log.error(e); throw new FileDownloadError(); } }
From source file:org.openeos.tools.maven.plugins.GenerateEntitiesMojo.java
private Set<File> checkForLocalFiles(File file) throws IOException, URISyntaxException { final Set<File> result = new TreeSet<File>(); final PathMatcher matcher = FileSystems.getDefault() .getPathMatcher("glob:" + file.getAbsolutePath() + "/" + searchpath); SimpleFileVisitor<Path> fileVisitor = new SimpleFileVisitor<Path>() { @Override/* w w w . j ava2 s. c om*/ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (matcher.matches(file)) { result.add(file.toFile()); } return FileVisitResult.CONTINUE; } }; Files.walkFileTree(file.toPath(), fileVisitor); return result; }
From source file:com.yahoo.parsec.gradle.utils.FileUtils.java
/** * Find files in path.//www . j a v a 2 s. c o m * * @param path find path * @param pattern find patttern * @return a set of path * @throws IOException IOException */ public Set<Path> findFiles(String path, String pattern) throws IOException { try { Set<Path> paths = new HashSet<>(); PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher(pattern); Files.walkFileTree(Paths.get(path), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path filePath, BasicFileAttributes attrs) { if (pathMatcher.matches(filePath.getFileName())) { paths.add(filePath); } return FileVisitResult.CONTINUE; } }); return paths; } catch (IOException e) { throw e; } }
From source file:cpd3314.project.CPD3314ProjectTest.java
@Test public void testSortIAndLimitAndOutput() throws Exception { System.out.println("main"); String[] args = { "-sort=I", "-o=i", "-limit=10" }; CPD3314Project.main(args);/*ww w . j a v a 2 s . c o m*/ File expected = FileSystems.getDefault().getPath("testFiles", "sortI.xml").toFile(); File result = new File("i.xml"); assertTrue("Output File Doesn't Exist", result.exists()); assertXMLFilesEqual(expected, result); }
From source file:dpfmanager.shell.interfaces.gui.component.dessign.DessignView.java
private void addTreeView() { // Root node (my computer) CheckBoxTreeItem<String> rootNode = new CheckBoxTreeItem<>(getHostName(), new ImageView(new Image("images/computer.png"))); checkTreeView = new CheckTreeView<>(rootNode); rootNode.addEventHandler(TreeItem.<Object>branchExpandedEvent(), new ExpandEventHandler(checkTreeView)); rootNode.addEventHandler(TreeItem.<Object>branchCollapsedEvent(), new CollapseEventHandler()); // Root items Iterable<Path> rootDirectories = FileSystems.getDefault().getRootDirectories(); for (Path name : rootDirectories) { if (Files.isDirectory(name)) { FilePathTreeItem treeNode = new FilePathTreeItem(name); rootNode.getChildren().add(treeNode); }//from w w w. j ava 2 s .c o m } rootNode.setExpanded(true); // Add data and add to gui treeViewHBox.getChildren().clear(); treeViewHBox.getChildren().add(checkTreeView); HBox.setHgrow(checkTreeView, Priority.ALWAYS); }