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:edu.umd.umiacs.clip.tools.io.BZIP2Files.java

protected static Stream<String> lines(File file) throws IOException {
    return lines(file.toPath());
}

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

public static Collection<ScoreResult> retrieve(File path) {

    try {//from   ww w.j  a va 2 s  .  c om
        return list(path.toPath()).filter(ScoreDAO::isKPIFile).map(ScoreDAO::fromFile)
                .collect(Collectors.toList());
    } catch (IOException ioe) {
        throw new RuntimeException("Error reading all Yields KPI result from " + path.getAbsolutePath(), ioe);
    }

}

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

public static void compressDirectory(Path path, OutputStream output) {
    try {//from   w ww.  ja  v a2s. co m
        // Wrap the output file stream in streams that will tar and gzip everything
        TarArchiveOutputStream taos = new TarArchiveOutputStream(new GZIPOutputStream(output));
        // TAR has an 8 gig file limit by default, this gets around that
        taos.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_STAR); // to get past the 8 gig limit
        // TAR originally didn't support long file names, so enable the support for it
        taos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
        for (File child : path.toFile().listFiles()) {
            addFileToTarGz(taos, child.toPath(), "");
        }
        taos.close();
    } catch (IOException e) {
        throw new ApplicationSourceException(e);
    }
}

From source file:com.edmunds.etm.tools.urltoken.util.OptionUtils.java

@SuppressWarnings("unchecked")
public static List<String> parseValues(OptionSet options, OptionSpec<File> fileSpec) throws IOException {

    List<String> values;
    File file = options.valueOf(fileSpec);
    if (file != null) {
        values = Files.readAllLines(file.toPath());
    } else {/*from  w  ww  .  j a  v  a  2 s  . c om*/
        values = Lists.newArrayList();
    }

    return values;
}

From source file:edu.umd.umiacs.clip.tools.io.BZIP2Files.java

protected static Stream<CSVRecord> records(CSVFormat format, File file) throws IOException {
    return records(format, file.toPath());
}

From source file:com.crushpaper.Main.java

/** Returns the contents of the file as a string or null. */
static String readFile(File file) {
    byte[] encoded;

    try {/*from   ww w . j a v a2  s .c  o  m*/
        encoded = Files.readAllBytes(file.toPath());
    } catch (IOException e) {
        return null;
    }

    return new String(encoded, Charset.forName("UTF-8"));
}

From source file:gui.CompressDecompress.java

public static byte[] compressBuffer(List<List<BigInteger>> encBuffer) {

    try {// w w  w  .j  ava  2s  . co m
        File loc = new File("temp.dat");
        if (loc.exists()) {
            Files.delete(loc.toPath());
        }
        byte[] byteArray = serialize(encBuffer);
        AdaptiveArithmeticCompress.encoder(byteArray, loc.getAbsolutePath());

        InputStream is = new FileInputStream(loc);
        byte[] bytes = IOUtils.toByteArray(is);
        is.close();

        return bytes;

    } catch (IOException ex) {
        Logger.getLogger(CompressDecompress.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;

}

From source file:com.github.sakserv.lslock.cli.LockListerCli.java

/**
 * Returns the inode of the supplied File
 *
 * @param lockFile      Retrieve inode for this File
 * @return      The inode of the supplied lockFile
 * @throws IOException      If the File can not be found
 *///  w  w  w. j  a v a  2s  .com
public static int getInode(File lockFile) throws IOException {
    BasicFileAttributes basicFileAttributes = Files.readAttributes(lockFile.toPath(),
            BasicFileAttributes.class);
    Object fileKey = basicFileAttributes.fileKey();
    String fileAttrString = fileKey.toString();
    return Integer.parseInt(
            fileAttrString.substring(fileAttrString.indexOf("ino=") + 4, fileAttrString.indexOf(")")));
}

From source file:edu.umd.umiacs.clip.tools.scor.WordVectorUtils.java

public static WordVectors loadTxt(File vectorsFile, boolean... normalize) {
    AbstractCache cache = new AbstractCache<>();
    INDArray arrays[] = lines(vectorsFile.toPath()).map(line -> line.split(" "))
            .filter(fields -> fields.length > 2).map(split -> {
                VocabWord word = new VocabWord(1.0, split[0]);
                word.setIndex(cache.numWords());
                cache.addToken(word);//from ww w .  j  av a 2s.  c o m
                cache.addWordToIndex(word.getIndex(), split[0]);
                float[] vector = new float[split.length - 1];
                range(1, split.length).parallel().forEach(i -> vector[i - 1] = parseFloat(split[i]));
                return Nd4j.create(vector);
            }).toArray(size -> new INDArray[size]);

    INDArray syn = Nd4j.vstack(arrays);

    InMemoryLookupTable lookupTable = new InMemoryLookupTable.Builder().vectorLength(arrays[0].columns())
            .useAdaGrad(false).cache(cache).useHierarchicSoftmax(false).build();
    Nd4j.clearNans(syn);
    if (normalize.length > 0 && normalize[0]) {
        syn.diviColumnVector(syn.norm2(1));
    }

    lookupTable.setSyn0(syn);

    WordVectorsImpl vectors = new WordVectorsImpl();
    vectors.setLookupTable(lookupTable);
    vectors.setVocab(cache);
    return vectors;
}

From source file:com.c4om.autoconf.ulysses.configanalyzer.packager.CompressedFileConfigurationPackager.java

/**
 * It takes an absolute {@link File} and returns a {@link File} relative to
 * another given base {@link File}.//  w  w w .  j  a  v  a  2  s  .co m
 * 
 * @param absoluteFile the absolute File
 * @param baseFile the base File
 * @return a File relative to baseFile, pointing to the same file than
 *         absoluteFile
 */
protected static File relativizeFile(File absoluteFile, File baseFile) {
    Path absolutePath = absoluteFile.toPath();
    Path basePath = baseFile.toPath();
    Path relativePath = basePath.relativize(absolutePath);
    return relativePath.toFile();
}