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:org.libraryweasel.configmanager.JsonConfigManager.java

@Override
public <T> void write(String name, T instance) {
    Path path = pathsService.getInstancePath("config/" + name + ".json");
    try {// w  w  w. j a v  a 2 s  .c o m
        objectMapper.writeValue(path.toFile(), instance);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}

From source file:com.netease.hearttouch.hthotfix.HashFileGenerator.java

public void generate() throws IOException {
    if (hashMap.isEmpty()) {
        return;/*from   w  ww . ja  va 2  s  .c  o m*/
    }
    try {
        Path relativePath = Paths.get(outputPath);

        if (relativePath.toFile().exists())
            relativePath.toFile().delete();

        if (!relativePath.getParent().toFile().exists()) {
            Files.createDirectories(relativePath.getParent());
        }

        Files.createFile(relativePath);
        FileOutputStream outputStream = null;
        outputStream = new FileOutputStream(relativePath.toFile());

        sink = Okio.buffer(Okio.sink(outputStream));
        Set<Map.Entry<String, String>> set = hashMap.entrySet();
        Iterator<Map.Entry<String, String>> iterator = set.iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, String> entry = iterator.next();
            String className = entry.getKey();
            String sha1Hex = entry.getValue();
            sink.writeUtf8(String.format("%s,%s", className, sha1Hex));
            sink.writeByte(newLine);
        }

    } catch (IOException e) {
        e.printStackTrace();
        logger.error("HashFileGenerator generate error:\t" + e.getMessage());
        throw e;
    } finally {
        if (sink != null) {
            sink.close();
            sink = null;
        }
    }

}

From source file:ch.eitchnet.csvrestendpoint.components.CsvDataHandler.java

public List<String> getCsvNames() {

    File csvDataDir = getCsvDataDir();
    if (!csvDataDir.isDirectory()) {
        logger.error("CSV Data Dir is not a directory at " + csvDataDir.getAbsolutePath());
        return Collections.emptyList();
    }//from  w  w w  .  j a  v a2s.  co  m

    try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(csvDataDir.toPath())) {

        List<String> names = new ArrayList<>();

        for (Iterator<Path> iter = directoryStream.iterator(); iter.hasNext();) {
            Path path = iter.next();
            String name = path.toFile().getName();
            if (name.endsWith(".csv"))
                names.add(name.substring(0, name.length() - 4));
        }

        return names;

    } catch (Exception e) {
        throw new RuntimeException("Failed to read CSV names due to " + e.getMessage());
    }
}

From source file:org.eclipse.vorto.remoterepository.VortoTestApplication.java

@Bean(name = "fsDirectory")
@DependsOn("analyzer")
public FSDirectory getFSDirectory() {
    FSDirectory fsd = null;/*from   w  ww .j ava2 s  . c o m*/

    Path indexLocation = Paths.get("src/test/resources/temp/lucent");

    File location = indexLocation.toFile();

    if (!location.exists() || !location.canRead()) {
        log.info("Creating index directory: '" + location.getAbsolutePath() + "'");
        location.mkdirs();
    }

    try {
        fsd = FSDirectory.open(location, new NativeFSLockFactory());
    } catch (IOException e) {
        log.log(Level.SEVERE, " IOException for creating Indexing folder", e);
    }

    return fsd;
}

From source file:fr.cnrs.sharp.test.MainCLITest.java

@Test
public void Main1() throws IOException {
    InputStream is = MainCLITest.class.getClassLoader().getResourceAsStream("galaxy.prov.ttl");
    Path p = Files.createTempFile("test-prov", ".ttl");
    FileUtils.copyInputStreamToFile(is, p.toFile());
    System.out.println("Galaxy PROV written to " + p.toString());

    String[] params = { "-i", p.toString() };

    StopWatch sw = new StopWatch();
    sw.start();//from  w ww .  ja  v a2  s. c om
    Main.main(params);
    sw.stop();
    System.out.println("DONE in " + sw.getTime() + " ms");

}

From source file:fr.cnrs.sharp.test.MainCLITest.java

@Test
public void Main2() throws IOException {
    InputStream is = MainCLITest.class.getClassLoader().getResourceAsStream("galaxy.prov.ttl");
    Path p = Files.createTempFile("test-prov", ".ttl");
    FileUtils.copyInputStreamToFile(is, p.toFile());
    System.out.println("Galaxy PROV written to " + p.toString());

    String[] params = { "-i", p.toString(), "-s" };

    StopWatch sw = new StopWatch();
    sw.start();/*from   ww w  .  j av  a  2s.  co m*/
    Main.main(params);
    sw.stop();
    System.out.println("DONE in " + sw.getTime() + " ms");

}

From source file:org.libraryweasel.configmanager.JsonConfigManager.java

@Override
public <T> T read(String name, Class<T> configurationClass) {
    Path path = pathsService.getInstancePath("config/" + name + ".json");
    try {//  w ww  .  j a  va 2 s .co  m
        return objectMapper.readValue(path.toFile(), configurationClass);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}

From source file:fr.inria.atlanmod.neoemf.extension.Workspace.java

public File newFile(String prefix) throws IOException {
    Path createdFolder = Files.createTempDirectory(temporaryFolder.toPath(), prefix);
    Files.deleteIfExists(createdFolder);
    return createdFolder.toFile();
}

From source file:com.yqboots.initializer.web.controller.ProjectInitializerController.java

@RequestMapping(value = "/", method = RequestMethod.POST)
public Object startup(@ModelAttribute(WebKeys.MODEL) @Valid final ProjectInitializerForm form,
        final BindingResult bindingResult, final ModelMap model) throws IOException {
    if (bindingResult.hasErrors()) {
        return FORM_URL;
    }/*from w  ww.j a v  a 2 s.  com*/

    Path path;

    final MultipartFile file = form.getFile();
    if (StringUtils.isNotBlank(file.getName())) {
        try (InputStream inputStream = file.getInputStream()) {
            path = initializer.startup(form.getMetadata(), form.getTheme(), inputStream);
        }
    } else {
        path = initializer.startup(form.getMetadata(), form.getTheme());
    }

    final HttpEntity<byte[]> result = FileWebUtils.downloadFile(path,
            new MediaType("application", "zip", StandardCharsets.UTF_8));

    // clear temporary folder
    final Path parent = path.getParent();
    FileUtils.deleteDirectory(parent.toFile());

    // clear model
    model.clear();

    return result;
}

From source file:io.fabric8.kubernetes.generator.processor.AbstractKubernetesAnnotationProcessor.java

private FileObject getFileObject(String fileName) throws IOException {
    FileObject fileObject = processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT, "", fileName);
    Path path = Paths.get(fileObject.toUri());
    File file = path.toFile();
    if (file.exists() && !file.delete()) {
        throw new IOException("Failed to delete old kubernetes json file: " + fileName);
    }//from  w w w.  java2s . com
    fileObject = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", fileName);
    return fileObject;
}