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:com.google.devtools.build.lib.bazel.dash.DashModule.java

private Log getLog(String logPath) {
    Log.Builder builder = Log.newBuilder().setPath(logPath);
    File log = new File(logPath);
    try {/*  www. j av  a2  s .c o  m*/
        long fileSize = Files.size(log.toPath());
        if (fileSize > ONE_MB) {
            fileSize = ONE_MB;
            builder.setTruncated(true);
        }
        byte buffer[] = new byte[(int) fileSize];
        try (FileInputStream in = new FileInputStream(log)) {
            ByteStreams.readFully(in, buffer);
        }
        builder.setContents(ByteString.copyFrom(buffer));
    } catch (IOException e) {
        env.getReporter().getOutErr().printOutLn("Error reading log file " + logPath + ": " + e.getMessage());
        // TODO(kchodorow): add this info to the proto and send.
    }
    return builder.build();
}

From source file:edu.cornell.library.scholars.webapp.controller.api.distribute.file.FileDistributorTest.java

private void setVitroHomeDirectory(File home) {
    try {//from   www . j  a  v  a2 s  .  c om
        Field instanceField = ApplicationUtils.class.getDeclaredField("instance");
        instanceField.setAccessible(true);
        instanceField.set(null, new ApplicationStub(new VitroHomeDirectory(null, home.toPath(), null)));
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}

From source file:com.machinepublishers.jbrowserdriver.JBrowserDriver.java

private static void initClasspath() {
    List<String> classpathSimpleTmp = new ArrayList<String>();
    List<String> classpathUnpackedTmp = new ArrayList<String>();
    try {//from  w  w w  .  j  a va2 s.co  m
        List<File> classpathElements = new FastClasspathScanner().getUniqueClasspathElements();
        final File classpathDir = Files.createTempDirectory("jbd_classpath_").toFile();
        Runtime.getRuntime().addShutdownHook(new FileRemover(classpathDir));
        List<String> pathsSimple = new ArrayList<String>();
        List<String> pathsUnpacked = new ArrayList<String>();
        for (File curElement : classpathElements) {
            String rootLevelElement = curElement.getAbsoluteFile().toURI().toURL().toExternalForm();
            pathsSimple.add(rootLevelElement);
            pathsUnpacked.add(rootLevelElement);
            if (curElement.isFile() && curElement.getPath().endsWith(".jar")) {
                try (ZipFile jar = new ZipFile(curElement)) {
                    Enumeration<? extends ZipEntry> entries = jar.entries();
                    while (entries.hasMoreElements()) {
                        ZipEntry entry = entries.nextElement();
                        if (entry.getName().endsWith(".jar")) {
                            try (InputStream in = jar.getInputStream(entry)) {
                                File childJar = new File(classpathDir, Util.randomFileName() + ".jar");
                                Files.copy(in, childJar.toPath());
                                pathsUnpacked.add(childJar.getAbsoluteFile().toURI().toURL().toExternalForm());
                                childJar.deleteOnExit();
                            }
                        }
                    }
                }
            }
        }
        classpathSimpleTmp = createClasspathJar(classpathDir, "classpath-simple.jar", pathsSimple);
        classpathUnpackedTmp = createClasspathJar(classpathDir, "classpath-unpacked.jar", pathsUnpacked);
    } catch (Throwable t) {
        Util.handleException(t);
    }
    classpathSimpleArgs = Collections.unmodifiableList(classpathSimpleTmp);
    classpathUnpackedArgs = Collections.unmodifiableList(classpathUnpackedTmp);
}

From source file:com.zaba37.easyreader.actions.menuBar.ImageBackgroundLoader.java

private String createWindowsDirecotry(String mainPath) {
    mainPath = mainPath.substring(0, mainPath.lastIndexOf("/"));
    mainPath = mainPath + "/TmpEasyReaderImageDirectory";
    File file = new File(mainPath);

    try {/*www.  ja va  2s.c  om*/
        if (file.exists()) {
            FileUtils.forceDelete(file);
        }

        FileUtils.forceMkdir(file);

        Files.setAttribute(file.toPath(), "dos:hidden", true);

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

    return file.getPath();
}

From source file:com.twentyn.patentSearch.Searcher.java

private void init(List<File> indexDirectories) throws IOException {
    for (File indexDirectory : indexDirectories) {
        LOGGER.info("Opening index dir at %s", indexDirectory.getAbsolutePath());
        Directory indexDir = FSDirectory.open(indexDirectory.toPath());
        IndexReader indexReader = DirectoryReader.open(indexDir);
        IndexSearcher searcher = new IndexSearcher(indexReader);
        // Only add to the list if both of these calls work.
        indexReadersAndSearchers.add(Pair.of(indexReader, searcher));
    }//from  w  w w . ja  va  2  s  .c o m
}

From source file:com.excelsiorjet.maven.plugin.JetMojo.java

private void copyDependency(File from, File to, File buildDir, ArrayList<String> dependencies) {
    try {//from w ww.ja  va  2  s.co  m
        if (!to.exists()) {
            Files.copy(from.toPath(), to.toPath());
        }
        dependencies.add(buildDir.toPath().relativize(to.toPath()).toString());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:at.ac.tuwien.qse.sepm.gui.controller.impl.GridViewImpl.java

private void handleDragDropped(DragEvent event) {
    LOGGER.debug("drag dropped");

    Dragboard dragboard = event.getDragboard();
    boolean success = dragboard.hasFiles();
    if (success) {
        dragboard.getFiles().forEach(f -> LOGGER.debug("dropped file {}", f));
        for (File file : dragboard.getFiles()) {
            try {
                workspaceService.addDirectory(file.toPath());
            } catch (ServiceException ex) {
                LOGGER.error("Couldn't add directory {}");
            }/*from ww  w.j av  a 2s  . c om*/
        }
    }
    event.setDropCompleted(success);
    event.consume();
}

From source file:com.mapr.synth.SchemaSamplerTest.java

@Test
public void testFileSampler() throws IOException {
    File f = new File("numbers.tsv");
    f.deleteOnExit();//from ww w  .j  a v  a 2  s. c o m

    BufferedWriter out = Files.newBufferedWriter(f.toPath(), Charsets.UTF_8);
    out.write("a\tb\n");
    for (int i = 0; i < 20; i++) {
        out.write(i + "\t" + (i * i) + "\n");
    }
    out.close();

    SchemaSampler s = new SchemaSampler(
            Resources.asCharSource(Resources.getResource("schema008.json"), Charsets.UTF_8).read());

    for (int k = 0; k < 1000; k++) {
        JsonNode r = s.sample();
        assertEquals(6, r.get("x").get("x").asInt() + r.get("x").get("y").asInt());
        int i = r.get("y").get("a").asInt();
        assertEquals(i * i, r.get("y").get("b").asInt());
    }
}

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

/**
 * Load script from file./*from  ww  w.  ja v a2s  .  c o  m*/
 * @param file
 */
private void loadScript(final File file) {
    if (file == null || !file.exists()) {
        return;
    }
    try {
        scriptName.setText(file.getCanonicalPath());
        scripterInput.replaceText(
                Files.readAllLines(file.toPath()).stream().collect(Collectors.joining(System.lineSeparator())));
    } catch (final IOException e) {
        LOGGER.error("Caught error.", e);
    }
}

From source file:luceneGazateer.EntryData.java

public ArrayList<EntryData> searchDocuments(String indexerPath, String inputRecord, DocType recordType)
        throws IOException {

    File indexfile = new File(indexerPath);
    indexDir = FSDirectory.open(indexfile.toPath());

    //inputRecord.replace(","," ");
    if (!DirectoryReader.indexExists(indexDir)) {
        LOG.log(Level.SEVERE, "No Lucene Index Dierctory Found, Invoke indexBuild() First !");
        System.out.println("No Lucene Index Dierctory Found, Invoke indexBuild() First !");
        System.exit(1);//from  ww  w  .j a  va 2  s  . c o m
    }

    IndexReader reader = DirectoryReader.open(indexDir);

    IndexSearcher searcher = new IndexSearcher(reader);

    Query q = null;

    HashMap<String, ArrayList<ArrayList<String>>> allCandidates = new HashMap<String, ArrayList<ArrayList<String>>>();

    if (!allCandidates.containsKey(inputRecord)) {
        try {
            ArrayList<ArrayList<String>> topHits = new ArrayList<ArrayList<String>>();
            //System.out.println("query is : "+inputRecord);
            q = new MultiFieldQueryParser(new String[] { "DATA" }, analyzer).parse(inputRecord);

            TopScoreDocCollector collector = TopScoreDocCollector.create(hitsPerPage);
            searcher.search(q, collector);
            ScoreDoc[] hits = collector.topDocs().scoreDocs;
            for (int i = 0; i < hits.length; ++i) {
                ArrayList<String> tmp1 = new ArrayList<String>();
                int docId = hits[i].doc;
                Document d;
                try {
                    d = searcher.doc(docId);
                    tmp1.add(d.get("ID"));
                    tmp1.add(d.get("DATA"));
                    tmp1.add(((Float) hits[i].score).toString());

                } catch (IOException e) {
                    e.printStackTrace();
                }
                topHits.add(tmp1);
            }
            allCandidates.put(inputRecord, topHits);
        } catch (org.apache.lucene.queryparser.classic.ParseException e) {
            e.printStackTrace();
        }
    }

    ArrayList<EntryData> resolvedEntities = new ArrayList<EntryData>();
    pickBestCandidates(resolvedEntities, allCandidates);
    reader.close();

    return resolvedEntities;

}