Example usage for java.nio.file Path toFile

List of usage examples for java.nio.file Path toFile

Introduction

In this page you can find the example usage for java.nio.file Path toFile.

Prototype

default File toFile() 

Source Link

Document

Returns a File object representing this path.

Usage

From source file:at.tl_photography.jsync.common.FileChecker.java

/**
 * Generate m d5.//from  w  w w  . ja v  a 2 s .c  o m
 *
 * @param path
 *            the path
 * @return the byte[]
 */
public static String generateMD5(Path path) {
    try (FileInputStream fis = new FileInputStream(path.toFile())) {
        return DigestUtils.md5Hex(fis);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;

}

From source file:minij.TestFiles.java

private static List<Object[]> getFiles(Class<? extends Exception> exceptionClass, Path... paths) {
    List<Object[]> files = new LinkedList<>();

    for (Path path : paths) {
        for (File file : FileUtils.listFiles(path.toFile(), null, true)) {
            files.add(new Object[] { file, exceptionClass });
        }// w  w  w.jav a 2  s  .  c o  m
    }

    return files;
}

From source file:dev.meng.wikipedia.profiler.Cleaner.java

public static void cleanData(List<String> values) {
    for (String value : values) {
        try {/*from www . j ava 2s  . c  om*/
            Path filepath = Paths.get(value);
            File file = filepath.toFile();
            if (file.exists()) {
                if (file.isFile()) {
                    Files.delete(filepath);
                } else if (file.isDirectory()) {
                    FileUtils.deleteDirectory(file);
                }
            }
        } catch (IOException ex) {
            LogHandler.console(Cleaner.class, ex);
        }
    }
}

From source file:org.dawnsci.marketplace.controllers.PageController.java

static String parse(Path path) {
    if (!path.toFile().exists()) {
        return "";
    }/*from ww  w  . j  av  a  2 s  .  c om*/
    StringWriter sw = new StringWriter();
    MarkupParser parser = new MarkupParser();
    parser.setMarkupLanguage(new MarkdownLanguage());
    HtmlDocumentBuilder builder = new HtmlDocumentBuilder(sw);
    builder.setEmitAsDocument(false);
    parser.setBuilder(builder);
    try {
        parser.parse(new StringReader(new String(Files.readAllBytes(path))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    return sw.toString();
}

From source file:io.yields.math.framework.kpi.ScoreDAO.java

private static boolean isKPIFile(Path path) {
    return path.toFile().isFile() && path.toString().endsWith(FILE_SUFFIX);
}

From source file:io.cloudslang.content.utilities.services.PdfParseService.java

private static PDDocument getPdfDocument(final Path path, final String password) throws IOException {
    if (isEmpty(password))
        return PDDocument.load(path.toFile());
    return PDDocument.load(path.toFile(), password);
}

From source file:com.ibm.wala.cast.js.nodejs.NodejsRequiredCoreModule.java

public static NodejsRequiredCoreModule make(String name) throws IOException {
    if (!names.containsKey(name)) {
        java.nio.file.Path p = Files.createTempDirectory("nodejs");
        File f = new File(p.toFile(), name + ".js");
        f.deleteOnExit();/* ww  w  .  j a va  2  s.co m*/
        p.toFile().deleteOnExit();
        names.put(name, f);
    }
    File file = names.get(name);
    TemporaryFile.streamToFile(file, getModule(name));
    SourceFileModule sourceFileModule = CAstCallGraphUtil.makeSourceModule(file.toURI().toURL(),
            file.getName());
    return new NodejsRequiredCoreModule(file, sourceFileModule);
}

From source file:cc.kave.commons.externalserializationtests.ExternalTestCaseProvider.java

@Nonnull
public static List<TestCase[]> getTestCases(Path baseDirectory) throws ClassNotFoundException, IOException {
    if (!baseDirectory.toFile().exists()) {
        return Lists.newLinkedList();
    }/*from   w ww.  java  2s  .  co  m*/
    return recursiveGetTestCases(baseDirectory.toFile(), baseDirectory.toString());
}

From source file:Main.java

static public Document getDocument(Path filePath)
        throws IOException, ParserConfigurationException, SAXException {
    return getDocument(filePath.toFile());
}

From source file:com.ttech.cordovabuild.infrastructure.archive.ArchiveUtils.java

private static void addFileToTarGz(TarArchiveOutputStream tOut, Path path, String base) throws IOException {
    File f = path.toFile();
    String entryName = base + f.getName();
    TarArchiveEntry tarEntry = new TarArchiveEntry(f, entryName);
    tOut.putArchiveEntry(tarEntry);/*from  w  w  w.  jav  a 2s  . com*/
    if (f.isFile()) {
        IOUtils.copy(new FileInputStream(f), tOut);
        tOut.closeArchiveEntry();
    } else {
        tOut.closeArchiveEntry();
        File[] children = f.listFiles();
        if (children != null) {
            for (File child : children) {
                addFileToTarGz(tOut, child.toPath().toAbsolutePath(), entryName + "/");
            }
        }
    }
}