List of usage examples for java.nio.file Path toFile
default File toFile()
From source file:com.preferanser.server.client.DealUploader.java
private List<File> discoverJsonFiles(String jsonDealsPath) throws URISyntaxException, IOException { final List<File> jsonFiles = Lists.newArrayList(); Path path = Paths.get(DealUploader.class.getResource(jsonDealsPath).toURI()); Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override/*from w w w . ja v a2 s . c om*/ public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException { File file = path.toFile(); if (attrs.isRegularFile() && file.getName().endsWith(".json")) jsonFiles.add(file); return super.visitFile(path, attrs); } }); return jsonFiles; }
From source file:de.learnlib.alex.data.dao.FileDAOImpl.java
@Override public void create(User user, Long projectId, InputStream uploadedInputStream, FormDataContentDisposition fileDetail) throws IllegalStateException, IOException, NotFoundException { projectDAO.getByID(user.getId(), projectId); // access check Path uploadedDirectoryLocation = Paths.get(getUploadsDir(user, projectId)); File uploadDirectory = uploadedDirectoryLocation.toFile(); if (!uploadDirectory.exists()) { uploadDirectory.mkdir();//from www. ja v a2 s . c om } if (!uploadDirectory.isDirectory()) { throw new IllegalStateException("Could not find the right directory to upload the file."); } Path uploadedFileLocation = Paths.get(uploadedDirectoryLocation.toString(), fileDetail.getFileName()); if (uploadedFileLocation.toFile().exists()) { throw new IllegalStateException("The file already exists."); } writeToFile(uploadedInputStream, uploadedFileLocation.toString()); }
From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.SpinnakerProfile.java
/** * @param node is the node to find required files in. * @return the list of files required by the node to function. *///from w w w .ja v a 2 s . c om List<String> processRequiredFiles(Node node) { List<String> files = new ArrayList<>(); Consumer<Node> fileFinder = n -> files.addAll(n.localFiles().stream().map(f -> { try { f.setAccessible(true); String fPath = (String) f.get(n); if (fPath == null) { return null; } File fFile = new File(fPath); String fName = fFile.getName(); // Hash the path to uniquely flatten all files into the output directory Path newName = Paths.get(spinnakerOutputDependencyPath, Math.abs(fPath.hashCode()) + "-" + fName); File parent = newName.toFile().getParentFile(); if (!parent.exists()) { parent.mkdirs(); } else if (fFile.getParent().equals(parent.toString())) { // Don't move paths that are already in the right folder return fPath; } Files.copy(Paths.get(fPath), newName, REPLACE_EXISTING); f.set(n, newName.toString()); return newName.toString(); } catch (IllegalAccessException e) { throw new RuntimeException("Failed to get local files for node " + n.getNodeName(), e); } catch (IOException e) { throw new HalException( new ProblemBuilder(FATAL, "Failed to backup user file: " + e.getMessage()).build()); } finally { f.setAccessible(false); } }).filter(Objects::nonNull).collect(Collectors.toList())); node.recursiveConsume(fileFinder); return files; }
From source file:com.samsung.sjs.ABackendTest.java
/** * Prefix the specified JS file with some of the testing primitives we assume, * placing the output in tmpdir and returning the resulting File. *//* w ww.j a va 2s .com*/ public File prefixJS(Path tmpdir, File js) throws IOException, FileNotFoundException { File result = File.createTempFile("___", ".js", tmpdir.toFile()); OutputStream out = new FileOutputStream(result); IOUtils.write("function assert(cond) { if (!cond) { throw Error(); } }\n\n", out); IOUtils.write("function print(s) { console.log(s); }\n\n", out); IOUtils.write("function printInt(s) { console.log(s); }\n\n", out); IOUtils.write("function printString(s) { console.log(s); }\n\n", out); IOUtils.write("function printFloat(s) { console.log(s); }\n\n", out); IOUtils.write("function printFloat10(s) { console.log(s.toFixed(10)); }\n\n", out); IOUtils.write("function itofp(s) { return s; }\n\n", out); IOUtils.write("function string_of_int(x) { return x.toString(); }\n\n", out); IOUtils.write("var TyHint = {};\n\n", out); IOUtils.copy(new FileReader(js), out); return result; }
From source file:edu.wustl.mir.erl.ihe.xdsi.util.Plug.java
/** * Gets the value of the {@link #strng variable string} after all * instances of ${key} where an entry for "key" exists in the map are * replaced with the corresponding value from the map. Also writes the * string to a file using UTF-8 encoding. * @param pathToFile {@link java.nio.file.Path Path} to write the string to. * @param append boolean, if true string will be appended to file rather than * overwriting it./*from www . j a v a2s . c o m*/ * @return The same string written to the file, in case you want it for * anything * @throws Exception on error creating or writing to file. */ public String get(Path pathToFile, boolean append) throws Exception { String out = StrSubstitutor.replace(strng, map); FileUtils.writeStringToFile(pathToFile.toFile(), out, "UTF-8", append); return out; }
From source file:io.divolte.server.hdfs.HdfsFlusherTest.java
private void verifyAvroFile(List<Record> expected, Schema schema, Path avroFile) { final List<Record> result = StreamSupport .stream(readAvroFile(schema, avroFile.toFile()).spliterator(), false).collect(Collectors.toList()); assertEquals(expected, result);/* w ww . j a va 2 s .c o m*/ }
From source file:io.github.swagger2markup.MarkdownConverterTest.java
@Test public void testWithInterDocumentCrossReferences() throws IOException, URISyntaxException { //Given/* w w w . j a v a2 s . co m*/ Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); Path outputDirectory = Paths.get("build/test/markdown/idxref"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder().withMarkupLanguage(MarkupLanguage.MARKDOWN) .withInterDocumentCrossReferences().build(); Swagger2MarkupConverter.from(file).withConfig(config).build().toFolder(outputDirectory); //Then String[] files = outputDirectory.toFile().list(); assertThat(files).hasSize(4).containsAll(expectedFiles); Path expectedFilesDirectory = Paths .get(AsciidocConverterTest.class.getResource("/expected/markdown/idxref").toURI()); DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testWithInterDocumentCrossReferences.html"); }
From source file:de.monticore.codegen.GeneratorTest.java
/** * Creates an Iterable over all the JavaFileObjects contained in a given * directory.//from ww w . ja v a2 s . c om * * @param sourceCodePath the directory from which JavaFileObjects are to be * retrieved * @param fileManager the StandardJavaFileManager to be used for the * JavaFileObject creation * @return the JavaFileObjects contained in the given directory */ protected Iterable<? extends JavaFileObject> getJavaFileObjects(Path sourceCodePath, StandardJavaFileManager fileManager) { Collection<File> files = FileUtils.listFiles(sourceCodePath.toFile(), new String[] { "java" }, true); return fileManager.getJavaFileObjects(files.toArray(new File[files.size()])); }
From source file:io.github.swagger2markup.MarkdownConverterTest.java
@Test public void testToFolder() throws IOException, URISyntaxException { //Given//from w w w. java2 s . c o m Path file = Paths.get(MarkdownConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); Path outputDirectory = Paths.get("build/test/markdown/to_folder"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder().withMarkupLanguage(MarkupLanguage.MARKDOWN) .build(); Swagger2MarkupConverter.from(file).withConfig(config).build().toFolder(outputDirectory); //Then String[] files = outputDirectory.toFile().list(); assertThat(files).hasSize(4).containsAll(expectedFiles); Path expectedFilesDirectory = Paths .get(AsciidocConverterTest.class.getResource("/expected/markdown/to_folder").toURI()); DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testToFolder.html"); }