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:muffinc.yafdivj.helper.FeretHandler.java

public static void move() {

    File file = new File(FOLDER);

    Path path = file.toPath();

    FileFilter fileFilter = new RegexFileFilter("0\\d{4}f.*tif");

    for (File file1 : file.listFiles(fileFilter)) {
        move(file1);/*from  w w w .ja  v  a  2 s. c o  m*/
    }
}

From source file:com.stratio.mojo.scala.crossbuild.FileRewriter.java

static void restoreFile(final File origFile) throws IOException {
    final File bkpFile = getBackupFileName(origFile);
    Files.copy(bkpFile.toPath(), origFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
}

From source file:com.arrow.acn.client.utils.MD5Util.java

public static byte[] calcMD5Checksum(File file) throws NoSuchAlgorithmException, IOException {
    return calcMD5Checksum(file.toPath());
}

From source file:com.aliyun.fs.oss.utils.Utils.java

public static synchronized File getTempBufferDir(Configuration conf) throws IOException {
    File tmpFile = dirAlloc.createTmpFileForWrite("output-", LocalDirAllocator.SIZE_UNKNOWN, conf);
    String dir = tmpFile.toPath().getParent().toUri().getPath();
    LOG.debug("choose oss buffer dir: " + dir);
    return new File(dir, "data/" + loginUser + "/oss");
}

From source file:com.blackducksoftware.integration.hub.detect.util.DetectZipUtil.java

public static void unzip(File zip, File dest, Charset charset) throws IOException {
    Path destPath = dest.toPath();
    try (ZipFile zipFile = new ZipFile(zip, ZipFile.OPEN_READ, charset)) {
        Enumeration<? extends ZipEntry> entries = zipFile.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = entries.nextElement();
            Path entryPath = destPath.resolve(entry.getName());
            if (!entryPath.normalize().startsWith(dest.toPath()))
                throw new IOException("Zip entry contained path traversal");
            if (entry.isDirectory()) {
                Files.createDirectories(entryPath);
            } else {
                Files.createDirectories(entryPath.getParent());
                try (InputStream in = zipFile.getInputStream(entry)) {
                    try (OutputStream out = new FileOutputStream(entryPath.toFile())) {
                        IOUtils.copy(in, out);
                    }/*from w ww.jav a2  s  .  co  m*/
                }
            }
        }
    }
}

From source file:common.Util.java

public static byte[] readFile(File file) {
    try {/*from ww  w.  j a v  a2  s.  c om*/
        return Files.readAllBytes(file.toPath());
    } catch (Exception e) {
        System.out.println("Could not read file " + file + ": " + e);
        return null;
    }
}

From source file:com.stratio.mojo.scala.crossbuild.FileRewriter.java

private static void backupFile(final File origFile) throws IOException {
    final File bkpFile = getBackupFileName(origFile);
    Files.copy(origFile.toPath(), bkpFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
}

From source file:com.textocat.textokit.commons.consumer.XmiFileWriter.java

public static AnalysisEngineDescription createDescription(File outputDir)
        throws ResourceInitializationException {
    return createDescription(outputDir.toPath());
}

From source file:com.enremmeta.onenow.Utils.java

public static String readFile(File f) throws IOException {
    byte[] encoded;
    encoded = Files.readAllBytes(f.toPath());
    return new String(encoded);
}

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();/*  w ww .  j  ava2 s.c o  m*/
    String entryName = base + f.getName();
    TarArchiveEntry tarEntry = new TarArchiveEntry(f, entryName);
    tOut.putArchiveEntry(tarEntry);
    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 + "/");
            }
        }
    }
}