List of usage examples for java.nio.file Path toFile
default File toFile()
From source file:com.amazonaws.codepipeline.jenkinsplugin.CompressionTools.java
public static List<File> addFilesToCompress(final Path pathToCompress, final BuildListener listener) throws IOException { final List<File> files = new ArrayList<>(); if (pathToCompress != null) { Files.walkFileTree(pathToCompress, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<Path>() { @Override/*w w w . j av a 2s .c om*/ public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { files.add(file.toFile()); return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(final Path file, final IOException e) throws IOException { if (e != null) { LoggingHelper.log(listener, "Failed to visit file '%s'. Error: %s.", file.toString(), e.getMessage()); LoggingHelper.log(listener, e); throw e; } return FileVisitResult.CONTINUE; } }); } return files; }
From source file:com.goldmansachs.kata2go.tools.utils.TarGz.java
public static void write(InputStream tarGzInputStream, Path outTarGz) throws IOException { GzipCompressorInputStream gzipStream = new GzipCompressorInputStream(tarGzInputStream); FileOutputStream fios = new FileOutputStream(outTarGz.toFile()); int buffersize = 1024; final byte[] buffer = new byte[buffersize]; int n = 0;/*from w ww. j a v a 2s . com*/ while (-1 != (n = gzipStream.read(buffer))) { fios.write(buffer, 0, n); } fios.close(); gzipStream.close(); }
From source file:com.seleniumtests.util.logging.SeleniumRobotLogger.java
public static void reset() throws IOException { SeleniumRobotLogger.testLogs.clear(); // clear log file Appender fileAppender = Logger.getRootLogger().getAppender(FILE_APPENDER_NAME); if (fileAppender != null) { fileAppender.close();//from w w w . j ava 2 s.c o m // wait for handler to be closed WaitHelper.waitForMilliSeconds(200); Logger.getRootLogger().removeAppender(FILE_APPENDER_NAME); } Path logFilePath = Paths.get(outputDirectory, SeleniumRobotLogger.LOG_FILE_NAME).toAbsolutePath(); if (logFilePath.toFile().exists()) { Files.delete(logFilePath); } }
From source file:com.asakusafw.testdriver.DirectIoUtil.java
private static <T> DataModelSourceFactory load0(DataModelDefinition<T> definition, HadoopFileFormat<? super T> format, URL source) throws IOException, InterruptedException { List<String> segments = Arrays.stream(source.getPath().split("/")) //$NON-NLS-1$ .map(String::trim).filter(s -> s.isEmpty() == false).collect(Collectors.toList()); String name;/* w w w .j ava 2 s .c o m*/ if (segments.isEmpty()) { name = "testing.file"; //$NON-NLS-1$ } else { name = segments.get(segments.size() - 1); } Path tmpdir = Files.createTempDirectory("asakusa-"); //$NON-NLS-1$ try (InputStream in = source.openStream()) { Path target = tmpdir.resolve(name); Files.copy(in, target); return load0(definition, format, target.toFile()); } finally { File dir = tmpdir.toFile(); if (FileUtils.deleteQuietly(dir) == false && dir.exists()) { LOG.warn(MessageFormat.format("failed to delete a temporary file: {0}", tmpdir)); } } }
From source file:de.teamgrit.grit.report.PdfConcatenator.java
/** * Write the pdfs to the file./*from ww w . j a va 2 s.c o m*/ * * @param outFile * the out file * @param folderWithPdfs * the folder with pdfs * @throws IOException * Signals that an I/O exception has occurred. */ private static void writeFiles(File outFile, Path folderWithPdfs) throws IOException { FileWriterWithEncoding writer = new FileWriterWithEncoding(outFile, "UTF-8", true); File[] files = folderWithPdfs.toFile().listFiles(); if (files.length > 0) { for (File file : files) { // We only want the the PDFs as input if ("pdf".equals(FilenameUtils.getExtension(file.getName()))) { writer.append("\\includepdf[pages={1-}]{").append(file.getAbsolutePath()).append("} \n"); } } } else { LOGGER.warning("No Reports available in the specified folder: " + folderWithPdfs.toString()); } writer.close(); }
From source file:org.jboss.as.test.manualmode.elytron.CustomCredentialSecurityFactoryTestCase.java
public static Path createJar(String namePrefix, Class<?>... classes) throws IOException { Path testJar = Files.createTempFile(namePrefix, ".jar"); JavaArchive jar = ShrinkWrap.create(JavaArchive.class).addClasses(classes); jar.as(ZipExporter.class).exportTo(testJar.toFile(), true); return testJar; }
From source file:gndata.lib.config.AbstractConfig.java
/** * Loads a configuration of a certain type from a json file. * Note: this method should be used by subclasses in order to implement * a more specific load method./* ww w .jav a2s .com*/ * * @param filePath Path to the json configuration file to read from. * @param cls The class of the configuration type. * * @throws IOException */ protected static <T extends AbstractConfig> T load(String filePath, Class<T> cls) throws IOException { Path tmpPath = Paths.get(filePath); ObjectMapper mapper = new ObjectMapper().enable(ACCEPT_EMPTY_STRING_AS_NULL_OBJECT) .enable(ACCEPT_SINGLE_VALUE_AS_ARRAY).disable(FAIL_ON_UNKNOWN_PROPERTIES); try { T config = mapper.readValue(tmpPath.toFile(), cls); config.setFilePath(tmpPath.toString()); return config; } catch (IOException e) { throw new IOException("Unable to read configuration file: " + filePath, e); } }
From source file:com.basistech.rosette.apimodel.NonNullTest.java
@Parameterized.Parameters(name = "{0}") public static Collection<Object[]> data() throws URISyntaxException, IOException { File dir = new File("src/test/data"); Collection<Object[]> params = new ArrayList<>(); try (DirectoryStream<Path> paths = Files.newDirectoryStream(dir.toPath())) { for (Path file : paths) { if (file.toString().endsWith(".json")) { String className = file.getFileName().toString().replace(".json", ""); params.add(new Object[] { NonNullTest.class.getPackage().getName() + "." + className, file.toFile() }); }/*from w ww. j a va 2 s . c o m*/ } } return params; }
From source file:de.teamgrit.grit.report.PlainGenerator.java
/** * This method creates a plain-text file from a SubmissionObj instance. * // w w w .j a v a 2 s . c o m * @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(); }
From source file:com.goldmansachs.kata2go.tools.utils.TarGz.java
private static void decompressUtil(Path archiveFilePath, Path workingDir, boolean stripParent) throws Exception { try {/*from w ww .jav a 2 s. co m*/ MutableList<String> tarArgs = Lists.mutable.of(UNIX_TAR, "xvzf", archiveFilePath.toFile().getAbsolutePath()); if (stripParent) { tarArgs = tarArgs.with("--strip").with("1"); } Process process = new ProcessBuilder(tarArgs.toList()).directory(workingDir.toFile()).start(); int exitCode = process.waitFor(); if (exitCode != 0) { logStdout(process.getInputStream()); logStdErr(process.getErrorStream()); throw new Exception("Failed to decompress"); } } catch (Exception e) { throw new Exception("Failed to decompress", e); } }