List of usage examples for java.io File toPath
public Path toPath()
From source file:herddb.upgrade.ZIPUtils.java
public static List<File> unZip(InputStream fs, File outDir) throws IOException { try (ZipInputStream zipStream = new ZipInputStream(fs, StandardCharsets.UTF_8);) { ZipEntry entry = zipStream.getNextEntry(); List<File> listFiles = new ArrayList<>(); while (entry != null) { if (entry.isDirectory()) { entry = zipStream.getNextEntry(); continue; }//from ww w . ja v a 2 s .c om String normalized = normalizeFilenameForFileSystem(entry.getName()); File outFile = new File(outDir, normalized); File parentDir = outFile.getParentFile(); if (parentDir != null && !parentDir.isDirectory()) { Files.createDirectories(parentDir.toPath()); } listFiles.add(outFile); try (FileOutputStream out = new FileOutputStream(outFile); SimpleBufferedOutputStream oo = new SimpleBufferedOutputStream(out)) { IOUtils.copyLarge(zipStream, oo); } entry = zipStream.getNextEntry(); } return listFiles; } catch (IllegalArgumentException ex) { throw new IOException(ex); } }
From source file:com.bagdemir.eboda.utils.HttpUtils.java
public static File getFileResource(final HttpExchange httpExchange, final File baseDir) { String requestedUri = HttpUtils.getPathVariable(httpExchange); return baseDir.toPath().resolve(requestedUri.substring(1)).toFile(); }
From source file:org.jetbrains.webdemo.examples.ExamplesLoader.java
private static ExampleFile loadExampleFile(String path, String projectUrl, JsonNode fileManifest) throws IOException { try {/* w w w . jav a 2 s .co m*/ String fileName = fileManifest.get("filename").textValue(); boolean modifiable = fileManifest.get("modifiable").asBoolean(); boolean hidden = fileManifest.has("hidden") ? fileManifest.get("hidden").asBoolean() : false; String confType = fileManifest.has("confType") ? fileManifest.get("confType").asText() : null; File file = new File(path); String fileContent = new String(Files.readAllBytes(file.toPath())).replaceAll("\r\n", "\n"); String filePublicId = (projectUrl + "/" + fileName).replaceAll(" ", "%20"); ProjectFile.Type fileType = null; if (!fileManifest.has("type")) { fileType = ProjectFile.Type.KOTLIN_FILE; } else if (fileManifest.get("type").asText().equals("kotlin-test")) { fileType = ProjectFile.Type.KOTLIN_TEST_FILE; } else if (fileManifest.get("type").asText().equals("solution")) { fileType = ProjectFile.Type.SOLUTION_FILE; } else if (fileManifest.get("type").asText().equals("java")) { fileType = ProjectFile.Type.JAVA_FILE; } return new ExampleFile(fileName, fileContent, filePublicId, fileType, confType, modifiable, hidden); } catch (IOException e) { System.err.println("Can't load file: " + e.toString()); return null; } }
From source file:com.thoughtworks.go.agent.common.util.JarUtil.java
private static File extractJarEntry(JarFile jarFile, JarEntry jarEntry, File targetFile) { LOG.debug("Extracting {}!/{} -> {}", jarFile, jarEntry, targetFile); try (InputStream inputStream = jarFile.getInputStream(jarEntry)) { FileUtils.forceMkdirParent(targetFile); Files.copy(inputStream, targetFile.toPath()); return targetFile; } catch (IOException e) { throw new RuntimeException(e); }/*from w w w . j a va 2 s .co m*/ }
From source file:gov.nist.appvet.tool.sigverifier.util.FileUtil.java
public static boolean copyFile(String sourceFilePath, String destFilePath) { if (sourceFilePath == null || destFilePath == null) { return false; }//from w w w. jav a2s.c om File sourceFile = new File(sourceFilePath); if (!sourceFile.exists()) { return false; } File destFile = new File(destFilePath); try { Files.copy(sourceFile.toPath(), destFile.toPath(), StandardCopyOption.REPLACE_EXISTING); } catch (final IOException e) { log.error(e.toString()); return false; } finally { sourceFile = null; destFile = null; } return true; }
From source file:berlin.iconn.persistence.InOutOperations.java
public static void saveSimpleWeights(float[][] weights, Date date, String suffix) throws IOException { mkdir(simpleWeightsFolder);/*www . j a va2s.co m*/ File file = new File(simpleWeightsFolder + "/" + getFileNameByDate(date, suffix, "dat")); ObjectOutputStream oos = new ObjectOutputStream(Files.newOutputStream(file.toPath())); oos.writeObject(weights); oos.close(); }
From source file:edu.umd.umiacs.clip.tools.io.AllFiles.java
public static Stream<File> list(File dir) { return list(dir.toPath()); }
From source file:com.github.blindpirate.gogradle.core.cache.DirectorySnapshot.java
private static String md5(File projectRoot, File targetDir) { List<File> allFilesInDir = IOUtils.listAllDescendents(targetDir).stream().sorted(File::compareTo) .collect(Collectors.toList()); StringBuilder sb = new StringBuilder(); allFilesInDir.forEach(file -> {//from w w w . j av a 2 s . c o m Path relativePath = projectRoot.toPath().relativize(file.toPath()); sb.append(file.isFile() ? "f" : "d").append(File.pathSeparatorChar).append(toUnixString(relativePath)) .append(File.pathSeparatorChar).append(file.length()).append(File.pathSeparatorChar) .append(file.lastModified()).append(File.pathSeparatorChar); }); return DigestUtils.md5Hex(sb.toString()); }
From source file:edu.umd.umiacs.clip.tools.io.AllFiles.java
public static Stream<String> lines(File file) { return lines(file.toPath()); }
From source file:de.teamgrit.grit.report.PlainGenerator.java
/** * This method creates a plain-text file from a SubmissionObj instance. * /*from ww w . j a v a 2 s. com*/ * @param submission * A SubmissionObj containing the information that the content * gets generated from. * @param outdir * the output directory * @param courseName * the name of the Course * @param exerciseName * the name of the exercise * @return The Path to the created plain-text file. * @throws IOException * If something goes wrong when writing. */ public static Path generatePlain(final Submission submission, final Path outdir, String courseName, String exerciseName) throws IOException { final File location = outdir.toFile(); File outputFile = new File(location, submission.getStudent().getName() + ".report.txt"); if (Files.exists(outputFile.toPath(), LinkOption.NOFOLLOW_LINKS)) { Files.delete(outputFile.toPath()); } outputFile.createNewFile(); writeHeader(outputFile, submission, courseName, exerciseName); writeOverview(outputFile, submission); writeTestResult(outputFile, submission); // if there are compile errors, put these in the text file instead of // JUnit Test result CheckingResult checkingResult = submission.getCheckingResult(); if (checkingResult.getCompilerOutput().compilerStreamBroken()) { writeCompilerErrors(outputFile, submission); } else { TestOutput testResults = checkingResult.getTestResults(); if ((testResults.getPassedTestCount() < testResults.getTestCount()) && testResults.getDidTest()) { writeFailedTests(outputFile, submission); } } writeCompilerOutput(outputFile, submission); return outputFile.toPath(); }