Example usage for java.io File toPath

List of usage examples for java.io File toPath

Introduction

In this page you can find the example usage for java.io File toPath.

Prototype

public Path toPath() 

Source Link

Document

Returns a Path java.nio.file.Path object constructed from this abstract path.

Usage

From source file:eu.diversify.disco.experiments.testing.Tester.java

private String readContentOf(File readme) throws IOException {
    final StringBuffer buffer = new StringBuffer();
    for (String line : Files.readAllLines(readme.toPath(), Charset.defaultCharset())) {
        buffer.append(line);// www  .  j  a  v  a 2s.c o m
    }
    return buffer.toString();
}

From source file:jp.toastkid.script.Controller.java

/**
 * Save script to file.//  w ww  . jav a2s  . c o  m
 */
@FXML
private void saveScript() {
    try {
        if (new File(scriptName.getText()) != null) {
            final File file = new File(
                    "script" + Language.extension(scriptLanguage.getSelectionModel().getSelectedItem()));
            Files.createFile(file.toPath());
            scriptName.setText(file.getAbsolutePath());
        }
        final File file = new File(scriptName.getText());
        Files.write(file.toPath(), scripterInput.getText().getBytes("UTF-8"), StandardOpenOption.WRITE);
    } catch (final IOException e) {
        LOGGER.error("Caught error.", e);
    }
}

From source file:it.polimi.diceH2020.launcher.utility.FileUtility.java

public @NotNull File createTempZip(@NotNull Map<String, String> inputFiles) throws IOException {
    File folder = Files.createTempDirectory(settings.getWorkingDirectory().toPath(), null).toFile();
    policy.markForDeletion(folder);//  ww  w.ja  va  2 s.co  m

    List<File> tempFiles = new LinkedList<>();
    for (Map.Entry<String, String> entry : inputFiles.entrySet()) {
        File tmp = new File(folder, entry.getKey());
        if (tmp.getParentFile().mkdirs() || tmp.getParentFile().isDirectory()) {
            tempFiles.add(tmp);
            Files.write(tmp.toPath(), Compressor.decompress(entry.getValue()).getBytes(),
                    StandardOpenOption.CREATE_NEW);
        } else
            throw new IOException("could not prepare directory structure for ZIP file");
    }

    String fileName = String.format("%s.zip", folder.getName());
    File zip = new File(settings.getWorkingDirectory(), fileName);
    policy.markForDeletion(zip);
    zipFolder(folder, zip);

    tempFiles.forEach(policy::delete);
    policy.delete(folder);

    return zip;
}

From source file:net.codestory.simplelenium.driver.Downloader.java

protected void downloadZip(String driverName, String url, File targetZip) {
    if (targetZip.exists()) {
        if (targetZip.length() > 0) {
            return;
        }/*from  w  ww.  ja v  a2 s.c  om*/
        targetZip.delete();
    }

    System.out.printf("Downloading %s from %s...%n", driverName, url);

    File zipTemp = new File(targetZip.getAbsolutePath() + ".temp");
    zipTemp.getParentFile().mkdirs();

    try (InputStream input = URI.create(url).toURL().openStream()) {
        Files.copy(input, zipTemp.toPath());
    } catch (IOException e) {
        throw new IllegalStateException(
                "Unable to download " + driverName + " from " + url + " to " + targetZip, e);
    }

    if (!zipTemp.renameTo(targetZip)) {
        throw new IllegalStateException(String.format("Unable to rename %s to %s", zipTemp.getAbsolutePath(),
                targetZip.getAbsolutePath()));
    }
}

From source file:com.itemanalysis.jmetrik.file.JmetrikFileWriter.java

public JmetrikFileWriter(File file, LinkedHashMap<VariableName, VariableAttributes> variableAttributeMap) {
    this(file.toPath(), variableAttributeMap, false);
}

From source file:io.github.swagger2markup.Swagger2MarkupMojo.java

private void swaggerToMarkup(Swagger2MarkupConverter converter, boolean inputIsLocalFolder) {
    if (outputFile != null) {
        Path useFile = outputFile.toPath();
        /*//www . j  ava  2 s  .c  o  m
         * If user has specified input folder with multiple files to convert,
         * and has specified a single output file, then route all conversions
         * into one file under each 'new' sub-directory, which corresponds to
         * each input file.
         * Otherwise, specifying the output file with an input DIRECTORY means
         * last file converted wins.
         */
        if (inputIsLocalFolder) {
            if (outputDir != null) {
                File effectiveOutputDir = outputDir;
                effectiveOutputDir = getEffectiveOutputDirWhenInputIsAFolder(converter);
                converter.getContext().setOutputPath(effectiveOutputDir.toPath());
                useFile = Paths.get(effectiveOutputDir.getPath(), useFile.getFileName().toString());
            }
        }
        if (getLog().isInfoEnabled()) {
            getLog().info("Converting input to one file: " + useFile);
        }
        converter.toFile(useFile);
    } else if (outputDir != null) {
        File effectiveOutputDir = outputDir;
        if (inputIsLocalFolder) {
            effectiveOutputDir = getEffectiveOutputDirWhenInputIsAFolder(converter);
        }
        if (getLog().isInfoEnabled()) {
            getLog().info("Converting input to multiple files in folder: '" + effectiveOutputDir + "'");
        }
        converter.toFolder(effectiveOutputDir.toPath());
    } else {
        throw new IllegalArgumentException("Either outputFile or outputDir parameter must be used");
    }
}

From source file:FileGameAccess.java

@Override
public boolean deleteGameCommands(int gameId) {
    File currentCommandFile = new File(System.getProperty("user.dir") + File.separator + gameId + ".commands");
    boolean exists = currentCommandFile.exists();
    try {//  ww w .  j  a  v  a 2  s. co  m
        if (exists)
            Files.delete(currentCommandFile.toPath());
    } catch (IOException ex) {
        Logger.getLogger(FileGameAccess.class.getName()).log(Level.SEVERE, null, ex);
    }
    //boolean delete = currentCommandFile.delete();
    return exists;
}

From source file:net.rptools.tokentool.client.TokenTool.java

/**
 * /*w  w  w . ja va 2 s  . com*/
 * @author Jamz
 * @throws IOException
 * @since 2.0
 * 
 *        This method loads and processes all the overlays found in user.home/overlays and it can take a minute to load as it creates thumbnail versions for the comboBox so we call this during the
 *        init and display progress in the preLoader (splash screen).
 * 
 */
private TreeItem<Path> cacheOverlays(File dir, TreeItem<Path> parent, int THUMB_SIZE) throws IOException {
    TreeItem<Path> root = new TreeItem<>(dir.toPath());
    root.setExpanded(false);

    log.debug("caching " + dir.getAbsolutePath());

    File[] files = dir.listFiles();
    for (File file : files) {
        if (file.isDirectory()) {
            cacheOverlays(file, root, THUMB_SIZE);
        } else {
            Path filePath = file.toPath();
            TreeItem<Path> imageNode = new TreeItem<>(filePath,
                    ImageUtil.getOverlayThumb(new ImageView(), filePath));
            root.getChildren().add(imageNode);

            notifyPreloader(new Preloader.ProgressNotification((double) loadCount++ / overlayCount));
        }
    }

    if (parent != null) {
        // When we show the overlay image, the TreeItem value is "" so we need to
        // sort those to the bottom for a cleaner look and keep sub dir's at the top.
        // If a node has no children then it's an overlay, otherwise it's a directory...
        root.getChildren().sort(new Comparator<TreeItem<Path>>() {
            @Override
            public int compare(TreeItem<Path> o1, TreeItem<Path> o2) {
                if (o1.getChildren().size() == 0 && o2.getChildren().size() == 0)
                    return 0;
                else if (o1.getChildren().size() == 0)
                    return Integer.MAX_VALUE;
                else if (o2.getChildren().size() == 0)
                    return Integer.MIN_VALUE;
                else
                    return o1.getValue().compareTo(o2.getValue());
            }
        });

        parent.getChildren().add(root);
    }

    return root;
}

From source file:com.github.blindpirate.gogradle.task.go.GoTest.java

private String dirToImportPath(File dir) {
    Path relativeToProjectRoot = getProjectDir().toPath().relativize(dir.toPath());
    Path importPath = Paths.get(setting.getPackagePath()).resolve(relativeToProjectRoot);
    return toUnixString(importPath);
}

From source file:de.ks.text.AsciiDocParser.java

private String copyFiles(String parse, File dataDir) throws IOException {
    Pattern pattern = Pattern.compile("\"file:.*\"");
    Matcher matcher = pattern.matcher(parse);
    int bodyTag = parse.indexOf("<body");
    Map<String, String> replacements = new HashMap<>();
    while (matcher.find()) {
        int start = matcher.start();
        if (start < bodyTag) {
            continue;
        }// w ww.  jav a2  s.  c o m
        int end = matcher.end();

        String fileReference = parse.substring(start + 1, end - 1);
        end = fileReference.indexOf("\"");
        fileReference = fileReference.substring(0, end);

        log.debug("Found file reference {}", fileReference);

        URI uri = URI.create(fileReference.replace('\\', '/'));
        File sourceFile = new File(uri);
        File targetFile = new File(dataDir, sourceFile.getName());
        java.nio.file.Files.copy(sourceFile.toPath(), targetFile.toPath());

        replacements.put(fileReference, dataDir.getName() + "/" + targetFile.getName());
    }

    for (Map.Entry<String, String> entry : replacements.entrySet()) {
        String original = entry.getKey();
        String replacement = entry.getValue();
        parse = StringUtils.replace(parse, original, replacement);
    }
    return parse;
}