List of usage examples for java.nio.file Path toFile
default File toFile()
From source file:com.spotify.docker.client.messages.AuthConfig.java
private static JsonNode extractAuthJson(final Path configPath) throws IOException { final JsonNode config = MAPPER.readTree(configPath.toFile()); if (config.has("auths")) { return config.get("auths"); }//from w ww . j ava 2s .co m return config; }
From source file:jvmoptions.OptionAnalyzer.java
static Path toJson(String java6, String java7, String java8) throws Exception { Map<String, Map<String, String>> map6 = makeMap(java6); Map<String, Map<String, String>> map7 = makeMap(java7); Map<String, Map<String, String>> map8 = makeMap(java8); Path output = Paths.get("result", filename("json")); JsonFactory factory = new JsonFactory(); JsonGenerator jg = factory.createGenerator(output.toFile(), JsonEncoding.UTF8).useDefaultPrettyPrinter(); jg.writeStartObject();//from www.j a v a2 s . c o m Stream.of(map6, map7, map8).map(Map::keySet).flatMap(Collection::stream).sorted().distinct().forEach(k -> { try { jg.writeFieldName(k); jg.writeStartObject(); Map<String, String> base = pick(k, map8, map7, map6); jg.writeStringField("kind", base.get("kind")); jg.writeStringField("type", base.get("type")); jg.writeStringField("description", base.get("description")); jg.writeStringField("file", base.get("file")); write(jg, "java6", map6.get(k)); write(jg, "java7", map7.get(k)); write(jg, "java8", map8.get(k)); jg.writeEndObject(); } catch (IOException e) { throw new UncheckedIOException(e); } }); jg.writeEndObject(); jg.close(); return output; }
From source file:io.uploader.drive.util.FileUtils.java
public static InputStream getInputStreamWithProgressFilter( InputStreamProgressFilter.StreamProgressCallback callback, long size, Path path) throws FileNotFoundException { return getInputStreamWithProgressFilter(callback, size, new FileInputStream(path.toFile())); }
From source file:objective.taskboard.it.TemplateIT.java
private static File okTemplateWithoutSharedStrings() throws IOException, URISyntaxException { Path temp = Files.createTempFile("Followup", ".xlsm"); ZipUtils.zip(ZipUtils.stream(okTemplate()) .filter(ze -> !StringUtils.endsWith(ze.getName(), "sharedStrings.xml")), temp); return temp.toFile(); }
From source file:com.validation.manager.core.tool.Tool.java
public static File convertToPDF(String content, String filename) throws FileNotFoundException, IOException { Path path = Files.createTempFile("temp-file", ".txt"); File file = path.toFile(); Files.write(path, content.getBytes(StandardCharsets.UTF_8)); return convertToPDF(file, filename); }
From source file:edu.cwru.jpdg.Javac.java
/** * Compiles the java.//from w w w. j a va 2 s . c om */ public static List<String> javac(String basepath, String name, String s) { Path dir = Paths.get(cwd).resolve(basepath); if (Files.notExists(dir)) { create_dir(dir); } Path java = dir.resolve(name + ".java"); Path build = dir.resolve("build"); if (!Files.notExists(build)) { try { FileUtils.deleteDirectory(build.toFile()); } catch (IOException e) { throw new RuntimeException("Couldn't rm -r build dir"); } } create_dir(build); byte[] bytes = s.getBytes(); try { Files.write(java, bytes); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } try { Process p = Runtime.getRuntime() .exec(new String[] { "javac", "-d", build.toString(), java.toString() }); String line; BufferedReader stdout = new BufferedReader(new InputStreamReader(p.getInputStream())); List<String> stdout_lines = new ArrayList<String>(); line = stdout.readLine(); while (line != null) { stdout_lines.add(line); line = stdout.readLine(); } BufferedReader stderr = new BufferedReader(new InputStreamReader(p.getErrorStream())); List<String> stderr_lines = new ArrayList<String>(); line = stderr.readLine(); while (line != null) { stderr_lines.add(line); line = stderr.readLine(); } if (p.waitFor() != 0) { System.err.println(StringUtils.join(stdout_lines, "\n")); System.err.println("-------------------------------------"); System.err.println(StringUtils.join(stderr_lines, "\n")); throw new RuntimeException("javac failed"); } } catch (InterruptedException e) { throw new RuntimeException(e.getMessage()); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } return abs_paths(find_classes(build.toString())); }
From source file:com.twosigma.beakerx.evaluator.EvaluatorTest.java
public static TempFolderFactory getTestTempFolderFactory() { return new TempFolderFactory() { @Override//from w w w . j a va 2 s . c o m public Path createTempFolder() { Path path; try { path = Files.createTempDirectory(EvaluatorBaseTest.TEMP_DIR_NAME); path.toFile().deleteOnExit(); } catch (Exception e) { throw new RuntimeException(e); } return path; } }; }
From source file:com.netflix.nicobar.core.utils.ClassPathUtils.java
/** * Get all of the directory paths in a zip/jar file * @param pathToJarFile location of the jarfile. can also be a zipfile * @return set of directory paths relative to the root of the jar *//*from www . j a va2 s. co m*/ public static Set<Path> getDirectoriesFromJar(Path pathToJarFile) throws IOException { Set<Path> result = new HashSet<Path>(); ZipFile jarfile = new ZipFile(pathToJarFile.toFile()); try { final Enumeration<? extends ZipEntry> entries = jarfile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (entry.isDirectory()) { result.add(Paths.get(entry.getName())); } } jarfile.close(); } finally { IOUtils.closeQuietly(jarfile); } return result; }
From source file:com.ejisto.util.IOUtils.java
public static Collection<File> listJarFiles(Path dir) { return getAllFiles(dir.toFile(), jarExtension); }
From source file:com.example.bot.spring.KitchenSinkController.java
private static DownloadedContent createTempFile(String ext) { String fileName = LocalDateTime.now().toString() + '-' + UUID.randomUUID().toString() + '.' + ext; Path tempFile = KitchenSinkApplication.downloadedContentDir.resolve(fileName); tempFile.toFile().deleteOnExit(); return new DownloadedContent(tempFile, createUri("/downloaded/" + tempFile.getFileName())); }