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:com.hurence.logisland.processor.RandomStandardRecordGeneratorTest.java

private String loadResurceFileToString(String resourceFile) throws Exception {
    Path resourcePath = Paths.get(getClass().getResource(resourceFile).toURI());
    return FileUtils.readFileToString(resourcePath.toFile());
}

From source file:de.monticore.io.FileReaderWriter.java

/**
 * Writes a String to a file using the specified encoding.
 * //from  w ww . jav  a 2  s .  c o  m
 * @param targetPath The location of the file to be written to.
 * @param content The String that's supposed to be written into the file
 * @see #setCharset(Charset)
 */
public void storeInFile(Path targetPath, String content) {
    try {
        FileUtils.write(targetPath.toFile(), content, this.charset);
    } catch (IOException e) {
        Log.error("0xA1023 IOException occured.", e);
        Log.debug("IOException occured while trying to write to the File " + targetPath + ".", e,
                this.getClass().getName());
    }
}

From source file:com.fizzed.blaze.ssh.SshBaseTest.java

public void contextWithEmptyUserDir() throws IOException {
    Path emptyUserDir = context.userDir().resolve("empty");
    FileUtils.deleteQuietly(emptyUserDir.toFile());
    Files.createDirectories(emptyUserDir);
    context.userDir(emptyUserDir);//from   w w  w. j  a va 2 s .  c om
}

From source file:com.perrier.music.entity.album.AlbumZipper.java

public File zip(Album album) throws IOException {

    Path zipPath = Files.createTempFile(ZIP_PREFIX + album.getId() + "-", ".zip");
    File zipFile = zipPath.toFile();

    try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile))) {
        List<Track> tracks = album.getTracks();
        for (Track t : tracks) {
            String name = createFileName(t);
            ZipEntry zipEntry = new ZipEntry(name);
            zos.putNextEntry(zipEntry);//  w  w w.j a  va  2  s.  co m

            try (InputStream audioStream = this.storageService.getAudioStream(t.getAudioStorageKey())) {
                IOUtils.copy(audioStream, zos);
            }
        }
    }

    return zipFile;
}

From source file:org.kawakicchi.bookshelf.infrastructure.storage.fs.FSContentStorage.java

public InputStream get(final String key) {
    String[] s = key.split("/");
    Path path = Paths.get(BASE_DIR.getAbsolutePath(), s);

    InputStream stream = null;/*ww  w .  ja  v a2 s.c o  m*/
    try {
        stream = new FileInputStream(path.toFile());
    } catch (IOException ex) {

    }

    return stream;
}

From source file:com.hpl.mds.annotations.processors.JCompiler.java

private JCompiler() {
    try {//from ww w. ja  v a 2 s . com
        Path outputPath = Paths.get(OUTPUT_DIR);
        File outputDirFile = outputPath.toFile();
        if (outputDirFile.exists()) {
            FileUtils.cleanDirectory(outputDirFile);
        }
        URL url = outputDirFile.toURI().toURL();
        CLASS_LOADER = new URLClassLoader(new URL[] { url });
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:io.github.sn0cr.rapidRunner.testRunner.TestCaseFinder.java

public TestCaseFinder(Path parentFolder, String filePattern, String inExtension, String outExtension) {
    final String[] files = parentFolder.toFile().list(new WildcardFileFilter(filePattern));
    Arrays.sort(files, new NaturalOrderComparator());
    for (final String filename : files) {
        final String extension = FilenameUtils.getExtension(filename);
        final String name = FilenameUtils.getBaseName(filename);
        final Path toFile = Paths.get(parentFolder.toString(), filename);
        Pair<Path, Path> testCasePair;
        if (this.testCases.containsKey(name)) {
            testCasePair = this.testCases.get(name);
        } else {/*from w w  w .  ja v a2s  . co m*/
            testCasePair = new Pair<Path, Path>();
        }
        if (extension.equals(inExtension)) {
            testCasePair.setA(toFile);
        } else if (extension.equals(outExtension)) {
            testCasePair.setB(toFile);
        }
        if (testCasePair.notEmpty()) {
            this.testCases.put(name, testCasePair);
        }
    }
}

From source file:com.netflix.spinnaker.halyard.deploy.services.v1.VaultService.java

public void publishSecret(DeploymentConfiguration deploymentConfiguration, String name, Path path) {
    String contents;/* w  w w . ja v  a2s  . c  o  m*/
    try {
        contents = IOUtils.toString(new FileInputStream(path.toFile()));
    } catch (IOException e) {
        throw new HalException(Problem.Severity.FATAL,
                "Failed to read config file " + path.toString() + ": " + e.getMessage());
    }

    publishSecret(deploymentConfiguration, name, contents);
}

From source file:de.ks.flatadocdb.defaults.DefaultEntityPersister.java

@Override
public boolean canParse(Path path, EntityDescriptor descriptor) {
    if (path.toFile().exists()) {
        try (FileInputStream stream = new FileInputStream(path.toFile())) {
            try (LineNumberReader reader = new LineNumberReader(new InputStreamReader(stream))) {
                String line1 = reader.readLine();
                String line2 = reader.readLine();
                line1 = line1 == null ? "" : line1.trim();
                line2 = line2 == null ? "" : line2.trim();
                boolean valid = checkLine(line1, line2, descriptor.getEntityClass());
                if (valid) {
                    log.debug("Found valid file {} to parse as {}", path,
                            descriptor.getEntityClass().getSimpleName());
                }//from  w  ww  . j a  v  a2  s.  com
                return valid;
            }
        } catch (IOException e) {
            log.debug("Unable to parse {} as {}", path, descriptor.getEntityClass(), e);
            return false;
        }
    }
    return false;
}

From source file:com.surevine.gateway.scm.gatewayclient.GatewayPackage.java

void createTar(final Path tarPath, final Path... paths) throws IOException, ArchiveException {
    ArchiveOutputStream os = new ArchiveStreamFactory().createArchiveOutputStream("tar",
            Files.newOutputStream(tarPath));
    try {// w  ww  . ja  va  2 s.  c om
        for (Path path : paths) {
            TarArchiveEntry entry = new TarArchiveEntry(path.toFile());
            entry.setName(path.getFileName().toString());
            os.putArchiveEntry(entry);
            Files.copy(path, os);
            os.closeArchiveEntry();
        }
    } finally {
        os.close();
    }
}